yusufenes commited on
Commit
5725247
·
verified ·
1 Parent(s): 0767a00

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +100 -0
  2. car.csv +0 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
13
+ warnings.filterwarnings('ignore')
14
+
15
+ dataset = pd.read_csv('car.csv')
16
+ df = dataset.copy()
17
+
18
+ def other_values(df,col,n):
19
+ tc = df[col].value_counts()
20
+ ov = tc[tc<=n].index
21
+ df[col] = df[col].apply(lambda x: 'Other' if x in ov else x)
22
+
23
+ def datacleanning(X):
24
+ X = X.drop_duplicates()
25
+ X.dropna(axis=0, inplace=True)
26
+ if 'Unnamed: 0' in X.columns:
27
+ X.drop('Unnamed: 0', axis=1, inplace=True)
28
+ other_values(X, 'Company Name', 100)
29
+ other_values(X, 'Model Name', 100)
30
+ other_values(X, 'Color', 170)
31
+ return X
32
+
33
+ from sklearn.model_selection import train_test_split
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],
74
+ 'Color':[color],
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()
100
+
car.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit==1.31.1
2
+ scikit-learn==1.4.1.post1
3
+ pandas==2.1.0