Lesson Introduction

Welcome! Today, we're learning about Encoding Categorical Features. Have you ever thought about how computers understand things like colors, car brands, or animal types? These are categorical features. Computers are good at understanding numbers but not words, so we convert these words into numbers. This process is called encoding.

Our goal is to understand categorical features, why they need encoding, and how to use OneHotEncoder and LabelEncoder from SciKit Learn to do this. By the end, you'll be able to transform categorical data into numerical data for machine learning.

Introduction to Categorical Features

First, let's understand categorical features. Think about categories you see daily, like different types of fruits (apple, banana, cherry) or car colors (red, blue, green). These are examples of categorical features because they represent groups. In machine learning, these features must be converted to numbers to be understood.

Why encode these features? Machine learning algorithms only work with numerical data. It's like translating a book to another language; we convert categorical features to numbers so our models can "read" the data.

If a dataset includes car colors like Red, Blue, and Green, our model won't understand these words. We transform them into numbers for the model to use.

Introducing OneHotEncoder

One-hot encoding is a method to convert categorical data into a numerical format by creating binary columns for each category. Each column represents one category, and contains a 1 if the category is present and a if it is not. Here, let's look at an example for a better understanding. We will encode data with step-by-step.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal