demethantas commited on
Commit
566b91b
1 Parent(s): 97e6d32

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +91 -0
  2. cars.xls +0 -0
  3. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # # Araba Fiyatı Tahmin Eden Model ve Deployment
5
+
6
+
7
+ #import libraries
8
+ import pandas as pd
9
+ from sklearn.model_selection import train_test_split
10
+ from sklearn.linear_model import LinearRegression
11
+ from sklearn.metrics import r2_score,mean_squared_error
12
+ from sklearn.pipeline import Pipeline
13
+ from sklearn.compose import ColumnTransformer
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(),
40
+ ['Mileage','Cylinder','Liter','Doors']),
41
+ ('cat',OneHotEncoder(),['Make','Model','Trim','Type'])])
42
+
43
+
44
+
45
+
46
+ model=LinearRegression()
47
+ pipe=Pipeline(steps=[('preprocessor',preproccer),
48
+ ('model',model)])
49
+ pipe.fit(X_train,y_train)
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({
56
+ 'Make':[make],
57
+ 'Model':[model],
58
+ 'Trim':[trim],
59
+ 'Mileage':[mileage],
60
+ 'Type':[car_type],
61
+ 'Car_type':[car_type],
62
+ 'Cylinder':[cylinder],
63
+ 'Liter':[liter],
64
+ 'Doors':[doors],
65
+ 'Cruise':[cruise],
66
+ 'Sound':[sound],
67
+ 'Leather':[leather]
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
+
cars.xls ADDED
Binary file (142 kB). View file
 
requirements.txt ADDED
Binary file (150 Bytes). View file