Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Ordinal Encoding | The Very First Steps
Introduction to Scikit Learn
course content

Course Content

Introduction to Scikit Learn

Introduction to Scikit Learn

1. The Very First Steps
2. Scaling Numerical Data
3. Models in Scikit Learn

bookOrdinal Encoding

Features can be divided into categorical and numerical.

A categorical feature is a feature whose value can be attributed to any group, but the order of the values in this group is completely unimportant. Between the values of categorical features it is impossible to establish the relationship > or < ('greater' or 'less').

The value of a numeric feature is a scalar. Between the values of numeric features it is possible to establish the relationship 'greate' or 'less'.

КАРТИНКА???

Scikit-learn does not support processing of categorical features. So we should move to numerical representation

We have the two most techniques to move to numerical representation: an Ordinal Encoding and an One-Hot Encoding. Let's get acquainted with the one of them Ordinal Encoding - the point of this encoding is that each unique value of the category is encoded with an integer number. For example: python is 1, SQL is 2, Java is 3.

Now, let's look at the example how to implelemt this encoding.

123456789101112131415
# example of a ordinal encoding import pandas as pd from sklearn.preprocessing import OrdinalEncoder # define data data = pd.read_csv('C:/Users/User1/Desktop/РОБОТА/Data.csv') print(data) # define ordinal encoding encoder = OrdinalEncoder() # transform data result = encoder.fit(data) result = result.transform(data) print(result)
copy

It is time for an example.

Analysis

We see that here the missing values are represented by zeros(missing_values = 0), we replace them with the mean value(strategy ='mean') of the column in which the missing value is located.

Task

Swipe to show code editor

test

Let's try to fill the empty space in your small dataset.To use SimpleImputer you have to implement the next steps:

  1. Import the class.
  2. Create an instance of the class (imputer object).
  3. Specify the parameters you need, especially: we see that here the missing values are represented by NaN, so replace them with the constant value 15.
  4. Fit the imputer on your data using fit() function
  5. Impute all missing values in you data using transform() function.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 3
toggle bottom row

bookOrdinal Encoding

Features can be divided into categorical and numerical.

A categorical feature is a feature whose value can be attributed to any group, but the order of the values in this group is completely unimportant. Between the values of categorical features it is impossible to establish the relationship > or < ('greater' or 'less').

The value of a numeric feature is a scalar. Between the values of numeric features it is possible to establish the relationship 'greate' or 'less'.

КАРТИНКА???

Scikit-learn does not support processing of categorical features. So we should move to numerical representation

We have the two most techniques to move to numerical representation: an Ordinal Encoding and an One-Hot Encoding. Let's get acquainted with the one of them Ordinal Encoding - the point of this encoding is that each unique value of the category is encoded with an integer number. For example: python is 1, SQL is 2, Java is 3.

Now, let's look at the example how to implelemt this encoding.

123456789101112131415
# example of a ordinal encoding import pandas as pd from sklearn.preprocessing import OrdinalEncoder # define data data = pd.read_csv('C:/Users/User1/Desktop/РОБОТА/Data.csv') print(data) # define ordinal encoding encoder = OrdinalEncoder() # transform data result = encoder.fit(data) result = result.transform(data) print(result)
copy

It is time for an example.

Analysis

We see that here the missing values are represented by zeros(missing_values = 0), we replace them with the mean value(strategy ='mean') of the column in which the missing value is located.

Task

Swipe to show code editor

test

Let's try to fill the empty space in your small dataset.To use SimpleImputer you have to implement the next steps:

  1. Import the class.
  2. Create an instance of the class (imputer object).
  3. Specify the parameters you need, especially: we see that here the missing values are represented by NaN, so replace them with the constant value 15.
  4. Fit the imputer on your data using fit() function
  5. Impute all missing values in you data using transform() function.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 3
toggle bottom row

bookOrdinal Encoding

Features can be divided into categorical and numerical.

A categorical feature is a feature whose value can be attributed to any group, but the order of the values in this group is completely unimportant. Between the values of categorical features it is impossible to establish the relationship > or < ('greater' or 'less').

The value of a numeric feature is a scalar. Between the values of numeric features it is possible to establish the relationship 'greate' or 'less'.

КАРТИНКА???

Scikit-learn does not support processing of categorical features. So we should move to numerical representation

We have the two most techniques to move to numerical representation: an Ordinal Encoding and an One-Hot Encoding. Let's get acquainted with the one of them Ordinal Encoding - the point of this encoding is that each unique value of the category is encoded with an integer number. For example: python is 1, SQL is 2, Java is 3.

Now, let's look at the example how to implelemt this encoding.

123456789101112131415
# example of a ordinal encoding import pandas as pd from sklearn.preprocessing import OrdinalEncoder # define data data = pd.read_csv('C:/Users/User1/Desktop/РОБОТА/Data.csv') print(data) # define ordinal encoding encoder = OrdinalEncoder() # transform data result = encoder.fit(data) result = result.transform(data) print(result)
copy

It is time for an example.

Analysis

We see that here the missing values are represented by zeros(missing_values = 0), we replace them with the mean value(strategy ='mean') of the column in which the missing value is located.

Task

Swipe to show code editor

test

Let's try to fill the empty space in your small dataset.To use SimpleImputer you have to implement the next steps:

  1. Import the class.
  2. Create an instance of the class (imputer object).
  3. Specify the parameters you need, especially: we see that here the missing values are represented by NaN, so replace them with the constant value 15.
  4. Fit the imputer on your data using fit() function
  5. Impute all missing values in you data using transform() function.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Features can be divided into categorical and numerical.

A categorical feature is a feature whose value can be attributed to any group, but the order of the values in this group is completely unimportant. Between the values of categorical features it is impossible to establish the relationship > or < ('greater' or 'less').

The value of a numeric feature is a scalar. Between the values of numeric features it is possible to establish the relationship 'greate' or 'less'.

КАРТИНКА???

Scikit-learn does not support processing of categorical features. So we should move to numerical representation

We have the two most techniques to move to numerical representation: an Ordinal Encoding and an One-Hot Encoding. Let's get acquainted with the one of them Ordinal Encoding - the point of this encoding is that each unique value of the category is encoded with an integer number. For example: python is 1, SQL is 2, Java is 3.

Now, let's look at the example how to implelemt this encoding.

123456789101112131415
# example of a ordinal encoding import pandas as pd from sklearn.preprocessing import OrdinalEncoder # define data data = pd.read_csv('C:/Users/User1/Desktop/РОБОТА/Data.csv') print(data) # define ordinal encoding encoder = OrdinalEncoder() # transform data result = encoder.fit(data) result = result.transform(data) print(result)
copy

It is time for an example.

Analysis

We see that here the missing values are represented by zeros(missing_values = 0), we replace them with the mean value(strategy ='mean') of the column in which the missing value is located.

Task

Swipe to show code editor

test

Let's try to fill the empty space in your small dataset.To use SimpleImputer you have to implement the next steps:

  1. Import the class.
  2. Create an instance of the class (imputer object).
  3. Specify the parameters you need, especially: we see that here the missing values are represented by NaN, so replace them with the constant value 15.
  4. Fit the imputer on your data using fit() function
  5. Impute all missing values in you data using transform() function.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 3
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt