Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import pandas as pd,numpy as np
|
|
| 2 |
import pickle
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
-
st.title("Mobile Data User Behaviour")
|
| 6 |
|
| 7 |
# st.title("User Behavior Using Mobile Prediction")
|
| 8 |
# model_2 = pickle.load(open(r"\rfc.pkl","rb")) #pickle file path
|
|
@@ -10,6 +10,46 @@ st.title("Mobile Data User Behaviour")
|
|
| 10 |
# if st.button("Submit"):
|
| 11 |
# result = model_2.predict([[]])
|
| 12 |
# st.write(f"The predicted price of the rental house is {result}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
# age = st.number_input("Enter age",min_value=0,max_value=1000,step=1,format="%d" )
|
|
|
|
| 2 |
import pickle
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
+
# st.title("Mobile Data User Behaviour")
|
| 6 |
|
| 7 |
# st.title("User Behavior Using Mobile Prediction")
|
| 8 |
# model_2 = pickle.load(open(r"\rfc.pkl","rb")) #pickle file path
|
|
|
|
| 10 |
# if st.button("Submit"):
|
| 11 |
# result = model_2.predict([[]])
|
| 12 |
# st.write(f"The predicted price of the rental house is {result}")
|
| 13 |
+
|
| 14 |
+
import joblib
|
| 15 |
+
import streamlit as st
|
| 16 |
+
|
| 17 |
+
st.title("User Behavior Using Mobile Prediction")
|
| 18 |
+
|
| 19 |
+
# Inputs
|
| 20 |
+
Device_Model = st.selectbox("Enter Device Model Type", ['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21'])
|
| 21 |
+
age = st.number_input("Enter age", min_value=0, max_value=100, step=1, format="%d")
|
| 22 |
+
gender = st.radio("Enter gender", ['Male', 'Female'])
|
| 23 |
+
Operating_System = st.selectbox("Enter Operating System Type", ['Android', 'iOS'])
|
| 24 |
+
App_Usage_Time = st.number_input("Enter the App Usage Time")
|
| 25 |
+
Screen_On_Time = st.number_input("Enter the Screen On Time")
|
| 26 |
+
Battery_Drain = st.number_input("Enter the Battery Drain")
|
| 27 |
+
Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed")
|
| 28 |
+
Data_Usage = st.number_input("Enter the Data Usage")
|
| 29 |
+
|
| 30 |
+
# Load the model
|
| 31 |
+
model_path = "./rfc.pkl" # Adjust if in a subdirectory
|
| 32 |
+
try:
|
| 33 |
+
model_2 = joblib.load(model_path)
|
| 34 |
+
|
| 35 |
+
# Encode categorical variables
|
| 36 |
+
mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4}
|
| 37 |
+
mapping_os = {'Android': 0, 'iOS': 1}
|
| 38 |
+
mapping_gender = {'Male': 0, 'Female': 1}
|
| 39 |
+
|
| 40 |
+
device_model_encoded = mapping_device[Device_Model]
|
| 41 |
+
operating_system_encoded = mapping_os[Operating_System]
|
| 42 |
+
gender_encoded = mapping_gender[gender]
|
| 43 |
+
|
| 44 |
+
if st.button("Submit"):
|
| 45 |
+
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]])
|
| 46 |
+
st.write(f"The predicted behavior is: {result}")
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
st.error(f"Model file not found at: {model_path}")
|
| 49 |
+
except Exception as e:
|
| 50 |
+
st.error(f"An error occurred: {e}")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
|
| 54 |
|
| 55 |
# age = st.number_input("Enter age",min_value=0,max_value=1000,step=1,format="%d" )
|