Spaces:
Sleeping
Sleeping
drmurataltun
commited on
Commit
•
7890a30
1
Parent(s):
18f410e
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,6 @@
|
|
3 |
|
4 |
# # Araba Fiyatı Tahmin Eden Model ve Deployment
|
5 |
|
6 |
-
# In[18]:
|
7 |
-
|
8 |
|
9 |
#import libraries
|
10 |
import pandas as pd
|
@@ -16,41 +14,26 @@ from sklearn.compose import ColumnTransformer
|
|
16 |
from sklearn.preprocessing import StandardScaler,OneHotEncoder
|
17 |
|
18 |
|
19 |
-
# In[19]:
|
20 |
-
|
21 |
|
22 |
#Load data
|
23 |
df=pd.read_excel('cars.xls')
|
24 |
|
25 |
|
26 |
-
# In[6]:
|
27 |
-
|
28 |
-
|
29 |
-
df.head()
|
30 |
-
|
31 |
-
|
32 |
-
# In[7]:
|
33 |
-
|
34 |
|
35 |
-
#df.to_csv('cars.csv',index=False)
|
36 |
|
37 |
|
38 |
-
# In[20]:
|
39 |
|
40 |
|
41 |
X=df.drop('Price',axis=1)
|
42 |
y=df[['Price']]
|
43 |
|
44 |
|
45 |
-
# In[21]:
|
46 |
-
|
47 |
|
48 |
X_train,X_test,y_train,y_test=train_test_split(X,y,
|
49 |
test_size=0.2,
|
50 |
random_state=42)
|
51 |
|
52 |
|
53 |
-
# In[22]:
|
54 |
|
55 |
|
56 |
preproccer=ColumnTransformer(transformers=[('num',StandardScaler(),
|
@@ -58,7 +41,6 @@ preproccer=ColumnTransformer(transformers=[('num',StandardScaler(),
|
|
58 |
('cat',OneHotEncoder(),['Make','Model','Trim','Type'])])
|
59 |
|
60 |
|
61 |
-
# In[23]:
|
62 |
|
63 |
|
64 |
model=LinearRegression()
|
@@ -68,10 +50,6 @@ pipe.fit(X_train,y_train)
|
|
68 |
y_pred=pipe.predict(X_test)
|
69 |
mean_squared_error(y_test,y_pred)**0.5,r2_score(y_test,y_pred)
|
70 |
|
71 |
-
|
72 |
-
# In[24]:
|
73 |
-
|
74 |
-
|
75 |
import streamlit as st
|
76 |
def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
|
77 |
input_data=pd.DataFrame({
|
@@ -90,27 +68,24 @@ def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,lea
|
|
90 |
})
|
91 |
prediction=pipe.predict(input_data)[0]
|
92 |
return prediction
|
93 |
-
st.title("
|
94 |
-
st.write("
|
95 |
-
make=st.selectbox("
|
96 |
model=st.selectbox("Model",df[df['Make']==make]['Model'].unique())
|
97 |
trim=st.selectbox("Trim",df[(df['Make']==make) & (df['Model']==model)]['Trim'].unique())
|
98 |
-
mileage=st.number_input("
|
99 |
-
car_type=st.selectbox("
|
100 |
-
cylinder=st.selectbox("
|
101 |
liter=st.number_input("Liter",1,6)
|
102 |
-
doors=st.selectbox("
|
103 |
-
cruise=st.radio("
|
104 |
-
sound=st.radio("
|
105 |
-
leather=st.radio("
|
106 |
-
if st.button("
|
107 |
pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)
|
108 |
|
109 |
st.write("Predicted Price :red_car: $",round(pred[0],2))
|
110 |
|
111 |
|
112 |
-
# In[ ]:
|
113 |
-
|
114 |
-
|
115 |
|
116 |
|
|
|
3 |
|
4 |
# # Araba Fiyatı Tahmin Eden Model ve Deployment
|
5 |
|
|
|
|
|
6 |
|
7 |
#import libraries
|
8 |
import pandas as pd
|
|
|
14 |
from sklearn.preprocessing import StandardScaler,OneHotEncoder
|
15 |
|
16 |
|
|
|
|
|
17 |
|
18 |
#Load data
|
19 |
df=pd.read_excel('cars.xls')
|
20 |
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
23 |
|
24 |
|
|
|
25 |
|
26 |
|
27 |
X=df.drop('Price',axis=1)
|
28 |
y=df[['Price']]
|
29 |
|
30 |
|
|
|
|
|
31 |
|
32 |
X_train,X_test,y_train,y_test=train_test_split(X,y,
|
33 |
test_size=0.2,
|
34 |
random_state=42)
|
35 |
|
36 |
|
|
|
37 |
|
38 |
|
39 |
preproccer=ColumnTransformer(transformers=[('num',StandardScaler(),
|
|
|
41 |
('cat',OneHotEncoder(),['Make','Model','Trim','Type'])])
|
42 |
|
43 |
|
|
|
44 |
|
45 |
|
46 |
model=LinearRegression()
|
|
|
50 |
y_pred=pipe.predict(X_test)
|
51 |
mean_squared_error(y_test,y_pred)**0.5,r2_score(y_test,y_pred)
|
52 |
|
|
|
|
|
|
|
|
|
53 |
import streamlit as st
|
54 |
def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
|
55 |
input_data=pd.DataFrame({
|
|
|
68 |
})
|
69 |
prediction=pipe.predict(input_data)[0]
|
70 |
return prediction
|
71 |
+
st.title("Araba Fiyatı Tahmin :red_car: @drmurataltun")
|
72 |
+
st.write("Arabanın özelliklerini seçin")
|
73 |
+
make=st.selectbox("Marka",df['Make'].unique())
|
74 |
model=st.selectbox("Model",df[df['Make']==make]['Model'].unique())
|
75 |
trim=st.selectbox("Trim",df[(df['Make']==make) & (df['Model']==model)]['Trim'].unique())
|
76 |
+
mileage=st.number_input("Kilometre",200,60000)
|
77 |
+
car_type=st.selectbox("Tipi",df[(df['Make']==make) & (df['Model']==model & df['Trim']==trim )['Type'].unique())
|
78 |
+
cylinder=st.selectbox("Silindir",df['Cylinder'].unique())
|
79 |
liter=st.number_input("Liter",1,6)
|
80 |
+
doors=st.selectbox("Kapı",df['Doors'].unique())
|
81 |
+
cruise=st.radio("Hız S.",[True,False])
|
82 |
+
sound=st.radio("Ses Sistemi",[True,False])
|
83 |
+
leather=st.radio("Deri döşeme",[True,False])
|
84 |
+
if st.button("Tahmin"):
|
85 |
pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)
|
86 |
|
87 |
st.write("Predicted Price :red_car: $",round(pred[0],2))
|
88 |
|
89 |
|
|
|
|
|
|
|
90 |
|
91 |
|