ConstantCoder commited on
Commit
117b31e
·
verified ·
1 Parent(s): d4a5730

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -84
app.py CHANGED
@@ -1,10 +1,7 @@
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
4
- # ## Car Prediction
5
- # İkinci el araç fiyatlarını (özelliklerine göre) tahmin eden modeller oluşturma ve MLOPs ile Hugging Fcae üzerinden yayımlayacağız
6
 
7
- # In[42]:
8
 
9
 
10
  import pandas as pd
@@ -17,63 +14,15 @@ from sklearn.pipeline import Pipeline # veri işleme hattı
17
  from sklearn.metrics import mean_squared_error, r2_score
18
 
19
 
20
- # In[2]:
21
-
22
-
23
- #excel dosyalarını okumak için
24
-
25
-
26
- # In[28]:
27
-
28
-
29
- get_ipython().system('pip install xldr')
30
-
31
-
32
- # # Veri dosyasını yükle
33
-
34
- # In[7]:
35
-
36
-
37
- ls
38
-
39
-
40
- # In[29]:
41
-
42
-
43
  df=pd.read_excel("cars.xls")
44
  df
45
 
46
-
47
- # In[30]:
48
-
49
-
50
- df.info()
51
-
52
-
53
- # In[10]:
54
-
55
-
56
- #veri ön işleme
57
-
58
-
59
- # In[31]:
60
-
61
-
62
  x=df.drop('Price',axis=1) #fiyat sütununu çıkar fiyata etki edenler kalsın
63
  y=df['Price'] #tahmin
64
 
65
 
66
- # In[32]:
67
-
68
-
69
  x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=42)
70
 
71
-
72
- # # Veri ön işleme, standartlaştırma ve OHE işlemlerini otomatikleştiriyoruz (standartlaştırıyoruz). Artık preprocess kullanarak kullanıcında arayüz aracılığıyla gelen veriyi modelimize uygun hale çevirebiliriz
73
-
74
- # In[33]:
75
-
76
-
77
  preprocess=ColumnTransformer(
78
  transformers=[
79
  ('num',StandardScaler(),['Mileage', 'Cylinder','Liter','Doors']),
@@ -82,27 +31,15 @@ preprocess=ColumnTransformer(
82
  )
83
 
84
 
85
- # In[34]:
86
-
87
-
88
  my_model=LinearRegression()
89
 
90
 
91
- # In[35]:
92
-
93
-
94
- #pipeline ı tanımla
95
  pipe=Pipeline(steps=[('preprocessor',preprocess),('model',my_model)])
96
 
97
 
98
- # In[38]:
99
-
100
-
101
- #pipeline fit
102
  pipe.fit(x_train,y_train)
103
 
104
 
105
- # In[43]:
106
 
107
 
108
  y_pred=pipe.predict(x_test)
@@ -110,26 +47,6 @@ print('RMSE',mean_squared_error(y_test,y_pred)**0.5)
110
  print('R2',r2_score(y_test,y_pred))
111
 
112
 
113
- # In[44]:
114
-
115
-
116
- #isterseniz veri setinin tammamıyla tekrar eğitim yapabilirsiniz.
117
- #pipe.fit(X,y)
118
-
119
-
120
- # ## Streamlit ile modeli yayma/deploy/kullanıma sunma
121
-
122
- # In[41]:
123
-
124
-
125
- get_ipython().system('pip install streamlit')
126
-
127
-
128
- # Python ile yapılan çalışmnalrın hızlı bir şekilde deploy edilmesi için HTML render arayüzler tasarlamanızı sağlar
129
-
130
- # In[47]:
131
-
132
-
133
  import streamlit as st
134
  #price tahmin fonksiyonu tanımla
135
  def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
@@ -164,7 +81,7 @@ if st.button('Tahmin Et'):
164
  st.write('Fiyat:$',round(pred[0],2))
165
 
166
 
167
- # In[ ]:
168
 
169
 
170
 
 
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
 
 
4
 
 
5
 
6
 
7
  import pandas as pd
 
14
  from sklearn.metrics import mean_squared_error, r2_score
15
 
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  df=pd.read_excel("cars.xls")
18
  df
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  x=df.drop('Price',axis=1) #fiyat sütununu çıkar fiyata etki edenler kalsın
21
  y=df['Price'] #tahmin
22
 
23
 
 
 
 
24
  x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=42)
25
 
 
 
 
 
 
 
26
  preprocess=ColumnTransformer(
27
  transformers=[
28
  ('num',StandardScaler(),['Mileage', 'Cylinder','Liter','Doors']),
 
31
  )
32
 
33
 
 
 
 
34
  my_model=LinearRegression()
35
 
36
 
 
 
 
 
37
  pipe=Pipeline(steps=[('preprocessor',preprocess),('model',my_model)])
38
 
39
 
 
 
 
 
40
  pipe.fit(x_train,y_train)
41
 
42
 
 
43
 
44
 
45
  y_pred=pipe.predict(x_test)
 
47
  print('R2',r2_score(y_test,y_pred))
48
 
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  import streamlit as st
51
  #price tahmin fonksiyonu tanımla
52
  def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
 
81
  st.write('Fiyat:$',round(pred[0],2))
82
 
83
 
84
+
85
 
86
 
87