saliharana commited on
Commit
9072a35
·
verified ·
1 Parent(s): 6ff5be3

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +121 -0
  2. cars.xls +0 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """car_predict_price_app.iypnb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1MuVvbWw5xuPmG6VpSGWB59no-ij4Dmto
8
+
9
+ # Car Prediction #
10
+ İkinci el araç fiyatlarını (özelliklerine göre) tahmin eden modeller oluşturma ve MLOPs ile Hugging Face üzerinden yayımlayacağız.
11
+ """
12
+
13
+ import pandas as pd
14
+ from sklearn.model_selection import train_test_split #veri setini bölme işlemleri
15
+ from sklearn.linear_model import LinearRegression #Doğrusal regresyon
16
+ from sklearn.metrics import r2_score,mean_squared_error #modelimizin performansını ölçmek için
17
+ from sklearn.compose import ColumnTransformer #Sütun dönüşüm işlemleri
18
+ from sklearn.preprocessing import OneHotEncoder, StandardScaler # kategori - sayısal dönüşüm ve ölçeklendirme
19
+ from sklearn.pipeline import Pipeline #Veri işleme hattı
20
+
21
+ #Excell dosyalarını okumak için
22
+
23
+ !pip install xldr
24
+
25
+ """## Veri dosyasını yükle"""
26
+
27
+ ls
28
+
29
+ df=pd.read_excel('cars.xls')
30
+ df
31
+
32
+ df.info()
33
+
34
+ # Veri ön işleme
35
+
36
+ X=df.drop('Price',axis=1) #fiyat sütunu çıkar fiyata etki edenler kalsın
37
+ y=df['Price'] #tahmin
38
+
39
+ X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)
40
+
41
+ """#### Veri ön işleme, standartlaştırma ve OHE işlemlerini otomatikleştiriyoruz (standarlaştırıyoruz). Artık preprocess kullanarak kullanıcında arayüz aracılığıyla gelen veriyi mdoelimize uygun hale çevirebiliriz.
42
+
43
+ """
44
+
45
+ preprocess=ColumnTransformer(
46
+ transformers=[
47
+ ('num',StandardScaler(),['Mileage', 'Cylinder','Liter','Doors']),
48
+ ('cat',OneHotEncoder(),['Make','Model','Trim','Type'])
49
+ ]
50
+ )
51
+
52
+ my_model=LinearRegression()
53
+
54
+ #pipeline ı tanımla
55
+ pipe=Pipeline(steps=[('preprocessor',preprocess),('model',my_model)])
56
+
57
+ #pipeline fit
58
+ pipe.fit(X_train,y_train)
59
+
60
+ y_pred=pipe.predict(X_test)
61
+ print('RMSE',mean_squared_error(y_test,y_pred)**0.5)
62
+ print('R2',r2_score(y_test,y_pred))
63
+
64
+ #isterseniz veri setinin tammamıyla tekrar eğitim yapabilirsiniz.
65
+ #pipe.fit(X,y)
66
+
67
+ """## Streamlit ile modeli yayma/deploy/kullanıma sunma"""
68
+
69
+ !pip install streamlit
70
+
71
+ df['Mileage'].max()
72
+
73
+ df['Type'].unique()
74
+
75
+ df['Liter'].max()
76
+
77
+ """#### Python ile yapılan çalışmnalrın hızlı bir şekilde deploy edilmesi için HTML render arayüzler tasarlamanızı sağlar."""
78
+
79
+ import streamlit as st
80
+ #price tahmin fonksiyonu tanımla
81
+ def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
82
+ input_data=pd.DataFrame({'Make':[make],
83
+ 'Model':[model],
84
+ 'Trim':[trim],
85
+ 'Mileage':[mileage],
86
+ 'Type':[car_type],
87
+ 'Cylinder':[cylinder],
88
+ 'Liter':[liter],
89
+ 'Doors':[doors],
90
+ 'Cruise':[cruise],
91
+ 'Sound':[sound],
92
+ 'Leather':[leather]})
93
+ prediction=pipe.predict(input_data)[0]
94
+ return prediction
95
+ st.title("Car Price Prediction:red_car: @SalihaRanaUzun")
96
+ st.write('Enter the Car Details to predict its price')
97
+ make=st.selectbox('Make',df['Make'].unique())
98
+ model=st.selectbox('Model',df[df['Make']==make]['Model'].unique())
99
+ trim=st.selectbox('Trim',df[(df['Make']==make) &(df['Model']==model)]['Trim'].unique())
100
+ mileage=st.number_input('Mileage',100,200000)
101
+ car_type=st.selectbox('Type',df[(df['Make']==make) &(df['Model']==model)&(df['Trim']==trim)]['Type'].unique())
102
+ cylinder=st.selectbox('Cylinder',df['Cylinder'].unique())
103
+ liter=st.number_input('Liter',1,10)
104
+ doors=st.selectbox('Doors',df['Doors'].unique())
105
+ cruise=st.radio('Cruise',[True,False])
106
+ sound=st.radio('Sound',[True,False])
107
+ leather=st.radio('Leather',[True,False])
108
+ if st.button('Predict'):
109
+ pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)
110
+ st.write('Price:$', round(pred[0],2))
111
+
112
+ #streamlit run C:\ProgramData\anaconda3\Lib\site-packages\ipykernel_launcher.py
113
+
114
+ """libraries:
115
+ * Streamlit==1.31.1
116
+ * scikit-learn==1.4.1.post1
117
+ * pandas==2.1.0
118
+ * xlrd==2.0.1
119
+
120
+ """
121
+
cars.xls ADDED
Binary file (142 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.31.1
2
+ scikit-learn==1.4.1.post1
3
+ pandas==2.1.0
4
+ xlrd==2.0.1