Create test.py
Browse files
test.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
''''
|
| 2 |
+
Author : Rupesh Garsondiya
|
| 3 |
+
github : @Rupeshgarsondiya
|
| 4 |
+
Organization : L.J University
|
| 5 |
+
|
| 6 |
+
'''
|
| 7 |
+
|
| 8 |
+
import time
|
| 9 |
+
import streamlit as st
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import numpy as np
|
| 12 |
+
from sklearn.preprocessing import StandardScaler
|
| 13 |
+
from train import *
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class test :
|
| 17 |
+
|
| 18 |
+
def __init__(self):
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
def predict_data(self):
|
| 22 |
+
|
| 23 |
+
st.sidebar.title("Select Parameter ")
|
| 24 |
+
mt = Model_Train()
|
| 25 |
+
S_algo,Pipeline = mt.train_model()
|
| 26 |
+
df = None
|
| 27 |
+
options = ["Google Pixel 5", "OnePlus 9", "Samsung Galaxy S21", "Xiaomi Mi 11",'iPhone 12']
|
| 28 |
+
|
| 29 |
+
selected_option = st.sidebar.selectbox("Select phone model :", options)
|
| 30 |
+
|
| 31 |
+
if selected_option in options:
|
| 32 |
+
encoded_model = [1 if i == selected_option else 0 for i in options]
|
| 33 |
+
df = pd.DataFrame([encoded_model], columns=options)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
options1 = ["Android",'IOS']
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if selected_option =='iPhone 12':
|
| 43 |
+
selected_option1 = st.sidebar.selectbox("Select OS :", 'IOS')
|
| 44 |
+
encoded_os = [0,1]
|
| 45 |
+
else :
|
| 46 |
+
encoded_os = [1,0]
|
| 47 |
+
selected_option1 = st.sidebar.selectbox("Select OS :", 'Android')
|
| 48 |
+
df[options1] = encoded_os
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
options2 = ['Female','Male']
|
| 52 |
+
selected_option2 = st.sidebar.radio("Select Gender :", options2)
|
| 53 |
+
encoded_gender = [1 if i == selected_option2 else 0 for i in options2]
|
| 54 |
+
df[options2] = encoded_gender
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
app_time = st.sidebar.number_input('Enter app time : ',min_value=0.0,max_value=24.0,value=0.0)
|
| 58 |
+
df['App_Time(hours/day)'] = app_time
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
screen_time = st.sidebar.number_input('Enter your screen time : ',min_value=0.0,max_value=24.0,value=0.0)
|
| 62 |
+
df['screen_Time(hours/day)'] = screen_time
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
battary = st.sidebar.number_input('Enter battary drain(mAh) : ',min_value=100.0,max_value=6000.0,value=100.0)
|
| 66 |
+
df['Battery_Drain(mAh)'] = battary
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
no_app = st.sidebar.number_input('Enter number of apps installed : ',min_value=5.0,max_value=50.0,value=5.0)
|
| 70 |
+
df['Installed_app'] = no_app
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
data_use = st.sidebar.number_input('Enter data usage (GB) : ',min_value=0.0,max_value=10.0,value=0.0)
|
| 74 |
+
df['Data_Usage(GB)'] = data_use
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
age = st.sidebar.number_input('Enter your age : ',min_value=15.0,max_value=100.0,value=15.0)
|
| 78 |
+
df['Age'] = age
|
| 79 |
+
|
| 80 |
+
if st.button("Submit"):
|
| 81 |
+
st.write("Processing...")
|
| 82 |
+
time.sleep(2)
|
| 83 |
+
prediction = S_algo.predict(df)
|
| 84 |
+
if prediction==1:
|
| 85 |
+
|
| 86 |
+
st.write('Output : Occasional Users')
|
| 87 |
+
elif prediction==2:
|
| 88 |
+
st.write('Output : Casual Users ')
|
| 89 |
+
elif prediction==3:
|
| 90 |
+
st.write('Output : content consumer : ')
|
| 91 |
+
elif prediction==4:
|
| 92 |
+
st.write('Output : Social Media Enthusiasts')
|
| 93 |
+
else :
|
| 94 |
+
st.write('Output : Power Users')
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|