Spaces:
Sleeping
Sleeping
import numpy as np | |
import pandas as pd | |
import streamlit as st | |
import pickle | |
import feature_engine | |
with open('RandomForest.pkl', 'rb') as file_1: | |
model_rfr = pickle.load(file_1) | |
with open('model_scaler.pkl', 'rb') as file_2: | |
model_scaler = pickle.load(file_2) | |
st.write('Price Prediction based on random forest regression') | |
location = st.selectbox(label='Location', | |
options=['Delhi', | |
'Coimbatore', | |
'Mumbai', | |
'Hyderabad', | |
'Pune', | |
'Jaipur', | |
'Chennai', | |
'Kochi', | |
'Bangalore', | |
'Kolkata', | |
'Ahmedabad']) | |
year = st.selectbox(label='Year', | |
options= | |
['2014', '2013', '2017', '2012', '2016', '2015', '2011', '2007', | |
'2008', '2009', '2019', '2010', '2005', '2006', '2018', '2003', | |
'2004', 'less than 2003']) | |
fuel_type = st.selectbox(label='Fuel_Type', options=['CNG', 'Petrol', 'Diesel', 'LPG']) | |
transmission = st.selectbox(label='Transmission', options=['Manual', 'Automatic']) | |
owner_type = st.selectbox(label='Owner_Type', options=['First', 'Second', 'Third']) | |
power = st.number_input(label='Power', min_value=34.20, max_value=616.00, value=420.69, step=0.01) | |
model = st.selectbox(label='Model', | |
options=['Alto', 'Innova', 'Etios', 'i20', 'XUV500', 'Fortuner', 'EON', | |
'City', 'Q5', 'Grand', 'Corolla', 'Swift', 'Terrano', 'X1', '3', | |
'Ikon', 'Ritz', 'Micra', 'Laura', 'Civic', 'Jazz', 'Rapid', 'Polo', | |
'i10', 'Pajero', 'Creta', '5', 'Baleno', 'A4', 'Ertiga', 'Ciaz', | |
'A', 'Ecosport', 'Endeavour', 'Verna', 'Vitara', 'Indigo', | |
'Celerio', 'Sail', 'Scorpio', 'Ameo', 'Wagon', 'Brio', 'Santro', | |
'Figo', 'Tiago', 'Beat', 'Xcent', 'Camry', 'Vento', 'Teana', | |
'Manza', 'Fiesta', 'B', 'Accord', 'Zen', 'Elantra', 'Indica', | |
'Nano', 'Amaze', 'Q3', 'New', 'BRV', 'X3', 'GL-Class', 'GO', | |
'Ignis', 'A-Star', 'XE', 'EcoSport', 'KUV', 'Avventura', 'CR-V', | |
'Accent', 'XF', 'E-Class', 'M-Class', 'Xylo', 'Mobilio', 'S', | |
'Passat', 'Sunny', 'A8', '7', 'Duster', 'Dzire', 'A6', 'Linea', | |
'Sumo', 'Grande', 'Cooper', 'Thar', 'Xenon', 'Aveo', 'Tavera', | |
'Superb', '800', 'BR-V', 'Verito', 'Q7', 'Eeco', 'Bolero', 'Jetta', | |
'Elite', 'Flying', 'Tigor', 'Rover', 'XC90', 'X6', 'Land', | |
'Tucson', 'Omni', 'Spark', 'Cruze', 'GLC', 'SX4', 'KWID', 'Getz', | |
'Optra', 'Enjoy', 'TUV', 'Compass', 'GLE', 'CLA', 'S60', 'Captur', | |
'A3', 'Pulse', 'Punto', 'XC60', 'WRV', 'CrossPolo', 'Cayenne', | |
'Octavia', 'Quanto', 'S80', '370Z', '6', 'Sonata', 'Classic', | |
'Koleos', 'V40', 'GLA', 'Qualis', 'Freestyle', 'Abarth', 'Versa', | |
'redi-GO', 'SLC', 'Lodgy', '1.4Gsi', 'Zest', 'Ssangyong', 'Esteem', | |
'Clubman', 'X5', 'Captiva', 'Renault'] | |
) | |
manufacturer = st.selectbox(label='Manufacturer', | |
options=['Maruti', 'Toyota', 'Hyundai', 'Mahindra', 'Honda', 'Audi', | |
'Nissan', 'BMW', 'Ford', 'Skoda', 'Volkswagen', 'Mitsubishi', | |
'Mercedes-Benz', 'Tata', 'Chevrolet', 'Datsun', 'Jaguar', 'Fiat', | |
'Renault', 'Mini', 'Bentley', 'Land', 'Volvo', 'Jeep', 'Porsche', | |
'OpelCorsa' | |
]) | |
df = pd.DataFrame({'Location': [location], | |
'Year': [year], | |
'Fuel_Type': [fuel_type], | |
'Transmission': [transmission], | |
'Owner_Type':[owner_type], | |
'Power': [power], | |
'Model': [model], | |
'Manufacturer': [manufacturer], | |
}) | |
from sklearn.preprocessing import LabelEncoder | |
label = LabelEncoder() | |
label_lst = ['Location', 'Fuel_Type','Transmission','Model','Manufacturer'] | |
for col in label_lst : | |
df[col] = label.fit_transform(df[col]) | |
dic = {'First':2,'Second':1,'Third':0} | |
df['Owner_Type']=df['Owner_Type'].map(dic) | |
dic1 = {'2019':17,"2018":16,"2017":15,"2016":14,"2015":13,"2014":12,"2013":11,"2012":10,"2011":9,"2010":8,"2009":7,"2008":6,"2007":5,"2006":4,"2005":3,"2004":2,"2003":1,"less than 2003":0 } | |
df['Year']=df['Year'].map(dic1) | |
# Predict using Random Forest Regression | |
data_inf_scaled = model_scaler.transform(df) | |
y_pred_inf = model_rfr.predict(data_inf_scaled) | |
y_pred_inf | |
st.write('Price Predicted: ') | |
st.text(y_pred_inf) | |