Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DriveThePrice: What Drives the Price of a Car?

Practical Application Assignment 11.1 for the Professional Certificate in Machine Learning and Artificial Intelligence at UC Berkeley.

This project analyzes 426,880 used-vehicle listings to identify the factors that drive used-car prices and turns those findings into inventory and pricing recommendations for a used-car dealership. The full analysis, following the CRISP-DM process, is in what_drives_the_price.ipynb.

Data

The dataset is the course-provided sample of the Kaggle used-vehicles dataset (426,880 Craigslist listings, a subset of the original scrape of roughly three million). It is not committed to this repo. To run the notebook, place the CSV at data/vehicles.csv.

After cleaning (dropping identifier columns and the mostly-empty size column, removing listings missing essential fields, and filtering placeholder prices below 500 dollars, prices above 100,000 dollars, and odometer readings above 300,000 miles), 351,240 listings remain. Missing categorical values are kept as an explicit missing category rather than imputed, because listings that omit attributes turn out to price differently from those that state them.

Method

  • The target is log price, which removes the heavy right skew of raw prices.
  • The data is split 70/30 into train and test before any target-dependent fitting; the test set plays no role in training or model selection and is reserved for the final section, which reports test metrics for the selected model and the baseline and computes permutation importance.
  • All preprocessing lives inside a scikit-learn Pipeline: a cross-fitted TargetEncoder for categorical columns, PolynomialFeatures (degree chosen by cross validation), StandardScaler, then the regressor. This keeps the encoding and hyperparameter search free of test-set leakage.
  • Candidates: a median-predicting baseline, linear regression at degrees 1 and 2, and Ridge and Lasso at degree 2 with alpha chosen by GridSearchCV on the training set.

Results

Cross-validated RMSE on the training set, in log-price units:

Model CV RMSE (log price)
Baseline (always predict median) 0.894
Linear regression, degree 1 0.508
Linear regression, degree 2 0.464
Lasso, degree 2, alpha 0.0001 0.487
Ridge, degree 2, alpha 0.01 0.464 (selected)

At its winning alpha the Lasso fit stops at the iteration cap with a convergence warning, so its RMSE is approximate; it was not tuned further because it is not the selected model.

Final model performance on the held-out test set:

  • R2 of 0.727 on log price (the baseline scores below zero)
  • RMSE of 0.461 log units (test MSE 0.213)
  • Median absolute error of $2,535, versus $9,190 for the baseline
  • Mean absolute error of $4,289

Key findings

Each finding maps to a chart or metric in the notebook.

  • What the vehicle is matters most. Permutation importance on held-out data ranks model first (shuffling it costs about 0.25 of R2), ahead of year (about 0.19) and odometer (about 0.12). The model column effectively bundles brand, segment, and trim.
  • Age: prices climb steeply for vehicles newer than about 2010. Median listing price stays in a low band of roughly $4,000 to $7,000 for model years 1990 through 2005, then rises sharply to about $38,500 for 2021 models.
  • Mileage: median price falls with odometer reading, fastest over the first 100,000 miles before flattening near $5,000 at the highest mileages, and the linear model gives odometer the strongest negative coefficient.
  • Segment: full-size pickups command roughly three times sedan prices. Among the 15 most-listed models, the 2500, 1500, Silverado 1500, and F-150 have median prices of roughly $23,000 to $33,000, while the Corolla, Altima, Civic, Camry, and Accord sit near $7,000 to $8,300.
  • Condition labels are noisy in the middle and reliable at the bottom. Listings marked good or with no stated condition carry higher median prices than excellent, because those labels skew toward newer, lower-mileage dealer listings. The unambiguous signal: fair and salvage vehicles trade near $2,000 to $3,000, a fraction of everything else.

Recommendations for the dealership

  • Weight acquisition toward newer (roughly post-2015) and lower-mileage (under 100,000 miles) vehicles; the market pays a steep, quantifiable premium for both.
  • Stock trucks and SUVs for revenue per unit; stock high-volume sedans (Civic, Corolla, Camry, Altima) for turnover. Their lower price level reflects the segment, not weak demand, since they are among the most-listed vehicles in the market.
  • Use the model as a pricing sanity check: a listing priced far above its prediction will sit on the lot, and one priced far below leaves margin on the table. The test-set error above is the honest uncertainty band.
  • Do not price off condition labels alone; anchor on year, odometer, and model first, and use condition mainly to screen out or steeply discount fair and salvage stock.

Limitations and next steps

  • Listing price is not transaction price; the data cannot show what buyers actually paid.
  • The data is a snapshot and does not capture seasonality or macro shifts in the used-car market.
  • Next steps: gradient-boosted trees for richer nonlinearity, calibrated prediction intervals for pricing bands, and days-on-lot data to model turnover as well as price.

Running the notebook

pip install -r requirements.txt
jupyter notebook what_drives_the_price.ipynb

Python 3.10 or newer with scikit-learn 1.4 or newer, as pinned in requirements.txt; TargetEncoder requires at least scikit-learn 1.3. The full run takes several minutes on the 351,240-row dataset.

About

The primary objective of this project is to identify the determinants that influence the pricing of used cars through the training of Linear, Ridge, and Lasso Regression models of assorted polynomial degrees.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages