Objective
A DVD rental company wanted to improve inventory planning by predicting how many days a customer would keep a rental before returning it. The brief was straightforward: build a regression model that achieves a mean squared error of 3 or less on a held-out test set.
The dataset contained 15,861 rental records with features covering transaction details (amount paid, rental rate), movie attributes (release year, length, replacement cost, rating), and a special_features column listing extras like deleted scenes or behind-the-scenes footage.
Approach
Before touching any models, the data needed some work. The special_features column was a free-text field, so I extracted two binary flags from it: deleted_scenes and behind_the_scenes. The target variable, rental_length_days, was computed directly from the difference between return and rental timestamps.
With the features prepared, the next question was which ones actually mattered. I used Lasso regression with cross-validated alpha tuning to perform automatic feature selection. Lasso shrinks less useful coefficients toward zero, which makes it a clean way to cut noise before committing to a model. After fitting, only three features had non-zero coefficients: amount, rental_rate, and rental_rate_2.
From there I trained and tuned five models on the selected features, evaluating each on a 20% held-out test set:
- Linear Regression (baseline)
- Decision Tree (with GridSearchCV tuning)
- Bagging Regressor (with GridSearchCV tuning)
- Random Forest (with GridSearchCV tuning)
- Gradient Boosting
Findings
The baseline linear model fell just short of the target at MSE 3.02. Every tuned tree-based model cleared it comfortably:
| Model | Test MSE |
|---|---|
| Linear Regression | 3.02 |
| Decision Tree (tuned) | 2.50 |
| Bagging Regressor (tuned) | 2.50 |
| Random Forest (tuned) | 2.50 |
| Gradient Boosting | 2.78 |
The tuned Decision Tree, Bagging Regressor, and Random Forest all tied at the top with MSE 2.50 -- a 17% improvement over the linear baseline. Gradient Boosting also beat the target but sat slightly behind the others, likely because the shallow trees used to control overfitting limited its expressiveness on this dataset.
One result that stood out: Lasso selected only three features from a much wider set, yet those three were enough for tree-based models to outperform the linear baseline by a meaningful margin. The price of the rental, not the movie metadata, turned out to be the most predictive signal.
Takeaway
A few things I will carry forward from this project:
- Feature selection before modelling pays off. Starting with Lasso reduced dimensionality without losing the signal that mattered, and kept subsequent training fast and interpretable.
- Hyperparameter tuning has real impact. The untuned Decision Tree would have missed the target. The tuned version hit the best score in the comparison. GridSearchCV is not just housekeeping.
- Simpler models can match complex ones on the right data. A single Decision Tree, properly tuned, matched the Bagging Regressor and Random Forest. That is a useful reminder that more complexity is not always better.
The full notebook and dataset are on GitHub.