-
Notifications
You must be signed in to change notification settings - Fork 0
/
price.py
95 lines (81 loc) · 4.07 KB
/
price.py
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
import pickle
import streamlit as st
import pandas as pd
import numpy as np
#from streamlit_option_menu import option_menu
# loading the saved model
price_model = pickle.load(open('finalized_model.sav', 'rb'))
# page title
st.title('Used Phone Price Prediction using ML')
st.markdown(
f'<div style="display: flex; justify-content: center;"><img src="https://i.pinimg.com/originals/70/7c/39/707c39bfff546612b5b4604fe86cda32.gif" width="300"></div>',
unsafe_allow_html=True,
)
# Define the categories for each column
device_categories = ('Others', 'Samsung', 'Huawei', 'LG', 'Lenovo', 'ZTE', 'Xiaomi', 'Oppo', 'Asus', 'Alcatel',
'Micromax', 'Vivo', 'Honor', 'HTC', 'Nokia', 'Motorola', 'Sony', 'Meizu', 'Gionee', 'Acer',
'XOLO', 'Panasonic', 'Realme', 'Apple', 'Lava', 'Celkon', 'Spice', 'Karbonn', 'Coolpad',
'BlackBerry', 'Microsoft', 'OnePlus', 'Google', 'Infinix')
os_categories = ('Android', 'Others', 'iOS', 'Windows')
_4g_categories = ('yes', 'no')
_5g_categories = ('yes', 'no')
# Display select boxes for each categorical column
device_type = st.selectbox('Device type', device_categories)
os_type = st.selectbox('OS type', os_categories)
screen_size = st.number_input('Screen size in cm')
_4g = st.selectbox('4G supported', _4g_categories)
_5g = st.selectbox('5G supported', _5g_categories)
rear_camera_mp = st.number_input('Rear camera value in megapixels')
front_camera_mp = st.number_input('Front camera value in megapixels')
internal_memory = st.number_input('Internal memory(ROM) in GB',step=1)
ram = st.number_input('RAM in GB',step=1)
battery = st.number_input('Energy capacity of the device battery in mAh',step=1)
weight = st.number_input('Weight of the device in grams',step=1)
release_year = st.number_input("Year when the device model was released",step=1)
days_used= st.number_input("Number of days the used/refurbished device has been used",step=1)
new_price=st.number_input("Enter the price new device of the same model in Rupees",step=1)
features_values = {'device_type': device_type, 'os_type': os_type, '4g': _4g, '5g': _5g,
'screen_size': screen_size, 'Rear_camera_mp': rear_camera_mp,
'Front_camera_mp': front_camera_mp, 'Internal_memory': internal_memory,
'RAM': ram, 'Battery': battery, 'Weight': weight,
'Release_year': release_year, 'Days_used': days_used,
'new_price': new_price}
if st.button('Submit'):
if any(value == 0 or value == 0.00 for value in features_values.values()):
st.warning('Please input all the details.')
else:
# converting to euro and denormalizing the price
new_price= new_price/89.87
normalized_new_price=np.log(new_price)
# Create a DataFrame with the input values
data = pd.DataFrame({
'Device_type': [device_type],
'OS_type': [os_type],
'4g': [_4g],
'5g': [_5g],
'screen_size': [screen_size],
'Rear_camera_mp': [rear_camera_mp],
'Front_camera_mp': [front_camera_mp],
'Internal_memory': [internal_memory],
'RAM': [ram],
'Battery': [battery],
'Weight': [weight],
'Release_year': [release_year],
'Days_used': [days_used],
'Normalized_new_price': [normalized_new_price]
})
data_1 = pd.DataFrame({'screen_size': [screen_size],
'Rear_camera_mp': [rear_camera_mp],
'Front_camera_mp': [front_camera_mp],
'Battery': [battery],
'Normalized_new_price': [normalized_new_price]
})
# Perform one-hot encoding for categorical variables
data_encoded = pd.get_dummies(data_1)
# Predict the used price using the model
prediction = price_model.predict(data_encoded)
#st.write('Predicted used price:', prediction)
p=np.exp(prediction)
#indian rupee conversion
p=p*89.87
st.success(f'Price of the used/refurbished device: ₹ {round(p[0], 2)}')