Property Price Prediction ML-model

Link to Jupyter Notebook

This project is adapted from Aurelien Geron’s Hands-on Machine Learning Book (github link).

I build a regression model to predict median house values in Californian districts, given a number of features from these districts. More importantly, this project go through the basic building blocks when setting up any ML projects.

Following are main steps to consider:

  • Formulating the problem, defining the boundary conditions
  • Data acquisition
  • Discover and visualize data / Data exploration to gain insight
  • Prepare data for ML algorithm training and testing
  • Explore various model architectures to use
  • Select model and train it
  • Fine-tuning the model

Problem statement:

Prediction of district’s median housing price given all other metrics.

A supervised learning task is where we are given ‘labelled’ data for training purpose. Regression model to predict a continuous variable i.e. district median housing price. Given multiple features, this is a multi-class regression type problem. Univariate regression since a single output is estimated.



Looking at quick statistics for the data at hand:


Describe is powerful subroutine since that allows us to check the stat summary of numerical attributes. The 25%-50%-75% entries for each column show corresponding percentiles. It indicates the value below which a given percentage of observations in a group of observations fall. For example, 25% of observation have median income below 2.56, 50% observations have median income below 3.53, and 75% observations have median income below 4.74. 25% –> 1st Quartile, 50% –> Median, 75% –> 3rd Quartile

Plot dataset

housing.plot(kind="scatter", x="longitude", y="latitude", alpha=0.4,
    s=housing["population"]/100, label="population", figsize=(15,10),
    c="median_house_value", cmap=plt.get_cmap("jet"), colorbar=True,


This is more interesting! We have now plotted the data with more information. Each data-point has two additional set of info apart of frequency of occurence. First being the color of the point is the median_house_value entry (option c). The radius of the data-point is the population of that district (option s). It can be seen that the housing prices are very much related to the location. The ones closer to the bay area are more expensive but need not be densely populated.

Looking for simple correlations

In addition to looking at the plot of housing price, we can check for simpler corealtions. Pearson’s correlation matrix is something which is in-built in pandas and can be directly used. It checks for linear correlation between every pair of feature provided in the data-set. It estimates the covariance of the two features and estimates whether the correlation is inverse, direct, or none.



The correlation matrix suggests the amount of correlation between a pair of variables. When close to 1 it means a strong +ve correlation whereas, -1 means an inverse correlation. Looking at the correlation between median_house_values and other variables, we can see that there’s some correlation with median_income (0.68 – so +ve), and with the latitude (-0.14 – so an inverse relation).

Nifty tech tag lists fromĀ Wouter Beeftink