Can we use XGBoost to predict public housing price in Singapore? (Part 1)
By: Cheong Wei Si
Tags: Extreme Gradient Boosting, Machine Learning, R, Feature Importance, Xgboost

Can we use XGBoost to predict public housing price in Singapore? (Part 1)

An eXtreme Gradient Boosting analysis in R

Image Credits: Koon Boon Goh from Pixabay

Recently, a relative of mine decided to go house-hunting in the HDB resale market and would like to know the “fair value” of a modest 3-room flat. Intrigued, I wanted to see if I could answer her question, and study if it is possible to predict housing price in the HDB resale market.

Research Questions

(1) What is the median price of a 3-room HDB resale flat?

(2) What are the important variables in explaining HDB resale price?

(3) How accurately can we predict the price of HDB resale flats given a set of characteristics about the property?

Data

Using web-scraping techniques, I managed to obtain a cross-sectional dataset of 7,620 HDB listings from the property website 99.co 3 weeks ago. The dataset contained property-level variables such as sqft and the no. of bedrooms, as well as amenity-level variables such as distance to the nearest school and the no. of schools in the 1km radius.

Web-scraping Ethics

It is prudent to use the robotstxt package first to check if we are allowed to scrape data off a webpage. If the output from “paths_allowed( )” is TRUE, it means we are good to go! Do visit Part 2 of this post if you’re into the technicalities of web-scraping, where I will illustrate how the data can be obtained from 99.co.

Web-scraping data from sites that contain personal data such as Facebook or Instagram are clearly not allowed.

Variables Definition

Here is a brief overview on what the variables mean in the dataset. I will skip the explanations for those standard variables like “bedrm” which refers to the number of bedrooms in the property.

“lease_left” refers to the number of years to the expiry of the 99-year lease; after which, ownership of the HDB will return to the government. (Yep, you read that right. Our HDBs are leased from the government for 99 years only).

“dist_CBD” refers to the distance from the property to the Central Business District, or the city centre.

“dist_orchard” refers to the distance to Singapore’s prime shopping belt.

“dist_mrt”, “dist_park”, “dist_sch” refers to the distance from the property to the nearest train station, park and school respectively.

“no_of_mrts”, “no_of_parks”, “no_of_schs” refers to the number of train stations, parks and schools situated within a 1km radius of the property.

“price_psf_1yr” refers to the average transaction price per square foot of properties within the block for the past year.

“txn_count_1yr” refers to the number of transactions for properties within the block for the past year.

If we look at HDB’s website, HDB flats are generally classified as “2 rooms”, “3 rooms”, “4 rooms”, “5 rooms” and “Executive”. “new_housetype” reflects this classification.

Summary Statistics

We could group the data by “new_housetype” to obtain some general insights of the mean and median housing prices.

At a glance, I would suspect that the data contains some outliers. Resale prices for HDB flats rarely reach, let alone cross the $1M mark. Furthermore, it seems unlikely that a 5-room flat would cost an eye-popping $45M!

Since these are listings data put up by property agents and not official transaction data, there might be some nonsensical entries. Thus, it will be prudent to remove the outliers before carrying on with further analysis.