Spaces:
Sleeping
Sleeping
File size: 2,690 Bytes
153b6f3 2eeccd1 153b6f3 2636d8c 153b6f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
#!/usr/bin/env python
# coding: utf-8
# In[20]:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder,StandardScaler
from sklearn.pipeline import Pipeline
# In[21]:
df=pd.read_excel('cars.xls')
df.head()
# In[22]:
#pip install xlrd
# In[23]:
X=df.drop('Price', axis=1)
y=df['Price']
# In[24]:
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)
# In[25]:
#!pip install ydata-profiling
# In[26]:
#import ydata_profiling
# In[27]:
#df.profile_report()
# In[28]:
preprocess=ColumnTransformer(transformers=[
('num',StandardScaler(),['Mileage','Cylinder','Liter','Doors']),
('cat',OneHotEncoder(),['Make','Model','Trim','Type'])])
# Veri önişlemedeki standartlaşma ve one-hot kodlama işlemlerini otomatikleştiriyoruz.
# Artık preprocess kullanarak kullanıcıdan gelen veriyi modelimize uygun girdi haline dçnüştürebiliriz.
# In[31]:
model=LinearRegression()
pipe=Pipeline(steps=[('preprocesor', preprocess), ('model', model)])
# In[32]:
pipe.fit(X_train, y_train)
# In[33]:
y_pred=pipe.predict(X_test)
mean_squared_error(y_test,y_pred)**0.5,r2_score(y_test,y_pred)
# In[ ]:
import streamlit as st
def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):
input_data=pd.DataFrame({
'Make':[make],
'Model':[model],
'Trim':[trim],
'Mileage':[mileage],
'Type':[car_type],
'Car_type':[car_type],
'Cylinder':[cylinder],
'Liter':[liter],
'Doors':[doors],
'Cruise':[cruise],
'Sound':[sound],
'Leather':[leather]
})
prediction=pipe.predict(input_data)[0]
return prediction
st.title("Car Price Prediction :red_car: ")
st.write("Enter Car Details to predict the price of the car")
make=st.selectbox("Make",df['Make'].unique())
model=st.selectbox("Model",df[df['Make']==make]['Model'].unique())
trim=st.selectbox("Trim",df[(df['Make']==make) & (df['Model']==model)]['Trim'].unique())
mileage=st.number_input("Mileage",200,60000)
car_type=st.selectbox("Type",df['Type'].unique())
cylinder=st.selectbox("Cylinder",df['Cylinder'].unique())
liter=st.number_input("Liter",1,6)
doors=st.selectbox("Doors",df['Doors'].unique())
cruise=st.radio("Cruise",[True,False])
sound=st.radio("Sound",[True,False])
leather=st.radio("Leather",[True,False])
if st.button("Predict"):
pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)
st.write("Predicted Price :red_car: $",round(pred[0],2))
# In[ ]:
|