MiauRicc/Machine_Learning_for_Predictive_Modeling
0
1import streamlit as st2import pandas as pd3import numpy as np4import joblib5 6st.set_page_config(7 page_title='ExtraaLearn โ Lead Conversion Predictor',8 page_icon='๐',9 layout='centered'10)11 12st.title('๐ ExtraaLearn Lead Conversion Predictor')13st.markdown(14 'Enter the lead details below to predict whether they are likely '15 'to convert to a **paid customer**.'16)17st.divider()18 19@st.cache_resource20def load_model():21 return joblib.load('lead_conversion_model.pkl')22 23model = load_model()24 25col1, col2 = st.columns(2)26 27with col1:28 age = st.slider('Age', min_value=18, max_value=63, value=35)29 current_occupation = st.selectbox(30 'Current Occupation', ['Professional', 'Student', 'Unemployed']31 )32 first_interaction = st.selectbox(33 'First Interaction', ['Website', 'Mobile App']34 )35 profile_completed = st.selectbox(36 'Profile Completed', ['High', 'Medium', 'Low']37 )38 last_activity = st.selectbox(39 'Last Activity', ['Email Activity', 'Phone Activity', 'Website Activity']40 )41 42with col2:43 website_visits = st.number_input(44 'Website Visits', min_value=0, max_value=30, value=345 )46 time_spent_on_website = st.number_input(47 'Time Spent on Website (seconds)', min_value=0, max_value=2537, value=50048 )49 page_views_per_visit = st.number_input(50 'Page Views per Visit', min_value=0.0, max_value=18.5, value=3.0, step=0.151 )52 print_media_type1 = st.selectbox('Saw Newspaper Ad?', ['No', 'Yes'])53 print_media_type2 = st.selectbox('Saw Magazine Ad?', ['No', 'Yes'])54 55col3, col4 = st.columns(2)56with col3:57 digital_media = st.selectbox('Saw Digital Media Ad?', ['No', 'Yes'])58 educational_channels = st.selectbox('Heard via Educational Channels?', ['No', 'Yes'])59with col4:60 referral = st.selectbox('Came via Referral?', ['No', 'Yes'])61 62st.divider()63 64if st.button('๐ Predict Conversion', use_container_width=True, type='primary'):65 input_data = pd.DataFrame([{66 'age' : age,67 'current_occupation' : current_occupation,68 'first_interaction' : first_interaction,69 'profile_completed' : profile_completed,70 'website_visits' : website_visits,71 'time_spent_on_website': time_spent_on_website,72 'page_views_per_visit' : page_views_per_visit,73 'last_activity' : last_activity,74 'print_media_type1' : print_media_type1,75 'print_media_type2' : print_media_type2,76 'digital_media' : digital_media,77 'educational_channels' : educational_channels,78 'referral' : referral,79 }])80 81 prediction = model.predict(input_data)[0]82 proba = model.predict_proba(input_data)[0]83 84 if prediction == 1:85 st.success(86 f'โ
HIGH CONVERSION PROBABILITY โ This lead is likely to convert!\n\n'87 f'Confidence: {proba[1]*100:.1f}%'88 )89 else:90 st.warning(91 f'โ ๏ธ LOW CONVERSION PROBABILITY โ This lead is unlikely to convert.\n\n'92 f'Confidence: {proba[0]*100:.1f}%'93 )94 95 st.markdown('**Lead Summary:**')96 st.dataframe(input_data, use_container_width=True)97 98st.divider()99st.caption('ExtraaLearn Data Science Project ยท Powered by Scikit-learn & Streamlit')100 