aliicemill commited on
Commit
dbd98c3
·
verified ·
1 Parent(s): e7be0a3

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +78 -0
  2. cars.xls +0 -0
  3. ozellikler_CarPred.png +0 -0
  4. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ # author : @ Ali Cemil Özdemir
4
+
5
+ # Model that predicts car prices.
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
+ # upload data
17
+ df=pd.read_excel('cars.xls')
18
+
19
+ # create axis
20
+ X=df.drop('Price',axis=1)
21
+ y=df[['Price']]
22
+
23
+ # split data as train and test data.
24
+ X_train,X_test,y_train,y_test=train_test_split(X,y,
25
+ test_size=0.2,
26
+ random_state=42)
27
+
28
+
29
+ # preprocessing
30
+ preproccer=ColumnTransformer(transformers=[('num',StandardScaler(),
31
+ ['Mileage','Cylinder','Liter','Doors']),
32
+ ('cat',OneHotEncoder(),['Make','Model','Trim','Type'])])
33
+
34
+ # modelling
35
+ model=LinearRegression()
36
+ pipe=Pipeline(steps=[('preprocessor',preproccer),
37
+ ('model',model)])
38
+ pipe.fit(X_train,y_train)
39
+ y_pred=pipe.predict(X_test)
40
+ mean_squared_error(y_test,y_pred)**0.5,r2_score(y_test,y_pred)
41
+
42
+ # web interface
43
+ import streamlit as st
44
+ def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
45
+ input_data=pd.DataFrame({
46
+ 'Make':[make],
47
+ 'Model':[model],
48
+ 'Trim':[trim],
49
+ 'Mileage':[mileage],
50
+ 'Type':[car_type],
51
+ 'Car_type':[car_type],
52
+ 'Cylinder':[cylinder],
53
+ 'Liter':[liter],
54
+ 'Doors':[doors],
55
+ 'Cruise':[cruise],
56
+ 'Sound':[sound],
57
+ 'Leather':[leather]
58
+ })
59
+ prediction=pipe.predict(input_data)[0]
60
+ return prediction
61
+ st.title("Car Price Prediction :red_car: @Ali Cemil Özdemir")
62
+ st.write("Enter Car Details to predict the price of the car")
63
+ st.image("ozellikler_CarPred.png", caption="Car Features", use_column_width=True)
64
+ make=st.selectbox("Make",df['Make'].unique())
65
+ model=st.selectbox("Model",df[df['Make']==make]['Model'].unique())
66
+ trim=st.selectbox("Trim",df[(df['Make']==make) & (df['Model']==model)]['Trim'].unique())
67
+ mileage=st.number_input("Mileage",200,60000)
68
+ car_type=st.selectbox("Type",df['Type'].unique())
69
+ cylinder=st.selectbox("Cylinder",df['Cylinder'].unique())
70
+ liter=st.number_input("Liter",1,6)
71
+ doors=st.selectbox("Doors",df['Doors'].unique())
72
+ cruise=st.radio("Cruise",[True,False])
73
+ sound=st.radio("Sound",[True,False])
74
+ leather=st.radio("Leather",[True,False])
75
+ if st.button("Predict"):
76
+ pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)
77
+
78
+ st.write("Predicted Price :red_car: $",round(pred[0],2))
cars.xls ADDED
Binary file (142 kB). View file
 
ozellikler_CarPred.png ADDED
requirements.txt ADDED
Binary file (150 Bytes). View file