drmurataltun commited on
Commit
18f410e
1 Parent(s): da600de

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +116 -0
  2. cars.xls +0 -0
  3. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # # Araba Fiyatı Tahmin Eden Model ve Deployment
5
+
6
+ # In[18]:
7
+
8
+
9
+ #import libraries
10
+ import pandas as pd
11
+ from sklearn.model_selection import train_test_split
12
+ from sklearn.linear_model import LinearRegression
13
+ from sklearn.metrics import r2_score,mean_squared_error
14
+ from sklearn.pipeline import Pipeline
15
+ 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(),
57
+ ['Mileage','Cylinder','Liter','Doors']),
58
+ ('cat',OneHotEncoder(),['Make','Model','Trim','Type'])])
59
+
60
+
61
+ # In[23]:
62
+
63
+
64
+ model=LinearRegression()
65
+ pipe=Pipeline(steps=[('preprocessor',preproccer),
66
+ ('model',model)])
67
+ 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({
78
+ 'Make':[make],
79
+ 'Model':[model],
80
+ 'Trim':[trim],
81
+ 'Mileage':[mileage],
82
+ 'Type':[car_type],
83
+ 'Car_type':[car_type],
84
+ 'Cylinder':[cylinder],
85
+ 'Liter':[liter],
86
+ 'Doors':[doors],
87
+ 'Cruise':[cruise],
88
+ 'Sound':[sound],
89
+ 'Leather':[leather]
90
+ })
91
+ prediction=pipe.predict(input_data)[0]
92
+ return prediction
93
+ st.title("Car Price Prediction :red_car: @drmurataltun")
94
+ st.write("Enter Car Details to predict the price of the car")
95
+ make=st.selectbox("Make",df['Make'].unique())
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("Mileage",200,60000)
99
+ car_type=st.selectbox("Type",df['Type'].unique())
100
+ cylinder=st.selectbox("Cylinder",df['Cylinder'].unique())
101
+ liter=st.number_input("Liter",1,6)
102
+ doors=st.selectbox("Doors",df['Doors'].unique())
103
+ cruise=st.radio("Cruise",[True,False])
104
+ sound=st.radio("Sound",[True,False])
105
+ leather=st.radio("Leather",[True,False])
106
+ if st.button("Predict"):
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
+
cars.xls ADDED
Binary file (142 kB). View file
 
requirements.txt ADDED
Binary file (150 Bytes). View file