Feature Engineering: The key to machine learning (a housing price case-study)

Avatar
Posted on Oct 2, 2018

“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?

Ames, Iowa by neighborhood

 

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!

About Author

Avatar

Taino Pacheco

Taino Pacheco holds a master's degree in Biomolecular Science from Central Connecticut State University and is an alumni of the NYC Data Science Academy.
View all posts by Taino Pacheco >

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

2019 airbnb alumni Alumni Interview Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Big Data Book Launch Book-Signing bootcamp Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Industry Experts Job Jon Krohn JP Morgan Chase Kaggle lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest recommendation recommendation system regression Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Tableau TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp