Coursework

House price regression

Predicting house prices from their size with linear regression and a decision tree.

A notebook that loads 47 homes, each with a size in square feet and a sale price, and splits them 80/20: 37 to train on, 10 to test.

It fits a linear regression and a decision tree with scikit-learn, then checks each with 5-fold cross-validation, which trains on four fifths of the training data and scores on the last fifth, five times over.

With this little data the straight line generalizes far better than the tree, which memorizes the training houses and scores worse than guessing the average on unseen folds.

Housing data

47 homes, 37 train and 10 test

Linear regression

Decision tree

Evaluation

5-fold cross-validation

  • Housing data to Linear regression
  • Housing data to Decision tree
  • Linear regression to Evaluation
  • Decision tree to Evaluation
Simplified to the main pieces and how they talk to each other.

See it work

What the notebook found

ModelResult
Linear regressionPrice ≈ $125.10 per square foot + $86,935
Linear regression, cross-validationAverage R² of 0.52 across the five folds
Decision tree, cross-validationAverage R² of −0.23: it overfits the 37 houses

From the notebook's saved output. The scores are R²: 1 is a perfect fit, 0 is no better than the average price, and below 0 is worse.