Machine learning / Regression

ML Used Vehicle Regression Project

Role
Machine Learning Analyst
Status
Complete
Skills used
  • Python
  • pandas
  • NumPy
  • scikit-learn
  • Matplotlib
  • Seaborn

Research question

What factors were most important for influencing asking price for used vehicles on Craigslist in Spring 2021?

The source

The dataset

Source: Craigslist Cars and Trucks dataset by Austin Reese

I used Craigslist vehicle listings to see how asking price relates to seven details about each vehicle and listing. These are the prices sellers posted, which may differ from what the vehicles actually sold for.

Fields I used

  • Vehicle year
  • Odometer
  • Manufacturer
  • Condition
  • Title status
  • Vehicle type
  • State
source listings
426,880
prepared rows
259,125
predictor groups
7
Before modeling

Preparing the data

  1. Choose the columns

    I used asking price as the value to predict and kept seven vehicle and listing fields as inputs. I left the other source columns out of this first model.

  2. Remove extreme prices and mileage

    I kept prices above $1,000 and no higher than the 99th percentile. I also kept odometer readings from zero through their 99th percentile. I left unusual vehicle years in place because some could be classic cars.

  3. Fill gaps and remove duplicates

    I labeled missing category values as “unknown” and removed rows that were duplicates across the columns I selected. I did not separately fill in missing vehicle years.

  4. Prepare the categories

    I one-hot encoded manufacturer, condition, title status, vehicle type, and state so the model could use them. That left 259,125 rows and 124 predictor columns.

Model and evaluation

Testing the model

I trained a 100-tree random forest using a random 80/20 train/test split. To give the error some context, I compared it with a simple baseline: predict the training set’s median asking price for every test listing. The plot shows 5,000 test predictions. Points on the red diagonal would be perfect predictions.

Method Random forest regression

Swipe or scroll to see the full chart →
Scatterplot of 5,000 test listings with actual asking price on the horizontal axis and predicted price on the vertical axis. Points generally follow the perfect-prediction diagonal but spread more at higher prices.
Predicted versus actual asking prices for 5,000 test listings. The red line marks a perfect prediction; the notebook labels it “Regression Line.”
Model MAE
$3,657

On the held-out test set, predictions were off by this much on average, rounded to the nearest dollar.

Test R²
0.783

The model explained about 78% of the asking-price variation in the test set.

Baseline MAE
$10,146

Average error from predicting the training set’s median price for every test listing.

The result

Feature importance

Vehicle year stood out most in the model, with odometer next. Vehicle type and manufacturer followed. State, condition, and title status had smaller importance scores.

Swipe or scroll to see the full chart →
Horizontal bar chart of grouped random forest feature importance. Vehicle year is largest, then odometer, vehicle type, manufacturer, state, condition, and title status.
Feature importance from the notebook, grouped by original field. Longer bars mean a larger share of split-based importance. These scores describe prediction, not causation.
The full analysis

Project notebook

Scroll inside the notebook to read the original code and saved results.

Next projectSQL Portfolio ProjectBack to work