Feature Engineering: The key to machine learning (a housing price case-study)
“Feature engineering is the process of transforming raw data into features that better represent the underlying problem to the predictive models, resulting in improved model accuracy on unseen data.” -Dr. Jason Brownlee
Poorly performing model? Now what?
A classic data science problem occurs when a model performs well on test data but falters when confronted with unseen data. The data scientist is forced to brainstorm possible remedies: Train the model on a larger dataset? Tune the hyper-parameters? Ensemble or stack the weak model with another model? All of these are viable options, but before we choose one we should consider this quote:
“At the end of the day, some machine learning projects succeed and some fail. What makes the difference? Easily the most important factor is the features used. — Prof. Pedro Domingos
Feature engineering will almost always give you the biggest "bang for your buck" when it comes to model improvement. Remember the old saying "garbage in, garbage out"? Well, when you train your model on features that are weak in their predictive power, too numerous, or too few, you can expect a poor performing model as a result. Let's take a look at how we can use feature extraction to improve our datasets.
Feature engineering in action: Housing price prediction
This housing dataset looks at the attributes of different properties in Ames, Iowa. One of the attributes is the neighborhood the property is found.
This feature is made up of over 20 unique neighborhoods. If we were to encode these categorical variables into numeric variables we would only increase the dimensionality of our dataset. This puts unnecessary computational strain on our model. How can we use feature engineering to reduce the strain of having so many categories for one feature?
Consider this bit of advice:
“Coming up with features is difficult, time-consuming, requires expert knowledge. ‘Applied machine learning’ is basically feature engineering.” — Prof. Andrew Ng
It is important to note that "expert knowledge" is required to make the most of our features. Since we are dealing with real estate data we have to think like real estate experts. How can we simplify these 20+ neighborhoods, what factors do they have in common?
Why not break Ames, Iowa into larger districts that these neighborhoods can fall into. For example, North Ames vs. Central Ames vs. East Ames etc. We can reduce the neighborhood feature from 25 variables to 5 of 6. Better yet, we can group the neighborhoods by tax bracket or median income of the residents. The key is to get creative and think like a real estate expert!
Looking at the square footage features, you may be surprised that there are columns for basement square footage, first floor square footage, etc. but no column for total square footage. An easy example of feature extraction can be applied here: Creating a new column of the summed values of all square footage features associated with available living space. Who knows, maybe this new feature will be a powerful predictor in your final model.
In summary, when you find yourself trying to improve your model(s), look back to the features you are using. Is there any more information you can extract from them? Can you simplify them? Finally, think like an expert. Gain a little domain knowledge or reach out to someone who is an expert. If you are mystified by the data, that is usually a sign that you need a little more time researching!