Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# coding: utf-8
|
3 |
-
|
4 |
-
import pandas as pd
|
5 |
-
from sklearn.model_selection import train_test_split #veri setini bölme işlemleri
|
6 |
-
from sklearn.linear_model import LinearRegression #Doğrusal regresyon
|
7 |
-
from sklearn.metrics import r2_score,mean_squared_error #modelimizin performansını ölçmek için
|
8 |
-
from sklearn.compose import ColumnTransformer #Sütun dönüşüm işlemleri
|
9 |
-
from sklearn.preprocessing import OneHotEncoder, StandardScaler # kategori - sayısal dönüşüm ve ölçeklendirme
|
10 |
-
from sklearn.pipeline import Pipeline #Veri işleme hattı
|
11 |
-
df=pd.read_excel('cars.xls')
|
12 |
-
#df
|
13 |
-
|
14 |
-
df.info()
|
15 |
-
|
16 |
-
|
17 |
-
X=df.drop('Price',axis=1) #fiyat sütunu çıkar fiyata etki edenler kalsın
|
18 |
-
y=df['Price'] #tahmin
|
19 |
-
|
20 |
-
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)
|
21 |
-
|
22 |
-
|
23 |
-
preprocess=ColumnTransformer(
|
24 |
-
transformers=[
|
25 |
-
('num',StandardScaler(),['Mileage', 'Cylinder','Liter','Doors']),
|
26 |
-
('cat',OneHotEncoder(),['Make','Model','Trim','Type'])
|
27 |
-
]
|
28 |
-
)
|
29 |
-
|
30 |
-
|
31 |
-
my_model=LinearRegression()
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
#pipeline ı tanımla
|
36 |
-
pipe=Pipeline(steps=[('preprocessor',preprocess),('model',my_model)])
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
#pipeline fit
|
42 |
-
pipe.fit(X_train,y_train)
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
y_pred=pipe.predict(X_test)
|
47 |
-
print('RMSE',mean_squared_error(y_test,y_pred)**0.5)
|
48 |
-
print('R2',r2_score(y_test,y_pred))
|
49 |
-
|
50 |
-
df['Mileage'].max()
|
51 |
-
|
52 |
-
|
53 |
-
df['Type'].unique()
|
54 |
-
|
55 |
-
|
56 |
-
df['Liter'].max()
|
57 |
-
|
58 |
-
import streamlit as st
|
59 |
-
|
60 |
-
def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
|
61 |
-
input_data=pd.DataFrame({'Make':[make],
|
62 |
-
'Model':[model],
|
63 |
-
'Trim':[trim],
|
64 |
-
'Mileage':[mileage],
|
65 |
-
'Type':[car_type],
|
66 |
-
'Cylinder':[cylinder],
|
67 |
-
'Liter':[liter],
|
68 |
-
'Doors':[doors],
|
69 |
-
'Cruise':[cruise],
|
70 |
-
'Sound':[sound],
|
71 |
-
'Leather':[leather]})
|
72 |
-
prediction=pipe.predict(input_data)[0]
|
73 |
-
return prediction
|
74 |
-
st.title("AI kullanarak II. El Araba Fiyatı Tahmin:blue_car: MuR@TY@P")
|
75 |
-
st.write('Arabanın özelliklerini seçiniz')
|
76 |
-
make=st.selectbox('Marka',df['Make'].unique())
|
77 |
-
model=st.selectbox('Model',df[df['Make']==make]['Model'].unique())
|
78 |
-
trim=st.selectbox('Trim',df[(df['Make']==make) &(df['Model']==model)]['Trim'].unique())
|
79 |
-
mileage=st.number_input('Kilometre',100,200000)
|
80 |
-
car_type=st.selectbox('Araç Tipi',df[(df['Make']==make) &(df['Model']==model)&(df['Trim']==trim)]['Type'].unique())
|
81 |
-
cylinder=st.selectbox('Cylinder',df['Cylinder'].unique())
|
82 |
-
liter=st.number_input('Yakıt hacmi',1,10)
|
83 |
-
doors=st.selectbox('Kapı sayısı',df['Doors'].unique())
|
84 |
-
cruise=st.radio('Hız Sbt.',[True,False])
|
85 |
-
sound=st.radio('Ses Sis.',[True,False])
|
86 |
-
leather=st.radio('Deri döşeme.',[True,False])
|
87 |
-
if st.button('Tahmin'):
|
88 |
-
pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)
|
89 |
-
st.write('Fiyat:$', round(pred[0],2))
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|