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

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

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

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI