This research paper uses XG Boost regression to estimate
automobile prices, and it uses the Flask application code that you
have provided. It is customized to the needs of the user.
By-
Adarsh Pandey (07811503122) Kartik Saraf (08011503122)
Abhishek (03611503122) Aagam Jain (02411503122)
Third year students of Department of Information Technology, Bharati
Vidyapeeth’s College of Engineering A-4 Paschim Vihar New Delhi-110063
Abstract
This research article explains the deployment of the predictive model in a Flask web
application and investigates the usage of XG Boost regression for automobile price
prediction. The work employs feature engineering approaches, preprocesses the data,
and uses a dataset of automobile features. The effectiveness of the model is assessed
using common measures. With the Flask application, users can input automobile
attributes and get pricing forecasts through an easy-to-use interface. The correctness of
the model, deployment difficulties, and room for development are all covered in this
study.
1. Introduction
1.1 Background
In the automobile sector, predicting car prices accurately is essential for the benefit of all
parties involved, including dealers, finance institutions, and consumers. Knowing an
automobile's fair market value helps buyers and sellers make educated decisions and
guarantees they get or offer a fair price. Dealerships utilize price projections to improve
customer happiness, manage inventory more efficiently, and optimize pricing tactics.
Accurate car values are essential to financial organizations' ability to manage risks,
determine the collateral value of cars for loans, and determine the right interest rates.
Car pricing are heavily influenced by a number of things. Among them are:
Age:A car's value typically declines with age because of wear and tear, technological
obsolescence, and shifting market preferences.
- Diameter: Because it denotes more extensive use and the possibility of future repair
needs, higher mileage frequently translates into poorer value.
- Type of Fuel:A car's worth is affected by its fuel type—petrol, diesel, electric, or hybrid
—depending on factors like cost, market trends, fuel efficiency, and environmental
impact.
- Model and Brand:A car's resale value can be influenced by model popularity and brand
reputation; certain brands and models hold their worth better over time.
- Condition and extras: The price is also influenced by the overall state, which includes
the mechanical and aesthetic components, as well as optional extras like infotainment
systems, luxury add-ons, and sophisticated safety systems.
The intricate, non-linear correlations and interactions between these aspects are
frequently difficult for traditional approaches, such linear regression or basic heuristics,
to account for. Usually, these techniques depend on the assumptions of linearity and
independence between variables, which might not apply to real-world data and result in
less-than-ideal predictions.
Machine learning (ML) has become a potent substitute for auto price prediction,
especially when used to ensemble approaches such as XG Boost (Extreme Gradient
Boosting). XG Boost is a fast and efficient implementation of gradient-boosted decision
trees. Iteratively, it creates a sequence of decision trees, with each new tree fixing the
flaws in the preceding ones. Through the use of regularization techniques, this strategy
gives the model robustness against overfitting and enables it to capture complicated
relationships between features.
The benefits of XG Boost in this situation include:
- Managing Intricate Connections: Complex, non-linear interactions between features
that conventional models would overlook can be modeled using it.
- Feature Importance: By revealing which features are most important, the algorithm
aids in determining which elements have the biggest effects on car prices.
- Speed and Scalability: Because of its high efficiency and ability to manage big datasets,
XG Boost is a good fit for real-world applications where scalability and speed are crucial.
Adaptability: It can be customized to meet individual demands because it offers a variety
of loss functions and evaluation measures and can handle both numerical and
categorical input.
These features allow XG Boost to forecast car prices more precisely and nuancedly,
which is important for a number of applications in the automotive industry. In this study,
the use of XG Boost for automobile price prediction is investigated. Its effectiveness is
assessed, and its incorporation into a web-based tool for real-time price estimation is
covered.
1.2 Objective
The main goal of this research is to use XG Boost regression to create a car price
prediction model and use Flask to implement it as an online application. The training,
assessment, and data preparation procedures are described in depth in the study. The
incorporation of the model into an intuitive web interface that enables real-time price
forecasts depending on user inputs is also covered.
1.3 Motivation
This study was motivated by the need for easily available, precise tools for automotive
pricing. This project seeks to close the gap between sophisticated prediction models and
end-user applications by utilizing web technologies and machine learning, offering a
workable solution to automotive market participants.
2. Literature Review
2.1 Conventional Techniques for Predicting Car Prices
Early auto price prediction techniques mostly relied on statistical models such as linear
regression. Predictions made by these models were frequently less accurate because
they frequently overlooked non-linear correlations and interactions between variables.
2.2 Machine Learning Advances for Predictive Pricing
More advanced methods like gradient boosting, random forests, and decision trees were
introduced with the emergence of machine learning. These models are less susceptible
to the presumptions made by conventional statistical techniques and are capable of
capturing intricate patterns in data. The gradient boosting implementation known as XG
Boost has become well-known for its effectiveness and precision in a range of predictive
tasks, including price prediction.
2.3 Integration of Web Applications
A common strategy for opening up predictive analytics to a wider audience is to
incorporate machine learning models into web apps. Because of its ease of use and
versatility, Flask is a lightweight Python web framework that is frequently employed for
this kind of work. Through a web interface, this integration offers a smooth way for users
to engage with predictive models.
3. Approach
3.1 Gathering and Preparing Data
3.1.1 Sources of Data
The study's information was assembled from Kaggle dataset. It contains a number of
features, like the seller type, mileage, company name, year, and transmission, among
others. The price of the car is the target variable.
Fig: Data frame of the data source
3.1.2 Data Purification
Handling missing numbers, adjusting data types, and getting rid of duplicates were all
part of data cleaning. Using one-hot encoding, categorical variables like transmission
and fuel type were encoded. To improve the model's learning process, numerical
features such as year and mileage were standardized to bring them to a common scale.
3.1.3 The Process of Feature Engineering
To improve the predictive ability of the model, feature engineering entailed generating
new features from preexisting ones. For example, the car's age was determined by using
the year of manufacture, and the depreciation rate was determined by calculating a
feature based on age and mileage.
3.2 Model Creation
3.2.1 Model Selection
XG Boost was chosen due to its outstanding performance in a range of prediction tasks,
robustness against overfitting, and ability to handle both numerical and categorical data
effectively. Grid search and cross-validation were used to adjust the model's
hyperparameters, including learning rate, maximum depth, and number of estimators.
The well-liked, open-source supervised learning technique XG Boost (Extreme Gradient
Boosting) maximizes decision tree performance by gradient boosting. The way it
operates is by repeatedly adding decision trees to an ensemble, each one trying to
improve upon the mistakes made by the one before it. In addition to introducing other
enhancements over conventional gradient boosting, XG Boost uses a gradient descent
approach to minimize the loss function. These improvements include:
L1 and L2 regularization are used in regularization to avoid overfitting.
Sparsity awareness: managing sparse data and missing values
Effective parallelization of huge datasets with parallelization
XGBoost (Extreme Gradient Boosting) is a popular machine learning algorithm used for
both regression and classification tasks. The main formula used in XGBoost for
regression is:
y_pred = ∑(f_t(x)) + constant
where:
y_pred is the predicted value
f_t is the function of the t-th tree
x is the input feature vector
constant is a constant value added to the prediction to improve model performance
3.2.2 Instruction and Assessment
A 70:15:15 ratio was used to divide the dataset into training, validation, and test sets.
Hyperparameters were adjusted for the model using the validation set after it was
trained on the training set. Metrics like R-squared (R²), Mean Absolute Error (MAE), and
Root Mean Squared Error (RMSE) were used to assess the final model on the test set.
3.2.3 Measures of Performance
MAE : calculates the average magnitude of prediction errors without taking direction
into account.
MAE = (1/n) * ∑|y_true - y_pred|
where:
MAE is the Mean Absolute Error
n is the number of samples
y_true is the true target value
y_pred is the predicted value
∑ denotes the sum of the absolute differences
RMSE : offers a measurement of the discrepancies between observed values and values
predicted by a model.
RMSE = √(1/n) * ∑(y_true - y_pred)^2
where:
RMSE is the Root Mean Square Error
n is the number of observations
y_true is the true target value
y_pred is the predicted value
∑ denotes the sum of the squared differences
√ denotes the square root
R² score : represents the model's ability to explain variance in the dependent variable.
R² = 1 - (SSE / SST)
where:
R² is the R-Squared value
SSE is the Sum of Squared Errors (residuals)
SST is the Total Sum of Squares
3.3 Development of Flask Applications
3.3.1 Architecture of the Application
The predictive model's front-end interface is provided by the Flask application. The HTML
templates, `[Link]`, and static files for styling are the key parts. The application's
purpose is to accept user inputs obtained through a form, display the estimated car
price, and process the inputs.
# [Link]
from flask import Flask, request, jsonify, render_template
import numpy as np
import pickle
app = Flask(__name__)
# Load the trained model
model = [Link](open('model_car.pkl', 'rb'))
# Define a function to process the input data
def process_input(data):
features = [
'year', 'km_driven', 'fuel', 'seller_type', 'transmission',
'owner', 'seats', 'max_power', 'mileage', 'engine_cc'
# Create a list of values in the correct order
processed_data = [float(data[feature]) for feature in features]
# Convert the list to a numpy array and reshape it
processed_data = [Link](processed_data).reshape(1, -1)
return processed_data
@[Link]('/')
def home():
return render_template('[Link]')
@[Link]('/predict', methods=['POST'])
def predict():
# Get the form data
data = [Link].to_dict()
# Process the input data
processed_data = process_input(data)
# Make a prediction
prediction = [Link](processed_data)
# Convert the prediction to a standard Python float
prediction = float(prediction[0])
return jsonify({'prediction your car will cost you in : Rs': prediction})
if __name__ == "__main__":
[Link](debug=True)
3.3.2 Design of User Interface
Users can add facts about the car, like its year, mileage, fuel type, and other details,
using the HTML and CSS-styled user interface. The data entered into the form is
transmitted to the Flask back-end for processing before being incorporated into the
machine-learning model.
Fig : UI of web-page made by HTML and CSS
3.3.3 Consolidation and Examination
Ensuring proper input from the web form and precise rendering of predictions to the user
were key components of integration. Testing was done to make sure the program
handled a range of input scenarios—including data that was missing or incorrect—with
grace.
4. Outcomes
fig : price vs year plotting
fig : avg price of car with respect to their odometer
4.1 Performance of the Model
Ridge, Lasso, and Linear Regression were surpassed by the XG Boost model on the test
set, with an accuracy of 88.43% as opposed to their accuracy of roughly 79%. This
implies that XG Boost is having better performance was caused by its capacity to
manage intricate interactions and non-linear correlations in the data.
4.2 The Value of the Feature
The year of manufacture, mileage, and engine capacity were shown to be among the
most significant predictors of automobile pricing, according to an analysis of feature
importance. This is consistent with market trends, which show that larger engines and
newer, less-mileage cars typically fetch higher prices.
4.3 Usability of the Application
The application's usability and the precision of the projected pricing output were praised
by users. The responsiveness and simplicity of the interface's design won recognition for
allowing users with different degrees of technical proficiency to use it.
5. Talk
5.1 Results Interpretation
Given its high R2 value, the model is able to account for a sizable amount of the
variation in car costs. The correctness of the model is further supported by the
comparatively low MAE and RMSE values. These results imply that XG Boost is an
appropriate algorithm for this kind of prediction work.
5.2 Restrictions
The study has shortcomings in spite of its advantages. The model's predictions could be
skewed since the dataset might not accurately reflect the diversity of the auto industry.
Furthermore, the model does not consider extraneous variables like regional price
variations or economic situations.
5.3 Real-World Consequences
A wide range of stakeholders in the automobile industry can benefit from the developed
application, each in their own way.
Regarding Customers
1. Informed Purchasing Decisions : The app gives users clear, data-driven insights into
the market worth of automobiles, empowering them to make informed decisions. By
assisting sellers in establishing competitive prices and helping purchasers avoid
overpaying for cars, this transparency ensures that all parties participate in fair
transactions.
2. Comparison Shopping : By providing consumers with simple access to precise
automobile valuations, they may evaluate the costs of various vehicles according to their
characteristics, including make, model, age, and condition. Customers who are unsure
about their selections or want to be sure they are getting the best deal possible will find
this feature to be especially helpful.
3. Negotiation Leverage : Consumers are better able to bargain with sellers or
dealerships when they have a solid assessment of the car's value. This knowledge base
provides customers with confidence in their negotiating position and helps them avoid
accepting less-than-ideal bargains.
Regarding Dealerships
1. Inventory Management : Dealerships may accurately determine the market value of
their inventory by using this program. This skill is essential for determining the best
pricing tactics, avoiding overstocking specific models, and guaranteeing a balanced
inventory that fits consumer demand.
2. Dynamic Pricing : Dealerships can use dynamic pricing techniques because they can
regularly update car appraisals based on real-time data. By using this strategy, they are
able to maximize revenue by responding to changes in consumer demand, rival pricing,
and market trends by adjusting prices accordingly.
3. Enhanced Customer Service : Dealerships can establish confidence and trust by
offering customers transparent pricing that is based on data-driven models. Customers
who value fair and accurate pricing may be more satisfied and loyal because of this
transparency.
Regarding Financial Establishments
1. Loan Risk Assessment : To determine the risk involved with vehicle loans, financial
organizations like banks and credit unions rely on precise car appraisals. The loan-to-
value ratio, which is a crucial aspect in determining loan terms, interest rates, and
approval status, is determined in part by an accurate appraisal of a vehicle's worth.
2. Collateral Valuation : To reduce the risk of loss in the event of default, precise pricing
is crucial in secured loan scenarios where the car is used as collateral. Financial
institutions can protect their interests by using the application to make sure the value of
the collateral justifies the loan amount.
3. Portfolio Management : Knowing the current market value of the cars linked to these
loans is essential for organizations that oversee a portfolio of auto loans. This
information is useful for determining any problems, evaluating the overall risk profile of
the portfolio, and making well-informed decisions on loan sales or restructuring.
Extra Advantages
1. Market Analysis : Research and market analysis might benefit from the application's
collected data. Analysts are able to recognize patterns in automobile prices, comprehend
customer inclinations, and predict changes in demand for particular car models or
attributes.
2. Insurance Industry Applications : Accurate automotive assessments are useful to
insurance businesses for policy underwriting, premium calculation, and claim
management. Accurately evaluating damage claims and determining suitable coverage
levels are made easier with knowledge of a car's genuine market worth.
3. Integration with Other Services : To give customers a seamless experience, the
application can be integrated with other services including loan platforms, online
automobile marketplaces, and auto repair businesses. A banking platform might, for
instance, pre-qualify loan applicants depending on the car they want to buy using the
model's valuations.
The program adds substantial value to the automotive ecosystem by providing a
dependable, data-driven method of predicting automobile prices. This enhances
decision-making, increases transparency, and eventually benefits all market participants.
5.4 Upcoming Projects
Prospective enhancements may encompass broadening the dataset to encompass a
more diverse range of automobile models and attributes, merging real-time market data,
and investigating the application of sophisticated algorithms such as neural networks.
More interactive elements and visualizations, including 3D automobile models, virtual
test drives, and tailored recommendations based on user preferences, could also
improve the user experience. Moreover, the integration of natural language processing
may facilitate voice commands or text-based inquiries for car searches by users. The
system might give users a more thorough and interesting experience by taking care of
these issues.
6. Concluding remarks
This study offers a thorough illustration of how to use XG Boost regression for predicting automobile
prices and how to successfully integrate it into a Flask web application. The powerful gradient
boosting framework XG Boost was selected due to its exceptional ability to handle intricate datasets
and produce precise forecasts. The XG Boost model was trained on a dataset of vehicle pricing as
part of the study, and it successfully identified the underlying patterns and trends. The model can
handle real-world data with precision, as demonstrated by its remarkable accuracy in predicting
automobile values.
The web application Flask functions as a useful interface that facilitates smooth interaction between
users and the prediction model. By utilizing this online application to deploy the XG Boost model,
customers may quickly enter vehicle-related data and obtain precise real-time price predictions.
This integration gives people and companies in the automobile sector a useful tool in addition to
improving the prediction model's usefulness.
Positive outcomes for model accuracy and application usability suggest that this approach has a
great deal of real-world application. In addition to possibly helping a number of stakeholders by
delivering fast and precise information—which can be essential for making well-informed decisions in
the automobile market—it provides a dependable option for estimating car prices.
7. References :
Dataset from kaggle (car price prediction):
[Link]
XGBoost algorithm explanation : [Link]
Scikit learn : [Link]
Flask documentation : [Link]
Bootstrap : [Link]
Pandas documentation : [Link] — pandas 2.2.2 documentation -
PyData |pandas - Python[Link] › docs › reference › api › pand...