House pricing in Toronto— Exploratory Data Analysis and Correlations
By: Laurent Risser
Tags: Seaborn, Craigslist, Real Estate, Python, Data Science

Toronto by night taken by Alexandre Risser https://www.alexandrerisser.com

Searching for “How to find an apartment in Toronto” on Google leads to dozens of pages of advice, which is a pretty good indicator that apartment hunting is a painful process.

As a Data Scientist trainee, I was sure that I could alleviate this pain a bit and simplify the way people search for a place to live in. The project I came up with aims to find out the relationships between the price of an apartment in the Greater Toronto Area (GTA), its location, surface, and the number of bedrooms. The business idea of this project is to help apartment seekers to find the best deal across different neighborhoods in the GTA.

Before I started analyzing the data, I needed to import all the packages required. For this project, I imported the following Python packages Seaborn and Matlpot to visualize the data.

Now let’s look at the data!

But some notes before. For some reason that I do not understand, I was only able to extract around 50–60 records per query, so, to increase my sample size, I ran my script for a few days until I reached 400 entries.

While looking at the data, I noticed another issue: the ‘neighbourhood’ column is a free text field, so few apartments within the same area can have very different neighbourhood names. In addition, sometimes the description is feeble; I have a few records with only ‘Toronto’, ‘North York,’ ‘Markham’. These names are not neighbourhoods, they are cities. This column is vague because of these two issues. Therefore, I was not able to use this column in my analysis, so I pushed forward with the three remaining variables: price, number of bedrooms and the surface.

Exploratory Analysis

The classic first step is to look at the distribution of the variables. Based on the table below, I noticed that I have 447 records:

218 records for a one-bedroom apartment

169 records for a two-bedroom apartment

45 records for a three-bedroom apartment

15 records for a four or five-bedroom apartment

I observed that the majority of the apartments in Toronto fall into the one or two-bedroom apartment categories; this is not a surprise. I decided that, due to the low amount of records for four and five-bedroom apartments, I wouldn’t discuss them much and instead I focused the following analyses toward the one, two and three-bedroom categories.

Summary table of all bedroom categories, source: Author

Based on my data, if you are looking for a one-bedroom apartment, the average price in February 2020 is $2360, and for a two-bedroom apartment it is $3237, so the difference is $877. The median price for a one-bedroom apartment is $2250, and for a two-bedroom apartment it is $2900, the difference is $650. In contrast, the difference in the median between two-bedroom and three-bedroom apartments is less than $100, and the average difference is $417, which might give us a hint about the prices not increasing linearly with the increasing number of bedrooms.

The cheapest apartment at the time I extracted the data from Craiglist was at $730. Here is the link to this apartment in case you are curious: link. It is not rare to find fake listings on this type of website, so below is a capture of this apartment, which seems legit (in case you were doubtful). However, I remain unsure if it is indeed a one-bedroom apartment. It seems like a bedroom in a shared apartment.

Craiglist, source:Author

The most expensive apartment in my data set is at $9,000, and the surprise is that it is a two-bedroom apartment near the famous CN Tower. Here is a link (in case you can afford it).

Most expensive appartment, source:Author

Next, I plotted a boxplot of the price by the number of bedrooms. Each boxplot is a graphic representation of the different quantiles, and the horizontal lines inside the boxes represent the median of the price.

I noticed here that the boxplots of the two and three-bedroom apartments overlap. So, according to my data, with the budget of a two-bedroom apartment, a potential renter could get a three-bedroom apartment in Toronto.

Regarding the dispersion of the data, the two-bedroom apartment category has a higher variance than the one-bedroom, with many outliers with prices ranging between $ 6,000 and $9,000.

Price per number of bedrooms, source: Author

Then I checked the distribution of the two variables for all the bedroom categories: the price and the surface.

Price Distribution, source: Author

I started with the price distribution. I noticed a high number of apartments at around $2,100, with a long tail up until the value of $9,000. The distribution seems right-skewed.

Surface distribution, source: Author

Regarding the surface distribution, a high number of apartments have a surface between 900 and 1,000 square feet (which is 92 square meters, for the non-imperial readers). It also has a right-skewed long tail up until 5,000 square feet (ca. 465 m²).

Moving on, below there is a scatter plot, where the number of bedrooms colours the points. This shows a clear, understandable and expected stratification: the layers of points clustered around particular prices and square footage, and as price and square footage increase, so do the number of bedrooms.

Price vs Square Footage Colored by Number of Bedrooms, source: Author

Correlation test

Next, I wanted to test the correlation between the price and the surface. To do that, I needed to investigate which test I could use. The two histograms above can already give us insight about the data not following a normal distribution. I further checked that below by doing Q-Q plots.

QQ plot — Surface, source: Author

QQ plot — Price, source: Author

If the data were following roughly the red line, the data would have been normally distributed. Also, I showed previously that the distribution of the data is right-skewed. This is due to a large number of apartments within the same price range, between $2,000 and $3,000 per month. Therefore, I was not able to run a parametric test on it. Instead, to show the correlation between my three variables, I did a correlation test using the method “Kendall.” This method is an entirely nonparametric approach to linear regression, where there is one independent and one dependent variable. It is robust to outliers in the dependent variable. The results are shown in the table below, from which I drew a few conclusions.

Correlation score, source: Author

As expected, the correlation is relatively robust at 0.63 between the number of bedrooms and the surface of the apartment. This is logically anticipated, given that the more bedrooms an apartment has, the more surface they will occupy.

Also, it is not surprising to see that the correlation between the price and the number of bedrooms is low (0.38). Similarly, the correlation between the price and the surface is 0.39. In my opinion, the cost of an apartment will be first influenced by the location in the city, then it will maybe increase by its surface and/or the number of bedrooms. For instance, an apartment located near the city center will likely be more expensive than an apartment far from the city center if both had the same surface.

I would like to dig more into housing data from Toronto, to be able to include the location (neighbourhood, for example) as another variable. But, in order to do so, I would need to change the source of the data. Therefore, my suggestion to improve the results and obtain a reasonable conclusion is that next time, I will choose a more valuable website to scrape in order to get more worthy data.

Anyway, I hope you appreciate the insights and feel free to give me some feedback =).

My repo on Github.