Spaces:
No application file
No application file
File size: 2,888 Bytes
2f301d0 a6268d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import streamlit as st
import pandas as pd
import joblib
import warnings
warnings.filterwarnings("ignore", message=".*ScriptRunContext.*")
# Load the trained model
def load_model():
return joblib.load("customer_prediction_model_v1_0.joblib")
model = load_model()
# Set the title of the Streamlit app
st.title("ExtraaLearn Customer Predictor")
st.subheader("Online Prediction")
# Collect user input based on dataset columns
# Collect user input for property features
age = st.number_input("age", min_value=5, max_value=90, step=1, value=30)
website_visits = st.number_input("website_visits", min_value=0, step=1, value=1)
time_spent_on_website = st.number_input("time_spent_on_website", min_value=0, step=1, value=1)
page_views_per_visit = st.number_input("page_views_per_visit", min_value=0, step=1, value=1)
current_occupation = st.selectbox("current_occupation", ["Professional", "Student", "Unemployed"])
first_interaction = st.selectbox("first_interaction", ["Mobile App", "Website"])
profile_completed = st.selectbox("profile_completed", ["Medium", "High", "Low"])
last_activity = st.selectbox("last_activity", ["Website Activity", "Email Activity", "Phone Activity"])
print_media_type1 = st.selectbox("print_media_type1", ["Yes", "No"])
print_media_type2 = st.selectbox("print_media_type2", ["Yes", "No"])
digital_media = st.selectbox("digital_media", ["Yes", "No"])
educational_channels = st.selectbox("educational_channels", ["Yes", "No"])
referral = st.selectbox("referral", ["Yes", "No"])
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'age' : 'age',
'website_visits' : 'website_visits',
'time_spent_on_website' : 'time_spent_on_website',
'page_views_per_visit' : 'page_views_per_visit',
'current_occupation' : 'current_occupation',
'first_interaction' : 'first_interaction',
'profile_completed' : 'profile_completed',
'last_activity' : 'last_activity',
'print_media_type1' : 'print_media_type1',
'print_media_type2' : 'print_media_type2',
'digital_media' : 'digital_media',
'educational_channels' : 'educational_channels',
'referral' : 'referral'
}])
# Set classification threshold
classification_threshold = 0.5
# Predict button
if st.button("Predict"):
prediction_proba = model.predict_proba(input_data)[0, 1]
prediction = (prediction_proba >= classification_threshold).astype(int)
result = "Join" if prediction == 1 else "not join"
st.write(f"Prediction: The customer is likely to **{result}**.")
st.write(f"Churn Probability: {prediction_proba:.2f}")
|