How to Apply Feature Selection in Your Data Science Project
Python Data Science

How to Apply Feature Selection in Your Data Science Project

Darío Abadie
Darío Abadie | | 2 min read

Feature selection is a feature engineering technique used to select the most relevant characteristics for a machine learning model.

Before getting into the details, it’s important to clarify that feature engineering is the process of preparing data for modeling. This includes selecting, creating, and transforming the features we’ll use in our model. Feature selection, specifically, refers to the selection of those features.

Why Is Feature Selection Important?

Well, sometimes we have many features available for a given problem, but not all of them are necessary or relevant for the model.

Using all available features can make the model less accurate or even slower to run.

Additionally, using irrelevant or redundant features can negatively affect model performance.

How Do We Select the Most Relevant Features for Our Model?

There are several techniques we can use, and the choice of technique depends on the dataset and the type of model we’re building.

Some common techniques include:

Filtering

This technique relies on statistical measures to select the most relevant features. For example, we could use Pearson correlation to select the features most correlated with the target variable.

Here’s an example of how we could use Pearson correlation in Python:

Pearson correlation example in Python

Wrapper

This technique uses the machine learning model as a “wrapper” to select features. For example, we could use a linear regression model and progressively eliminate features one by one.

Here’s an example of how we could use the wrapper technique in Python:

Wrapper technique example in Python

Embedded

This technique includes feature selection as part of the model training process. For example, some decision tree algorithms include automatic feature selection built in.

Here’s an example of how we could use the embedded technique in Python:

Embedded technique example in Python

Remember that feature selection is a key task in the machine learning modeling process, as it helps improve the accuracy and performance of our models by eliminating irrelevant or redundant features.

To close: sometimes we’re tempted to use all available features, thinking more is better. But as we’ve seen, irrelevant or redundant features can hurt model performance.

That’s why feature selection is key to building more accurate and robust models. Dedicate time and effort to this task during the modeling process.

Darío Abadie

Darío Abadie

Data Architect @ deployr

Share

Got a real technical problem?

We don't sell generic solutions. Let's talk about what you need to solve.

Let's talk