Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import numpy as np
|
| 3 |
import warnings
|
|
@@ -25,34 +34,40 @@ from sklearn.model_selection import train_test_split
|
|
| 25 |
def train_test(df):
|
| 26 |
X=df.drop('Price',axis=1)
|
| 27 |
y=df['Price']
|
| 28 |
-
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.
|
| 29 |
return X_train,X_test,y_train,y_test
|
| 30 |
|
| 31 |
-
|
| 32 |
-
X_train
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
from sklearn.pipeline import Pipeline
|
| 35 |
-
from sklearn.compose import ColumnTransformer
|
| 36 |
-
from sklearn.preprocessing import OneHotEncoder
|
| 37 |
-
from sklearn.preprocessing import StandardScaler
|
| 38 |
from sklearn.ensemble import HistGradientBoostingRegressor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
numeric_features = ['Model Year', 'Mileage', 'Engine Capacity']
|
| 42 |
-
categorical_features = ['Company Name', 'Model Name', 'Location', 'Engine Type', 'Color', 'Assembly', 'Body Type', 'Transmission Type', 'Registration Status']
|
| 43 |
-
transformer = ColumnTransformer(transformers=[('num',StandardScaler(),numeric_features),('cat',OneHotEncoder(drop='if_binary', dense=True),categorical_features)])
|
| 44 |
-
pipe = Pipeline(steps=[('preprocessor', transformer), ('regressor', hgbr)])
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
import streamlit as st
|
| 49 |
|
| 50 |
-
def price(companyName,modelName,modelYear,
|
| 51 |
input_data = pd.DataFrame({
|
| 52 |
'Company Name':[companyName],
|
| 53 |
'Model Name':[modelName],
|
| 54 |
'Model Year':[modelYear],
|
| 55 |
-
'Location':[
|
| 56 |
'Mileage':[mileage],
|
| 57 |
'Engine Type':[engineType],
|
| 58 |
'Engine Capacity':[engineCapacity],
|
|
@@ -60,27 +75,25 @@ def price(companyName,modelName,modelYear,location,mileage,engineType,engineCapa
|
|
| 60 |
'Assembly':[assembly],
|
| 61 |
'Body Type':[bodyType],
|
| 62 |
'Transmission Type':[transmissionType],
|
| 63 |
-
'Registration Status':[registrationStatus
|
| 64 |
})
|
| 65 |
-
|
| 66 |
-
prediction=pipe.predict(input_data)[0]
|
| 67 |
return prediction
|
| 68 |
-
|
| 69 |
st.title('Car Price Prediction:car @yusufenes')
|
| 70 |
st.write('Please Chose Car Specifications')
|
| 71 |
companyName = st.selectbox('Company Name',df['Company Name'].unique())
|
| 72 |
modelName = st.selectbox('Model Name',df[df['Company Name']==companyName]['Model Name'].unique())
|
| 73 |
modelYear = st.selectbox('Model Year',df[(df['Company Name']==companyName)&(df['Model Name'] == modelName)]['Model Year'].unique())
|
| 74 |
-
|
| 75 |
mileage = st.number_input('Mileage',df['Mileage'].min(),df['Mileage'].max())
|
| 76 |
engineType = st.selectbox('Engine Type',df['Engine Type'].unique())
|
| 77 |
engineCapacity = st.number_input('Engine Capacity',df['Engine Capacity'].min(),df['Engine Capacity'].max())
|
| 78 |
color = st.selectbox('Color',df['Color'].unique())
|
| 79 |
assembly = st.selectbox('Assembly',df['Assembly'].unique())
|
| 80 |
bodyType = st.selectbox('Body Type',df['Body Type'].unique())
|
| 81 |
-
transmissionType= st.selectbox('Transmission Type',df['Transmission Type'].unique())
|
| 82 |
registrationStatus = st.radio('Registration Status',['Yes','No'])
|
| 83 |
if st.button('Predict'):
|
| 84 |
-
pred=price(companyName,modelName,modelYear,
|
| 85 |
st.success(f'The predicted price is {pred} $')
|
| 86 |
-
st.balloons()
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""car_price.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1rtMdlilQhGBozNcdxDeSkuEthtwAz7-L
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
import pandas as pd
|
| 11 |
import numpy as np
|
| 12 |
import warnings
|
|
|
|
| 34 |
def train_test(df):
|
| 35 |
X=df.drop('Price',axis=1)
|
| 36 |
y=df['Price']
|
| 37 |
+
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=43)
|
| 38 |
return X_train,X_test,y_train,y_test
|
| 39 |
|
| 40 |
+
def dummie(X_train,X_test):
|
| 41 |
+
X_train = pd.get_dummies(X_train,drop_first=True)
|
| 42 |
+
X_test = pd.get_dummies(X_test,drop_first=True)
|
| 43 |
+
return X_train,X_test
|
| 44 |
+
|
| 45 |
+
def final_df(df):
|
| 46 |
+
df =datacleanning(df)
|
| 47 |
+
X_train,X_test,y_train,y_test = train_test(df)
|
| 48 |
+
X_train,X_test = dummie(X_train,X_test)
|
| 49 |
+
return df,X_train,X_test,y_train,y_test
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
from sklearn.ensemble import HistGradientBoostingRegressor
|
| 52 |
+
def model_fit(X_train,y_train):
|
| 53 |
+
hgb = HistGradientBoostingRegressor()
|
| 54 |
+
hgb.fit(X_train,y_train)
|
| 55 |
+
return hgb
|
| 56 |
+
|
| 57 |
+
model = model_fit(X_train,y_train)
|
| 58 |
|
| 59 |
+
!pip install streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
df = pd.get_dummies(df,drop_first=True)
|
| 62 |
|
| 63 |
import streamlit as st
|
| 64 |
|
| 65 |
+
def price(companyName,modelName,modelYear,locaiton,mileage,engineType,engineCapacity,color,assembly,bodyType,transmissionType,registrationStatus):
|
| 66 |
input_data = pd.DataFrame({
|
| 67 |
'Company Name':[companyName],
|
| 68 |
'Model Name':[modelName],
|
| 69 |
'Model Year':[modelYear],
|
| 70 |
+
'Location':[locaiton],
|
| 71 |
'Mileage':[mileage],
|
| 72 |
'Engine Type':[engineType],
|
| 73 |
'Engine Capacity':[engineCapacity],
|
|
|
|
| 75 |
'Assembly':[assembly],
|
| 76 |
'Body Type':[bodyType],
|
| 77 |
'Transmission Type':[transmissionType],
|
| 78 |
+
'Registration Status':[registrationStatus]
|
| 79 |
})
|
| 80 |
+
prediction=model.predict(input_data)[0]
|
|
|
|
| 81 |
return prediction
|
|
|
|
| 82 |
st.title('Car Price Prediction:car @yusufenes')
|
| 83 |
st.write('Please Chose Car Specifications')
|
| 84 |
companyName = st.selectbox('Company Name',df['Company Name'].unique())
|
| 85 |
modelName = st.selectbox('Model Name',df[df['Company Name']==companyName]['Model Name'].unique())
|
| 86 |
modelYear = st.selectbox('Model Year',df[(df['Company Name']==companyName)&(df['Model Name'] == modelName)]['Model Year'].unique())
|
| 87 |
+
locaiton = st.selectbox('Location',df['Location'].unique())
|
| 88 |
mileage = st.number_input('Mileage',df['Mileage'].min(),df['Mileage'].max())
|
| 89 |
engineType = st.selectbox('Engine Type',df['Engine Type'].unique())
|
| 90 |
engineCapacity = st.number_input('Engine Capacity',df['Engine Capacity'].min(),df['Engine Capacity'].max())
|
| 91 |
color = st.selectbox('Color',df['Color'].unique())
|
| 92 |
assembly = st.selectbox('Assembly',df['Assembly'].unique())
|
| 93 |
bodyType = st.selectbox('Body Type',df['Body Type'].unique())
|
| 94 |
+
transmissionType = st.selectbox('Transmission Type',df['Transmission Type'].unique())
|
| 95 |
registrationStatus = st.radio('Registration Status',['Yes','No'])
|
| 96 |
if st.button('Predict'):
|
| 97 |
+
pred=price(companyName,modelName,modelYear,locaiton,mileage,engineType,engineCapacity,color,assembly,bodyType,transmissionType,registrationStatus)
|
| 98 |
st.success(f'The predicted price is {pred} $')
|
| 99 |
+
st.balloons()
|