Spaces:
No application file
No application file
| 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}") | |