Second-Hand Car Prices Prediction using Machine Learning Algorithms in Python (Bachelor's Thesis)
This repository has been archived on 2026-10-18. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • Jupyter Notebook 95.3%
  • Python 4.5%
  • Makefile 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-11-07 20:10:15 +01:00
config Mostly refactoring coupled with tuning hyperparameters 2024-05-15 14:35:36 +02:00
docs Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
models Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
notebooks Mostly refactoring coupled with tuning hyperparameters 2024-05-15 14:35:36 +02:00
references Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
reports Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
src Mostly refactoring coupled with tuning hyperparameters 2024-05-15 14:35:36 +02:00
.gitignore Mostly refactoring coupled with tuning hyperparameters 2024-05-15 14:35:36 +02:00
Aleksa_Radojičić_20240165_Presentation.pdf docs: rename thesis and presentation to latin; provide links in readme 2025-11-07 20:10:15 +01:00
Aleksa_Radojičić_20240165_Thesis.pdf docs: rename thesis and presentation to latin; provide links in readme 2025-11-07 20:10:15 +01:00
LICENSE Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
Makefile refactor: Make python scripts more readable and organized 2024-03-24 17:08:20 +01:00
README.md docs: rename thesis and presentation to latin; provide links in readme 2025-11-07 20:10:15 +01:00
requirements.txt Mostly refactoring coupled with tuning hyperparameters 2024-05-15 14:35:36 +02:00
setup.py Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
test_environment.py Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00
tox.ini Initialized empty data science project using cookiecutter 2024-01-28 14:30:41 +01:00

Second-Hand Car Prices Prediction using Machine Learning Algorithms

This project was developed for my Bachelor's thesis at the Faculty of Organizational Sciences, Information Systems and Technologies. The goal was to predict prices of second-hand cars listed on the Serbian platform PolovniAutomobili using machine learning algorithms in Python.

Project Overview

The objective of this project is to accurately predict prices of second-hand cars in euros using various ML models. The dataset consisted of 23,759 cars for training and 5,940 vehicles for testing. Coefficient of determination [R2] was the main metric used for models evaluation. Hyperparameters for Random Forest and Gradient Boosting Model were optimized using cross-validation. Furthermore, optimized GBMs were used to predict 90% prediction intervals.

GBM model performed best, achieving R2 of 0.94027 and MAE (mean absolute error) of 1230.770€ on test data. The prediction intervals contained the true values only 43.38% of the time. The 0.50 quantile GBM model identified the production year as the most important attribute, followed by engine power, kilometerage, model name and others.

Data Acquisition

Vehicles were scraped from the website PolovniAutomobili using BeautifulSoup and Tor. SQLAlchemy and MySQL were used to store the data, resulting in a total of 30,788 rows and 50 columns.

Technologies Used

  • Programming Language: Python 3.11.8;
  • Database: MySQL, SQLAlchemy;
  • Web Scraping: BeautifulSoup, Tor, Stem, Selenium, tbselenium;
  • Data Analysis: Pandas, NumPy;
  • Visualization: Matplotlib, Seaborn;
  • Machine Learning: scikit-learn;
  • Configuration: PyYAML, Hydra.

Data Preprocessing

The Initial Cleaner component processed each column and removed outliers. The resulting data was passed then into a Preprocessor Pipeline, which prepared train and test set separately for modelling. Price (output column) was log-transformed to further improve model performance.

Results

Below are the tables of performance metrics for the optimized models on both the training and test sets.

Train Set Metrics

Model RMSE MAE R2
RF 1191.538 499.685 0.98717
GBM 0.50 1579.571 547.138 0.97746
GBM 0.05 2470.072 974.428 0.94488
GBM 0.95 1435.852 818.770 0.98137

Test Set Metrics

Model RMSE MAE R2
RF 2726.884 1311.138 0.93259
GBM 0.50 2566.822 1230.770 0.94027
GBM 0.05 3449.857 1715.0888 0.89211
GBM 0.95 2879.736 1624.346 0.92482

Additionaly, there is a comparison of R2 between the default and optimized ML models, along with a plot depicting true versus predicted values on the test set (GBM), including prediction intervals.

Comparing Default and Optimized Models on Test Set using R2 Metric (GBM)


Bachelor’s Thesis and Presentation

Both the thesis and presentation are available as PDFs in this repository. Files:

Acknowledgements

I really want to thank my mentors Sandro Radovanović and Andrija Petrović for their guidance and support throughout this project.