MACHINE LEARNING • LESSON 5

Feature Selection

Feature selection means choosing the features that are useful for solving a machine learning problem and leaving out features that are unnecessary, irrelevant, or potentially harmful.

THE SIMPLEST DEFINITION

Keep useful information. Remove unnecessary information.

A dataset can contain many pieces of information, but not every piece of information helps the model make a better prediction.

01

Why Do We Need Feature Selection?

Imagine we want to predict the price of a house.

We might have the following information:

USEFUL House Size

May have a strong relationship with house price.

USEFUL Number of Bedrooms

Can provide useful information about the house.

USEFUL Location

Can strongly affect house prices.

POSSIBLY UNNECESSARY Record ID

Identifies the row but usually does not describe the value of the house.

The goal of feature selection is to focus the model on information that actually helps solve the problem.

02

A Simple Example

Suppose we want to predict a student's exam score.

FEATURE Study Hours

6 hours

FEATURE Practice Tests

8 tests

POSSIBLY IRRELEVANT Student ID

58291

Study hours and practice tests could provide useful information for predicting an exam score.

Student ID identifies the student, but the number itself does not normally tell us how well the student will perform.

03

More Features Does Not Always Mean a Better Model

A common beginner mistake is to think:

"If more information is available, we should give all of it to the model."

That's not necessarily true.

Some features may contain irrelevant information. Adding unnecessary features can make the dataset more complicated without giving the model useful information.

TOO MUCH INFORMATION 20 Features

Some may be useful, while others may be irrelevant or redundant.

SELECTED FEATURES 5 Useful Features

The model focuses on information that is more relevant to the problem.

04

Feature Selection Is Based on the Problem

A feature is not automatically useful or useless. Its usefulness depends on what we are trying to predict.

For example, consider house location.

PROBLEM Predict House Price

Location can be very useful.

DIFFERENT PROBLEM Predict House Age

Location may be less directly useful than other information.

So you should never ask only: "Is this feature good?"

Ask: "Is this feature useful for the prediction problem I am solving?"

05

Irrelevant Features

An irrelevant feature is information that has little or no useful relationship with the prediction we are trying to make.

For example, suppose we are predicting house prices.

LIKELY USEFUL House Size
LIKELY USEFUL Location
LIKELY IRRELEVANT Random Row Number

Removing clearly irrelevant information can help keep the model's input cleaner and simpler.

06

Feature Selection Does Not Mean Guessing

We should not simply remove a feature because it looks unimportant to us.

In real machine learning projects, feature selection can be supported by data analysis, domain knowledge, model evaluation, and statistical or algorithmic techniques.

For this course, the important concept is:

Choose features based on whether they provide useful information for the prediction problem.
07

A Complete Example

Suppose we want to predict whether a customer will buy a product.

Feature Example Decision
Previous Purchases 8 Keep
Website Visits 15 Keep
Customer ID 83742 Consider Removing
Membership Type Premium Keep

The selected features become the information the model uses to learn and make predictions.

REMEMBER THIS

Feature Selection Means Choosing the Right Inputs.

A dataset can contain many features, but we should focus on features that provide useful information for the prediction problem. Unnecessary or irrelevant features can be removed when appropriate.

QUICK CHECK

Which Features Would You Keep?

We want to predict a house's price.

House Size Likely useful
Number of Bedrooms Likely useful
Random Record ID Likely unnecessary
Answer

House size and number of bedrooms are reasonable features to keep because they can provide information about house prices. A random record ID usually does not describe the house and would generally not be useful.

NEXT TOPIC

Preparing Features for Python

We now know what features are, what labels are, and how to choose useful features. Next, we will see how those features are prepared and represented so Python and machine learning libraries can work with them.