Encoding Seasonality to Improve Our Property Valuation Models
November 28, 2022
At Homebound, the Machine Learning & Pricing team is responsible for developing and maintaining an Automated Valuation Model (AVM) to accurately predict the value of a property. Dubbed here as the Homebound Valuation Model (HVM), characteristics such as the size of a home, property view, proximity to major roads, and much more are used to estimate the price of a property. This enables our underwriting team to quickly and accurately value properties for customers looking to sell their homes through the Homebound Property Purchase Portal.
Our team is continuously working on improving the HVM by engineering new features, modifying model architecture, and improving data quality. One feature we’ve recently incorporated in our models is seasonality. The time of year in which you decide to purchase or sell your house can have an impact on how much your property is worth. Depending on the location of a home, prices tend to be higher during the spring and summer months and lower during the winter time. While our initial models naively captured some aspects of seasonality through features such as the amount of time since a home was last sold, we wanted to explicitly encode aspects of seasonality into our models.
Traditionally, a home’s listing price is dependent on recently sold, comparable homes nearby, or comps. While a seller listing their home may not be planning for when they’re selling their home, an appraiser or real-estate agent factors the season into the listing price of their home. For machine learning models, this seasonality has to be explicitly included in the model, and can be done in numerous ways.
Encoding seasonality through the month in which an event occurred, ordinal or categorical, is probably the most common and simplest way to extract seasonal features. At Homebound, this is the month in which a property was listed for sale. Although this is easy to implement and interpret, this method often lacks what we want the model to understand about seasonality. For example, if this data is one-hot encoded, each month is considered independent, whereas in reality we know a relationship in time exists. If this data is ordinal, we account for the similarity between months such as January and February, while distancing dissimilar months such as January and June, but then run into the issue of January and December as being represented as the least similar months.
Another way to represent seasonality is by bucketing, or grouping time that may be relevant to the outcome being predicted. For example, we manually bucketed list dates into two potentially relevant ways, quarterly and seasonally. While this reduces dimensionality and manually encodes aspects of perceived seasonality, the same issues discussed above persists with both categorical and ordinal representations of these bucketed groups.
While both monthly and bucketed representations of time help in interpreting and representing seasonality as model features, they struggle with capturing the cyclic nature of time and seasons. An alternative way to capture this seasonal cycle is by transforming dates in a year into a two dimensional, sine and cosine, feature space. This is done by normalizing the numerical day of year to a value between 0 and 1, transforming those values between the 0 and 2π sine and cosine intervals, and then obtaining the sine and cosine of those values (think back to the unit circle from trigonometry). Each day in the year is then represented by a unique sine and cosine value pair that forms a circle, as seen in the figure below.
One downside to this methodology is a lack of interpretability. Having two features representing time makes it more difficult to decipher feature importance and its general effect on the outcome variable. Additionally, some models such as tree-based methods, may have trouble creating useful splits on two features representing one element, seasonality. One potential solution to this issue is creating a similar, one dimensional cyclic feature that is interpreted as N days from a specific, chosen point in time. This is the equivalent to representing time as just the normalized cosine representation of time from above, where each day is N days away from either January 1st until N converges in July. This does however, lead to two different times of the year being represented by the same value.
Ultimately, there is no “right” way to encode seasonality. Each of these methods have their pros and cons based on the problem at hand, business requirements, and the model chosen. Therefore, the only way we could fairly evaluate which method was the best for the HVM was through experimentation.
To determine how to best represent seasonality in the HVM, we ran experiments to determine the feature that minimized error, as defined by the Mean Average Precision Error (MAPE), and ultimately providing the greatest lift in model accuracy. At Homebound, we use mlflow to track experiments, store model details, and evaluate key metrics across different regions. The table below contains information on the seasonality experiments run.
Given cyclic feature encodings are generally used in non-tree based models, often in deep learning models, we were surprised to see it give us the greatest lift in model performance. The HVM is an ensemble of tree based methods, and therefore we were unsure about its ability to pick up on the seasonality of home prices from a two-dimensional feature space.
If you’re unsure about how to encode seasonality for your projects give these methods a try, you may be surprised with what works!
Next Steps & Future Work
As mentioned previously, one of our teams primary goals is to assist Homebound’s underwriting team in making quick, accurate, and fair offers to potential Homebound customers. Providing more explainability into HVM predictions is one way we can improve the partnership between our teams. While incorporating the two-dimensional cyclic features was great for boosting model performance, it somewhat decreased model interpretability.
One way the Machine Learning team has been gaining insight into individual predictions and the effects of seasonality on a prediction is through Shapley values. In the future, providing the same level of interpretability to HVM predictions for the underwriting team as well could help us iterate and improve our understanding of home price seasonality better in different regional markets and improve our models.
This section will focus primarily on implementing the different seasonality features discussed above, in Python.
We start by importing the packages needed to create a dummy Pandas DataFrame containing dates over the past three years (2019–2021) to extract seasonality features from.
For extracting months from dates, Pandas has convenient functionality that allows us to grab both month numbers and names from dates. Note it is not necessary to grab month names for the categorical representation of this feature as one-hot encoding month numbers will do, but is cleaner when done this way.
Fortunately, bucketing time into groups such as quarters is also relatively straight forward, and can be done in a similar manner as extracting month numbers and names.
Bucketing months into manually created groups, such as seasons, requires a little more work and is done by mapping months to its desired group.
Lastly, to create the cyclic features discussed above, the day of year from each date needs to be extracted. We can then create the sine and cosine time feature space by normalizing the day of year to a value between 0 and 1, transforming those values between the 0 and 2π sine and cosine intervals, and then obtaining the sine and cosine of those values.
Ultimately, the transformed seasonality features engineered should look something like the observations in the table below.
Homebound is hiring! Interested in working at Homebound? Check out our careers page!
 Araj, Victoria. “The Best Time of Year to Buy a House.” Rocket Mortgage, 1 Nov. 2022, https://www.rocketmortgage.com/learn/best-time-of-year-to-buy-a-house.
 Bescond, Pierre-Louis. “Cyclical Features Encoding, It’s about Time!”, Towards Data Science, 8 June 2020, https://towardsdatascience.com/cyclical-features-encoding-its-about-time-ce23581845ca.
 Hopper. “Ai in Travel, Part 2: Representing Cyclic and Geographic Features.” Medium — Life at Hopper, 27 Apr. 2018, https://medium.com/life-at-hopper/ai-in-travel-part-2-representing-cyclic-and-geographic-features-4ada33dd0b22.