File size: 3,177 Bytes
5725247
 
 
 
 
9b58893
5725247
 
 
9b58893
 
 
e4ae7b5
ddc3c92
fb2cdea
197609a
9b58893
 
 
 
 
430f47b
9b58893
fb2cdea
9b58893
4c16457
 
197609a
5725247
 
e4ae7b5
5725247
 
 
 
e4ae7b5
5725247
 
 
 
 
 
 
e4ae7b5
5725247
9b58893
5725247
7258f72
28e0b03
5725247
 
 
 
e4ae7b5
5725247
 
 
 
 
 
e4ae7b5
a20ef1d
5725247
e4ae7b5
3713ad4
e4ae7b5
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
import pandas as pd
import numpy as np
import warnings
warnings.filterwarnings('ignore')

dataset = pd.read_csv('clean_car.csv')
df = dataset.copy()
from sklearn.model_selection import train_test_split

X = df.drop('Price', axis=1)
y = df['Price']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15, random_state=43)

from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.ensemble import HistGradientBoostingRegressor
hgbr = HistGradientBoostingRegressor()
num_features = X.select_dtypes(include=['int64']).columns
cat_features = X.select_dtypes(include='object').columns
transformer = ColumnTransformer(transformers=[('num', StandardScaler(), num_features),('cat', OneHotEncoder(sparse_output=False), cat_features)])
pipe = Pipeline(steps=[('preprocessor', transformer), ('model', hgbr)])

pipe.fit(X_train, y_train)
score = pipe.score(X_test,y_test)
y_pred = pipe.predict(X_test)
mse = mean_squared_error(y_test,y_pred)
import streamlit as st

def price(companyName,modelName,modelYear,locaiton,mileage,engineType,engineCapacity,color,assembly,bodyType,transmissionType,registrationStatus):
  input_data = pd.DataFrame({
      'Company Name':[companyName],
      'Model Name':[modelName],
      'Model Year':[modelYear],
      'Location':[locaiton],
      'Mileage':[mileage],
      'Engine Type':[engineType],
      'Engine Capacity':[engineCapacity],
      'Color':[color],
      'Assembly':[assembly],
      'Body Type':[bodyType],
      'Transmission Type':[transmissionType],
      'Registration Status':[registrationStatus]
  })
  prediction=pipe.predict(input_data)[0]
  return prediction
st.title('Car Price Prediction :car: :arrow_forward: :dollar: @yusufenes')
st.success(f'Accuracy : {score.round(5)}')
st.write('Please Chose Car Specifications')
companyName = st.selectbox('Company Name',df['Company Name'].unique())
modelName = st.selectbox('Model Name',df[df['Company Name']==companyName]['Model Name'].unique())
modelYear = st.selectbox('Model Year',df[(df['Company Name']==companyName)&(df['Model Name'] == modelName)]['Model Year'].unique())
locaiton = st.selectbox('Location',df['Location'].unique())
mileage = st.number_input('Mileage',df['Mileage'].min(),df['Mileage'].max())
engineType = st.selectbox('Engine Type',df['Engine Type'].unique())
engineCapacity = st.number_input('Engine Capacity',df['Engine Capacity'].min(),df['Engine Capacity'].max())
color = st.selectbox('Color',df['Color'].unique())
assembly = st.selectbox('Assembly',df['Assembly'].unique())
bodyType = st.selectbox('Body Type',df['Body Type'].unique())
transmissionType = st.selectbox('Transmission Type',df['Transmission Type'].unique())
registrationStatus = st.selectbox('Registration Status',df['Registration Status'].unique())
if st.button('Predict'):
  pred=price(companyName,modelName,modelYear,locaiton,mileage,engineType,engineCapacity,color,assembly,bodyType,transmissionType,registrationStatus)
  st.success(f'The predicted price is :red_car: {pred.round(2)} :heavy_dollar_sign:')
  st.balloons()