File size: 6,479 Bytes
9b6d398 b63299c 9b6d398 3b743c2 b63299c 9859252 b63299c 9859252 b63299c 9859252 b63299c 9859252 b63299c 9859252 b63299c 9859252 b63299c 9b6d398 |
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
import pandas as pd,numpy as np
import pickle
import streamlit as st
# st.title("Mobile Data User Behaviour")
# st.title("User Behavior Using Mobile Prediction")
# model_2 = pickle.load(open(r"\rfc.pkl","rb")) #pickle file path
# if st.button("Submit"):
# result = model_2.predict([[]])
# 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")
# 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']) |