Used Car Price Prediction Web deployment and Key learnings
Building a Web App for Used Car Price Prediction Using Streamlit
In the previous blog, we built a machine learning model to predict used car prices based on various features such as company, car model, year, fuel type, and kilometers driven. In this post, we will take the next step and build an interactive web application using Streamlit that will allow users to input car details and get an estimated price prediction.
Streamlit Setup:
Streamlit is an open-source app framework in Python that enables you to create beautiful, interactive web applications with minimal effort. By using Streamlit, we can easily deploy our trained machine learning model and build a user-friendly interface for making predictions.
Let's walk through the process of creating the web application.
1. Importing Required Libraries
We start by importing the necessary libraries—Streamlit for the web app, Pandas for data manipulation, NumPy for numerical operations, and scikit-learn for machine learning functions.
2. Loading the Model
Next, we load the trained model that we saved earlier using the pickle module.
The model is stored in a file named Model.pkl.
3. Reading the Car Dataset
We read the cleaned car dataset, which contains information such as car companies,
models, year, fuel type, and the kilometers driven. This data will be used to
generate the select box options in the app.
4. Creating the Streamlit Interface
Now, we set up the user interface using Streamlit's widgets. The following steps
create the form where the user can input the car details for prediction:
- Select the car's company from a dropdown list.
- Select the car model based on the selected company.
- Select the year the car was bought.
- Choose the fuel type.
- Enter the kilometers driven by the car.
5. Making Predictions
Once the user inputs the car details, they can click the Predict button to
generate the car's estimated price. The inputs are passed to the trained model,
and the model predicts the price based on the features.
6. Running the App
With the model loaded, the user interface set up, and the prediction functionality
added, it's time to run the application. To start the Streamlit app, save the
script and run the following command in your terminal:
streamlit run Website.py
This will launch a local server, and you can interact with the web app through
your browser.
Example Output
Here’s how the app might look when deployed
1. User Input Section
Select the car's company, model, fuel type, and year of purchase, then enter details such as kilometers
driven and fuel type to predict the car's price.
2. Prediction Result
- On clicking "Predict," the app will display the estimated house price
Key Learnings
Data Cleaning and Preprocessing is Essential
Handling Missing Values: Ensuring that missing data is handledappropriately, such as filling in missing values for essential attributes,
Outlier Detection: Removing outliers in features like 'kms_driven' or 'year'
Feature Engineering: Creating new features or transforming existing ones,
Exploratory Data Analysis (EDA) Reveals Insights
Visualizations like box plots,Correlations and patterns identified during EDA, such as the relationship between
Choosing the Right Model is Key
Model Comparison: Testing multiple algorithms likeRandom Forest: Among the various models, Random Forest performed the best,
Model Deployment with Streamlit Simplifies User Interaction
Integration: The trainedUser-Friendly Interface: Streamlit’s interactive elements like dropdown menus,
Reproducibility Enhances Workflow:
By saving the model pipeline, preprocessing steps,Web Application Deployment Makes the Model Accessible:
Deploying the app onConclusion
This project helped to reinforce concepts in machine learning model development,
data preprocessing, and the practical application of AI techniques to real-world
problems. Additionally, it showcased how machine learning models can be integrated
into accessible web applications, making predictions available to users in an
interactive way.
Comments
Post a Comment