Optimizing Real Estate Price Prediction with Clustering for Haystacks.AI with Alternative Data
Project was in collaboration with Trevor Mattos
TLDR:
Partnered with PropTech company Haystacks.AI, we used real-life property data in Georgia to optimize property valuation using machine learning. We scraped additional features and alternative data (walk scores, grocery stores, schools). We implemented the haversine distance equation to get the distance to each amenity to add as a feature. We then ran PCA to get 3 principal components, then used k-means clustering to identify which cluster each property belonged to based on these principal components. We then added โclusterโ as a new feature in a linear regression model to see if it would perform better than the control (model with no clustering information) to see if it improved model performance- to which it did. We then subset the data to a smaller scale (Only Atlanta vs looking at the entire state) to find that this improved the model performance even further.
Figure 0: ( Top Left) Clear emergence of clusters in data, graphed by component 1 (C1), component 2 (C2), and component 3 (C3). ( Top Right) Pearson correlation heat map showing which factors are most strongly prevalent in each component: C1: crime; C2: General property info; C3: Distance to amenity. (Bottom) Clusters after k-means on the Atlanta subset.
Overview
The real estate market is uncertain and can be difficult to navigate, often riddled with issues like property valuation and the occurrence of market patterns/trends that are difficult to uncover. Machine learning can alleviate such issues, with algorithms like clustering that can help us identify trends and group properties based on similarities that may affect property value- like walk scores or distance to certain amenities. Supervised models can then use the information gained from clustering to aid in property valuation as well. Here weโll work together with Property Technology company, Haystacks.ai, to see how clustering algorithms can uncover natural groupings in real-estate data, then use the groupings to optimize property price prediction.
Data Cleaning and Feature Engineering
Haystacks.ai assists Single-family rental (SFR) investors with identifying properties to invest in to maintain a competitive and optimized real estate portfolio. The company provided us with scraped data from the entire state of Georgia, with some basic features on single-family rental properties:
Figure 1: Original dataset provided by Haystacks.ai with basic information about properties in Georgia.
After some basic data cleaning (imputing missing values, removing outliers) weโre left with around 11,500 properties to analyze.Now that we have a cleaned data set that is ready for analysis, we can do a quick 3D plot to see if thereโs any intuitive looking clusters:
Figure 2: Graph of properties in Georgia based on 3 numeric features
As is evident, no intuitive clusters appear in the given data. Luckily, we have a few tactics that may aid in the formation of clusters. We used both Google API and beautiful soup to scrape additional features such as walk score, schools, location of banks, location of schools, and some features that are indicative of gentrification- like the occurrence of grocers such as Trader Joes and Whole Foods. We were also able to find some Georgia crime rate data at the zipcode level.
Once the data is merged, we can pretty easily implement the haversine formula to calculate the distance from each property to the nearest amenities, then add the results as features as well.
Figure 3: Haversine formula. We can find the distance between any two points on a sphere, converting points to lat long and the radius of earth can give us the distance of any two points on the globe.
Clustering Algorithms Into Supervised Methods
Now that we have a heftier set of features, we might begin to see some clusters. To account for the curse of dimensionality, we can run Principal component analysis (PCA) to reduce our features to something easy to visualize- 3 principal components.
Figure 4: Clear formation of clusters. The correlation plot on the right can give us information about how to interpret the axis: C1 shows information on crime rates, C2 on general property features, and C3 shows distance to desirable amenities.
Since we have some nice looking data, we can use a clustering algorithm like K-means to group similar properties together. We use a quick for-loop to estimate what amount of clusters will give us the highest silhouette score, in our case n=3. Once we have our beautiful clusters, we can use this information to subset into 3 separate models to run supervised methods on:
Figure 5: Data with color = Cluster. Data is then subset by cluster labels, resulting in 3 models ready for linear regression.
We can compare these models to a control group to test if giving supervised machine learning models information about clustering improves price prediction. The control group consisted of the following features: beds, baths, square footage, year built, distance to school, distance to quality grocer (Whole Foods, Trader Joes, etc), distance to bank, and violent crime rate, with the target variable set as price. Weโll be looking at R^2 to score each model out of the box (without hyperparameter tuning) to test performance. The control group scored about R^2 = .48, model 1 scored R^2 =.45, model 2 scored R^2 = .65, and model 3 scored R^2 = .45, with an average of the 3 modelโs performance standing at R^2 = .52. While the models with information about clustering did average a slightly higher score than the model that did not have the clustering information, Itโs clear and intuitive that the models with greater data separation lead to better price prediction. Since we have access to latitude and longitude, what would happen if we plotted the experimental models on a map of Georgia?
Figure 6: Geographical distribution of 3 clusters: Model 1 =โOuter ring clusterโ, Model 2 = โDowntown clusterโ, Model 3 = โInner ring clusterโ
Our clustering algorithms were able to correctly identify and cluster which properties geospatially belonged together, without being given any information on latitude or longitude. The best performing cluster correlates to the downtown cluster, which makes sense as it would have different property valuations compared to the more suburban areas surrounding it.
Similarly, when looking at property data across a whole state the density can be difficult to parse through correctly since each local niche market values different things. What would happen if we subset the data to only look at Atlanta, Georgia?
Looking at just properties in Atlanta, Georgia, we follow the same algorithm: we take the Atlanta subset, run PCA, feed the 3 principal components to k-means, get the labels for the clusters, subset on the clusters, then run simple linear regression on the experimental models and control groups and compare out of the box R^2 scores to see if the clustering information helped supervised model performance.
Figure 7: Clusters of properties in Atlanta, Georgia with color = Cluster. The data is then subset into models based on cluster labels.
We again score each model by looking at R^2, with the target variable being price. The control group scored around .70, model 1 scored around .65, model 2 scored around .80, and model 3 scored around .72 (average of the 3 experimental models: .72). Itโs clear that crime rate seems to have a huge impact on price, and identifying areas of extreme (very high crime, very low crime) can help us to better predict property price.
Conclusions
As we have seen, clustering information can in fact increase a supervised modelโs price prediction ability. Clustering proves a promising method in the field of real estate, with the ability to provide investors a competitive edge in their real estate portfolios by gaining pricing power and to obtain desirable properties (i.e. minimized distance to amenities). Clustering can also have implications in property valuation by helping to understand niche local markets, and by feeding clustering labels to supervised models to enhance price prediction performance. The supervised methods can then aid in property valuation, and help investors decide to invest in a property and how to offer it at an optimized price.
Github: https://github.com/trevaveras/Unsupervised-Learning-RealEstate
Resources
https://www.xenonstack.com/blog/real-estate-investment
https://towardsdatascience.com/principal-component-analysis-algorithm-in-real-life-discovering-patterns-in-a-real-estate-dataset-18134c57ffe7
https://towardsdatascience.com/dbscan-clustering-algorithm-how-to-build-powerful-density-based-models-21d9961c4cec
https://gisdata.fultoncountyga.gov/datasets/adef0a906333496c931c56c3875c7af6_316/about