Spaces:
Runtime error
Runtime error
Upload 5 files
Browse files- app.py +28 -0
- eda.py +81 -0
- feature.txt +1 -0
- model.pkl +3 -0
- prediction.py +86 -0
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import Library
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Import the created Streamlit Page
|
5 |
+
import eda
|
6 |
+
import prediction
|
7 |
+
|
8 |
+
# Navigation button
|
9 |
+
navigasi = st.sidebar.selectbox(label='Select Page:', options=['Home Page', 'Exploratory Data Analysis', 'Prediction'])
|
10 |
+
|
11 |
+
# Looping for navigation
|
12 |
+
if navigasi == 'Home Page':
|
13 |
+
st.image("https://storage.googleapis.com/danacita-website-v3-prd/website_v3/images/biaya_bootcamp__kursus_hacktiv8_6.original.png")
|
14 |
+
st.header('Milestone 2')
|
15 |
+
st.write('')
|
16 |
+
st.write('Name : Salsa Sabitha Hurriyah')
|
17 |
+
st.write('Batch : HCK - 014')
|
18 |
+
st.write('Classification Model for Predicting Mobile Price Range')
|
19 |
+
st.write('')
|
20 |
+
st.caption('Please select another menu in the Select Box on the left of your screen to start!')
|
21 |
+
|
22 |
+
# Displays the EDA page
|
23 |
+
elif navigasi == 'Exploratory Data Analysis':
|
24 |
+
eda.run()
|
25 |
+
|
26 |
+
# Displays the Predict page
|
27 |
+
elif navigasi == 'Prediction':
|
28 |
+
prediction.run()
|
eda.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import library
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import seaborn as sns
|
7 |
+
import plotly.express as px
|
8 |
+
import json
|
9 |
+
|
10 |
+
# Load feature file
|
11 |
+
with open('feature.txt', 'r') as file:
|
12 |
+
feature = json.load(file)
|
13 |
+
|
14 |
+
# Set Config Halaman
|
15 |
+
st.set_page_config(
|
16 |
+
page_title = "Exploratory Data Analysis (EDA)",
|
17 |
+
)
|
18 |
+
|
19 |
+
def run():
|
20 |
+
|
21 |
+
# Set Judul
|
22 |
+
st.title("Exploratory Data Analysis (EDA)")
|
23 |
+
|
24 |
+
# Load Data
|
25 |
+
df = pd.read_csv("/Users/salsasabithah/Documents/FTDS/1-Phase/Milestone 2/p1-ftds014-hck-m2-Salsasbth/Mobile_Price_Classification.csv")
|
26 |
+
|
27 |
+
# Create dataset header
|
28 |
+
st.subheader("Dataset Mobile Price Classification")
|
29 |
+
|
30 |
+
# Display the dataframe on streamlit
|
31 |
+
st.dataframe(df)
|
32 |
+
st.markdown('---')
|
33 |
+
|
34 |
+
# Display data distribution for each price range
|
35 |
+
st.subheader("Data Distribution for Each Price Range")
|
36 |
+
|
37 |
+
# Check how much data is in each price range
|
38 |
+
price_range_counts = df['price_range'].value_counts()
|
39 |
+
|
40 |
+
# Show the amount of data in each price category
|
41 |
+
st.write("Amount of Data in Each Price Rategory :")
|
42 |
+
st.write(price_range_counts)
|
43 |
+
|
44 |
+
# Show plot of price categories
|
45 |
+
st.write("Plot of the price category :")
|
46 |
+
colors = ['blue', 'green', 'orange', 'red']
|
47 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
48 |
+
ax.pie(price_range_counts, labels=price_range_counts.index, autopct='%1.1f%%', colors=colors)
|
49 |
+
st.pyplot(fig)
|
50 |
+
|
51 |
+
st.write('The amount of data in each price range is same, as 500 data for each price range.')
|
52 |
+
st.markdown('---')
|
53 |
+
|
54 |
+
# Display data distribution for each feature selected per price range
|
55 |
+
# Looping through each feature
|
56 |
+
for selected_column in feature:
|
57 |
+
|
58 |
+
# View the average in each price_range
|
59 |
+
mean_col = df.groupby('price_range')[selected_column].mean().sort_values()
|
60 |
+
|
61 |
+
# Title for each plot
|
62 |
+
plot_title = 'Average of {} column per Price Range'.format(selected_column)
|
63 |
+
st.subheader(plot_title)
|
64 |
+
|
65 |
+
# Color to use for each bar
|
66 |
+
colors = ['blue', 'green', 'orange', 'red']
|
67 |
+
|
68 |
+
# Visualization of average in each price_range
|
69 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
70 |
+
mean_col.plot.barh(color=colors, ax=ax)
|
71 |
+
|
72 |
+
# Add labels
|
73 |
+
ax.set_xlabel("Average of '{}' column".format(selected_column))
|
74 |
+
ax.set_ylabel('Price Range')
|
75 |
+
|
76 |
+
# Plot displays
|
77 |
+
st.pyplot(fig)
|
78 |
+
st.markdown('---')
|
79 |
+
|
80 |
+
if __name__== '__main__':
|
81 |
+
run()
|
feature.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
["battery_power", "pc", "px_height", "px_width", "ram", "wifi"]
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ccb4c16d978c357b3d34bf4a0fbdbfb038b6331bbc7e6f01fc273fed12c452b
|
3 |
+
size 31144
|
prediction.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import library
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import pickle
|
6 |
+
import json
|
7 |
+
|
8 |
+
# Load Model
|
9 |
+
with open('model.pkl', 'rb') as file:
|
10 |
+
model = pickle.load(file)
|
11 |
+
with open('feature.txt', 'r') as file:
|
12 |
+
feature = json.load(file)
|
13 |
+
|
14 |
+
# Function to run streamlit model predictor
|
15 |
+
def run():
|
16 |
+
|
17 |
+
# Set Title
|
18 |
+
st.title("Predict the Price Range of a Mobile Based on its Features")
|
19 |
+
st.markdown('---')
|
20 |
+
|
21 |
+
# Create a Form for Data Inference
|
22 |
+
st.markdown('## Input Data')
|
23 |
+
with st.form('my_form'):
|
24 |
+
battery_power = st.number_input('Battery Power', min_value=500, max_value=8000)
|
25 |
+
blue = st.selectbox('Has bluetooth or not? 0 = No, Yes = 1', (0,1))
|
26 |
+
clock_speed = st.number_input('Clock Speed (Speed at Wich Microprocessor Execute Instruction)', min_value=0.5, max_value=3.0)
|
27 |
+
dual_sim = st.selectbox('Has dual sim or not? 0 = No, Yes = 1', (0,1))
|
28 |
+
fc = st.number_input('Front Camera mega pixels', min_value=0, max_value=40)
|
29 |
+
four_g = st.selectbox('Has 4G or not? 0 = No, Yes = 1', (0,1))
|
30 |
+
int_memory = st.number_input('Internal Memory in Gigabytes', min_value=2, max_value=256)
|
31 |
+
m_dep = st.number_input('Mobile Depth in cm', min_value=0.1, max_value=1.0)
|
32 |
+
mobile_wt = st.number_input('Weight of Mobilephone', min_value=80, max_value=300)
|
33 |
+
n_cores = st.number_input('Number of Cores of Processor', min_value=1, max_value=10)
|
34 |
+
pc = st.number_input('Primary Camera mega pixels', min_value=0, max_value=20)
|
35 |
+
px_height = st.number_input('Pixel Resolution Height', min_value=0, max_value=2000)
|
36 |
+
px_width = st.number_input('Pixel Resolution Width', min_value=500, max_value=2000)
|
37 |
+
ram = st.number_input('RAM in Megabytes', min_value=256, max_value=4000)
|
38 |
+
sc_h = st.number_input('Screen Height of Mobile in cm', min_value=5, max_value=20)
|
39 |
+
sc_w = st.number_input('Screen Width of Mobile in cm', min_value=1, max_value=15)
|
40 |
+
talk_time = st.number_input('The Longest Time for one battery charge when you use it', min_value=2, max_value=168)
|
41 |
+
three_g = st.selectbox('Has 3G or not? 0 = No, Yes = 1', (0,1))
|
42 |
+
touch_screen = st.selectbox('Has touch_screen or not? 0 = No, Yes = 1', (0,1))
|
43 |
+
wifi = st.selectbox('Has wifi or not? 0 = No, Yes = 1', (0,1))
|
44 |
+
|
45 |
+
# Create a button to make predictions
|
46 |
+
submitted = st.form_submit_button("Predict")
|
47 |
+
|
48 |
+
# Dataframe
|
49 |
+
data = {'battery_power': battery_power,
|
50 |
+
'blue': blue,
|
51 |
+
'clock_speed': clock_speed,
|
52 |
+
'dual_sim': dual_sim,
|
53 |
+
'fc': fc,
|
54 |
+
'four_g': four_g,
|
55 |
+
'int_memory': int_memory,
|
56 |
+
'm_dep': m_dep,
|
57 |
+
'mobile_wt': mobile_wt,
|
58 |
+
'n_cores': n_cores,
|
59 |
+
'pc': pc,
|
60 |
+
'px_height': px_height,
|
61 |
+
'px_width': px_width,
|
62 |
+
'ram': ram,
|
63 |
+
'sc_h': sc_h,
|
64 |
+
'sc_w': sc_w,
|
65 |
+
'talk_time': talk_time,
|
66 |
+
'three_g': three_g,
|
67 |
+
'touch_screen': touch_screen,
|
68 |
+
'wifi': wifi}
|
69 |
+
|
70 |
+
df = pd.DataFrame([data])
|
71 |
+
st.dataframe(df)
|
72 |
+
|
73 |
+
if submitted:
|
74 |
+
df_selected = df[feature]
|
75 |
+
y_pred_inf = model.predict(df_selected)
|
76 |
+
if y_pred_inf[0] == 0:
|
77 |
+
st.subheader('~ The Mobile Features you Enter is in "Entry-Level" price ~')
|
78 |
+
elif y_pred_inf[0] == 1:
|
79 |
+
st.write('~ The Mobile Features you Enter is in "Mid-Range" price ~')
|
80 |
+
elif y_pred_inf[0] == 2:
|
81 |
+
st.write('~ The Mobile Features you Enter is in "High-End" price ~')
|
82 |
+
elif y_pred_inf[0] == 3:
|
83 |
+
st.write('~ The Mobile Features you Enter is in "Flagship" price ~')
|
84 |
+
|
85 |
+
if __name__== '__main__':
|
86 |
+
run()
|