Feature Engineering is a critical part of any machine learning project. It is the step of the project where subject matter expertise and statistical knowledge play an integral role in helping the engineer choose the most relevant features for testing and building their models. This tutorial will take you through three feature engineering tips I often utilize when working through a machine learning project.

Assume you are working with a large restaurant chain with a business objective to optimize their staffing at all their locations. They want to ensure they are maximizing revenue by having enough staff to accommodate a busy day while also reducing costs by not overstaffing on slower days. Your goal is to build a machine learning model that predicts the number of customers walking through the door on any day for a specific shift, at a specific restaurant location.
Don’t overlook EDA

The first step in any data project, before you begin feature engineering, should be exploratory data analysis, or EDA. This step is critical for all data-related projects, not only machine learning. At this point, you probably already know what problem you are trying to solve with machine learning and how the stakeholder defines success. Business analysts or SMEs may have already directed you on what data is relevant for the project, which makes it tempting to save time and skip EDA, but that would be a mistake for a multitude of reasons. Most obviously, EDA is important for the data cleaning process and can also aid in decision-making for feature engineering.
One primary benefit of EDA is understanding the shape of the data. In the EDA portion of the machine learning process, we can understand the scales and formats of all the different variables. This can be achieved by simply looking at the summary statistics and visualizing the distributions. First, I like to isolate the target variable distribution by creating a histogram for numerical variables, or a basic bar chart for categorical variables. This helps you identify if you have an uneven target variable that skews in one direction, and if a transformation or normalization is necessary for a numerical variable. Also, visualizing the possible predictor variables can help you quickly identify which ones may need to go through data cleansing or if there are variables you can exclude altogether, like variables that are all null or only have one value.
The Benefits of Data Visualization for Data Scientists
In this project example, assume you are primarily using point of sale, or POS, data. Through the EDA process, you may be able to see that a majority of the data are ID fields or other irrelevant data fields that can be removed early prior to the feature engineering step.
Using visuals, such as a correlation matrix, can help reveal relationships among the variables in the data. Sometimes this can simply help you identify when two variables are providing the same information to the model. Other times, it helps identify more complex relationships. While there are models that capture predictor interactions automatically, others require the developer to set the interactions, whether they are straight multiplications (Variable A * Variable B), polynomials (Variable A ^2), or others.
An example of correlation in regards to predicting the number of customers for a restaurant is that as temperature increases to a certain degree, the number of customers could accelerate initially, but as it gets too hot, that rate of acceleration could begin to decrease, especially if that location has an outdoor patio.
Depending on the structure of your data, there are many different tests and statistical measures you can utilize to highlight which predictor variables will be the most informative. The chi-square test of independence and Cramer’s V are great for measuring association between categorical variables, while Spearman’s rank correlation is preferable for numerical or ordinal variables. You can also experiment with regularization, a common machine learning method, which can be used to remove redundant variables if two variables have a high correlation (multicollinearity).
Ultimately, EDA is all about getting more familiar with the data. You may need to continue partnering with the subject matter expert who is closest to the data to fully understand the interactions between variables. This strategic step is one of the most important, but it can take time. Don’t be tempted to take shortcuts on EDA to deliver the product faster. Doing so could prolong the process inadvertently.
Advanced Analytics in Tableau Series: One-Way ANOVA Tests
Think outside the table

Thinking outside the table means looking beyond the base dataset to elevate model performance. This allows you to remove the limits of what features can be incorporated into your models.
Continue reading with a free account, or login.
Unlock this tutorial and hundreds of other free visual analytics resources from our expert team.
Already have an account? Sign in
By continuing, you agree to our Terms & Conditions and Privacy Policy.

