-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar_Price_Predictor_app.py
165 lines (123 loc) · 5.07 KB
/
Car_Price_Predictor_app.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import streamlit as st
import pickle
import numpy as np
import pandas as pd
import altair as alt
# Load the model
rf1 = pickle.load(open("Random_Forest_Regressor.pkl", 'rb'))
# Display an image
st.image(r"Audi Car.jpg")
st.title('Car Price Predictor App')
st.header('Fill the Details to Predict Car Price')
# User input
fuel = st.selectbox('Fuel Type', ['Diesel', 'Petrol', 'CNG', 'LPG', 'Electric'])
seller_type = st.selectbox('Seller Type', ['Individual', 'Dealer', 'Trustmark Dealer'])
year = st.slider('Year', 1992, 2020)
owner = st.selectbox('Owner Type', ['First Owner', 'Second Owner', 'Third Owner', 'Fourth & Above Owner', 'Test Drive Car'])
transmission = st.selectbox('Transmission Type', ['Manual', 'Automatic'])
km_driven = st.slider('Km Driven', 1, 223159)
brand = st.selectbox('Brand', ['Maruti', 'Hyundai', 'Mahindra', 'Tata', 'Ford', 'Honda', 'Toyota', 'Chevrolet', 'Renault', 'Volkswagen', 'Nissan', 'Skoda', 'Others', 'Fiat', 'Audi', 'Datsun', 'BMW', 'Mercedes'])
# Define a mapping for categorical values to numerical values
fuel_map = {'Diesel': 1, 'Petrol': 4, 'CNG': 0, 'LPG': 3, 'Electric': 2}
seller_type_map = {'Individual': 1, 'Dealer': 0, 'Trustmark Dealer': 2}
transmission_map = {'Manual': 1, 'Automatic': 0}
owner_map = {'First Owner': 0, 'Second Owner': 2, 'Third Owner': 4, 'Fourth & Above Owner': 1, 'Test Drive Car': 3}
brand_map = {'Maruti': 9, 'Hyundai': 7, 'Mahindra': 8, 'Tata': 15, 'Ford': 5, 'Honda': 6, 'Toyota': 16, 'Chevrolet': 2, 'Renault': 13, 'Volkswagen': 17, 'Nissan': 11, 'Skoda': 14, 'Others': 12, 'Fiat': 4, 'Audi': 0, 'Datsun': 3, 'BMW': 1, 'Mercedes': 10}
# Convert categorical inputs to numerical values
fuel = fuel_map[fuel]
seller_type = seller_type_map[seller_type]
transmission = transmission_map[transmission]
owner = owner_map[owner]
brand = brand_map[brand]
# Create an input array for the model
test = np.array([year, km_driven, fuel, seller_type, transmission, owner, brand]).reshape(1, -1)
# Predict the price
if st.button('Predict'):
prediction = rf1.predict(test)
st.success(f"Predicted Car Price: {prediction[0]:.2f}")
# Line Chart of km_driven and Selling Price
st.title("Line Chart of km_Driven and Selling Price")
data = pd.read_csv(r"Car Details 2.csv")
line_chart = alt.Chart(data).mark_line(point=True).encode(
x='km_driven',
y='selling_price',
tooltip=['km_driven', 'selling_price']
).properties(
title='Line Plot of km_driven vs Selling Price',
width=600,
height=400
)
st.altair_chart(line_chart, use_container_width=True)
# Line Chart of Year and Selling Price
st.title("Line Chart of Year and Selling Price")
line_chart = alt.Chart(data).mark_line(point=True).encode(
x='year',
y='selling_price',
tooltip=['year', 'selling_price']
).properties(
title='Line Plot of year vs Selling Price',
width=600,
height=400
)
st.altair_chart(line_chart, use_container_width=True)
# Bar Chart of Year and Selling Price
st.title("Bar Chart of Fuel and Selling Price")
bar_chart = alt.Chart(data).mark_bar(point=True).encode(
x='fuel',
y='selling_price',
tooltip=['fuel', 'selling_price']
).properties(
title='Bar Plot of Fuel vs Selling Price',
width=600,
height=400
)
st.altair_chart(bar_chart, use_container_width=True)
# Bar Chart of Brand and Selling Price
st.title("Bar Chart of Brand and Selling Price")
bar_chart = alt.Chart(data).mark_bar(point=True).encode(
x='brands',
y='selling_price',
tooltip=['brands', 'selling_price']
).properties(
title='Bar Plot of Brand vs Selling Price',
width=600,
height=400
)
st.altair_chart(bar_chart, use_container_width=True)
# pie Chart of Seller Type and Selling Price
st.title("Pie Chart of Seller Type and Selling Price")
data_aggregated = data.groupby('seller_type').sum().reset_index()
pie_chart = alt.Chart(data_aggregated).mark_arc().encode(
theta=alt.Theta(field='selling_price', type='quantitative'),
color=alt.Color(field='seller_type', type='nominal'),
tooltip=['seller_type', 'selling_price']
).properties(
title='Pie Chart of Seller Type vs Selling Price',
width=600,
height=400
)
st.altair_chart(pie_chart, use_container_width=True)
# Bar Chart of Transmission Type and Selling Price
st.title("Bar Chart of Transmission Type and Selling Price")
bar_chart = alt.Chart(data).mark_bar(point=True).encode(
x='selling_price',
y='transmission',
tooltip=['transmission', 'selling_price']
).properties(
title='Bar Plot of Transmission Type vs Selling Price',
width=600,
height=400
)
st.altair_chart(bar_chart, use_container_width=True)
# Bar Chart of Owner Type and Selling Price
st.title("Bar Chart of Owner Type and Selling Price")
bar_chart = alt.Chart(data).mark_bar(point=True).encode(
x='owner',
y='selling_price',
tooltip=['owner', 'selling_price']
).properties(
title='Bar Plot of Owner Type vs Selling Price',
width=600,
height=400
)
st.altair_chart(bar_chart, use_container_width=True)