What it shows
People who buy a second-hand vehicle want a fair price. A regression model learns from listed prices, age and kilometres how much a scooter is worth. A student can build it from an open data set or from 100 prices noted from classified advertisements, and check how accurate it is.
The science
Linear regression finds weights w so that price ≈ w0 + w1 age + w2 kilometres that minimise the squared error on training data. The data are split into training and test sets so that accuracy is measured on unseen cases. R squared measures the fraction of variance explained, and mean absolute error gives the typical error in rupees. A model that fits training data but fails on test data is overfitting.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A laptop with Python 3, pandas, numpy, matplotlib and scikit-learn
- A CSV of used vehicle prices from an open data portal, or one that you collect (age, kilometres, company, price)
- Jupyter or Thonny
- A notebook for the report
Safety
For this project: Use only public data and do not include phone numbers or names of sellers in your file.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
11 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Collect or download at least 100 rows with age in years, kilometres driven and price in rupees, and check for obvious errors.
Load the data with pandas and describe it: count, mean, minimum and maximum of each column.
Plot price against age and price against kilometres to see how the points are spread.
Split the rows 80 to 20 into training and test sets with a fixed random seed.
Fit a LinearRegression model on the training set and print the coefficients with their meaning.
Predict the test set prices and compute mean absolute error and R squared.
Plot predicted against actual price with the 45 degree line and describe where errors are largest.
Try adding the company as a one-hot encoded column and see whether the error falls.
Try a polynomial feature for age and check for overfitting by comparing training and test scores.
Write a function that takes age and kilometres and returns an estimated price, and test it with your own examples.
Write the report with the data source, method, plots, errors and the limits of the model.
What you should see
The model predicts test prices within about 10 to 20 percent for typical vehicles, with R squared of about 0.6 to 0.85 depending on the data. The scatter of predicted against actual price shows where the model is weak.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1Why split data into train and test sets?
To measure accuracy on cases the model has not seen, and so detect overfitting.
2What does R squared mean?
The fraction of the variation in price that the model explains.
3What are the limits of this model?
It uses only a few features and a straight-line relation, but real prices also depend on condition, city and model.
4What is one-hot encoding?
Turning a category such as company into separate yes or no columns that the model can use.
Take it further
Try a decision tree regressor and a random forest and compare their errors with the linear model.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Computer & office
Excel Formulas Workbook
Sixty formulas and functions, each with a worked example from school, shop or office
