# import pandas as pd,numpy as np # import joblib # import streamlit as st # st.title("User Behavior Using Mobile Prediction") # Device_Model = st.selectbox("Enter Device Model Type",['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5','Google Pixel 5','OnePlus 9','Samsung Galaxy S21']) # age = st.number_input("Enter age",min_value=0,max_value=1000,step=1,format="%d" ) # gender = st.radio("Enter gender",['Male','Female']) # Operating_System= st.selectbox("Enter Operating System Type",['Android','iOS']) # App_Usage_Time = st.number_input("Enter the App Usage Time") # Screen_On_Time= st.number_input("Enter the Screen On Time") # Battery_Drain= st.number_input("Enter the Battery Drain") # Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed") # Data_Usage = st.number_input("Enter the Data Usage") # model_2 = joblib.load(r"Mobile_data_user_behaviour/rfc.pkl") #pickle file path # if st.button("Submit"): # result = model_2.predict([[Device_Model,Operating_System,App_Usage_Time,Screen_On_Time,Battery_Drain,Number_of_Apps_Installed,Data_Usage,age,gender]]) # st.write(f"The predicted price of the rental house is {result}") # import joblib # import streamlit as st # st.title("User Behavior Using Mobile Prediction") # # Inputs # Device_Model = st.selectbox("Enter Device Model Type", ['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21']) # age = st.number_input("Enter age", min_value=0, max_value=100, step=1, format="%d") # gender = st.radio("Enter gender", ['Male', 'Female']) # Operating_System = st.selectbox("Enter Operating System Type", ['Android', 'iOS']) # App_Usage_Time = st.number_input("Enter the App Usage Time") # Screen_On_Time = st.number_input("Enter the Screen On Time") # Battery_Drain = st.number_input("Enter the Battery Drain") # Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed") # Data_Usage = st.number_input("Enter the Data Usage") # # Load the model # model_path = "./rfc.pkl" # Adjust if in a subdirectory # try: # model_2 = joblib.load(model_path) # # Encode categorical variables # mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4} # mapping_os = {'Android': 0, 'iOS': 1} # mapping_gender = {'Male': 0, 'Female': 1} # device_model_encoded = mapping_device[Device_Model] # operating_system_encoded = mapping_os[Operating_System] # gender_encoded = mapping_gender[gender] # if st.button("Submit"): # result = model_2.predict([[device_model_encoded, operating_system_encoded, App_Usage_Time, Screen_On_Time, Battery_Drain, Number_of_Apps_Installed, Data_Usage, age, gender_encoded]]) # st.write(f"The predicted behavior is: {result}") # except FileNotFoundError: # st.error(f"Model file not found at: {model_path}") # except Exception as e: # st.error(f"An error occurred: {e}") import joblib import streamlit as st # Set page configuration st.set_page_config(page_title="User Behavior Prediction", page_icon="📱", layout="wide") # Add background image using custom CSS def add_bg_from_url(): st.markdown( f""" """, unsafe_allow_html=True ) add_bg_from_url() # Title and Description st.title("📱 User Behavior Prediction Using Mobile Data") st.markdown(""" Welcome to the **User Behavior Prediction App**! This tool predicts user behavior based on mobile usage data, powered by a machine learning model. Fill in the details below and click **Submit** to see the results. """) # Inputs in columns for better alignment col1, col2 = st.columns(2) with col1: Device_Model = st.selectbox( "📱 Device Model Type", ['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21'], help="Select the type of mobile device being used." ) Operating_System = st.selectbox( "⚙️ Operating System Type", ['Android', 'iOS'], help="Select the mobile's operating system." ) gender = st.radio( "👤 Gender", ['Male', 'Female'], help="Select the gender of the user." ) age = st.number_input( "🎂 Age", min_value=0, max_value=100, step=1, format="%d", help="Enter the user's age." ) with col2: App_Usage_Time = st.number_input( "⏱️ App Usage Time (in hours)", min_value=0.0, step=0.1, help="Enter the total app usage time (e.g., 3.5 hours)." ) Screen_On_Time = st.number_input( "🔆 Screen On Time (in hours)", min_value=0.0, step=0.1, help="Enter the total screen on time (e.g., 5.2 hours)." ) Battery_Drain = st.number_input( "🔋 Battery Drain (in percentage)", min_value=0.0, step=0.1, help="Enter the battery drain percentage (e.g., 15.5%)." ) Number_of_Apps_Installed = st.number_input( "📱 Number of Apps Installed", min_value=0, step=1, help="Enter the total number of apps installed on the device." ) Data_Usage = st.number_input( "📶 Data Usage (in GB)", min_value=0.0, step=0.1, help="Enter the total data usage (e.g., 1.5 GB)." ) # Load the model model_path = "./rfc.pkl" # Adjust if in a subdirectory try: model_2 = joblib.load(model_path) # Encode categorical variables mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4} mapping_os = {'Android': 0, 'iOS': 1} mapping_gender = {'Male': 0, 'Female': 1} device_model_encoded = mapping_device[Device_Model] operating_system_encoded = mapping_os[Operating_System] gender_encoded = mapping_gender[gender] # Predict and display result if st.button("🚀 Submit"): with st.spinner("Running prediction..."): result = model_2.predict([[device_model_encoded, operating_system_encoded, App_Usage_Time, Screen_On_Time, Battery_Drain, Number_of_Apps_Installed, Data_Usage, age, gender_encoded]]) st.success("🎉 Prediction Completed!") st.markdown(f"**📊 Predicted User Behavior:** `{result[0]}`") except FileNotFoundError: st.error(f"🚨 Model file not found at: `{model_path}`. Please upload the model.") except Exception as e: st.error(f"🚨 An error occurred: {e}") # age = st.number_input("Enter age",min_value=0,max_value=1000,step=1,format="%d" ) # gender = st.radio("Enter gender",['Male','Female']) # chestpain = st.selectbox("chestpain",['non-anginal_pain', 'typical_angina', 'atypical_angina','asymptomatic']) # restingBP = st.number_input("Enter BP",min_value=0,max_value=1000,step=1,format="%d") # serum_cholesterol = st.number_input("Enter serum_cholesterol",min_value=0,max_value=10000,step=1,format="%d") # fasting_blood_sugar = st.radio("Enter fasting_blood_sugar",['yes','no']) # restingrelectro= st.selectbox("Enter resting_electro",['ST-T_wave_abnormality', 'normal', 'left_ventricular_hypertrophy']) # maxheartrate = st.number_input("Enter max_heart_rate",min_value=0,max_value=1000,step=1,format="%d") # exerciseangia = st.radio("Enter exercise_angia",['yes','no']) # oldpeak= st.number_input("Enter oldpeak") # slope = st.selectbox("Enter slope",['downsloping', 'upsloping', 'flat']) # noofmajorvessels = st.selectbox("enter number of major vessels",['Three', 'One', 'Zero', 'Two'])