Frequency Encoding in Feature Engineering with Python

Learn how to apply frequency encoding, also known as count encoding, as a feature engineering technique in Python. This video covers the methods and implementation details for effective feature encoding.

Frequency Encoding in Feature Engineering with Python
Coder's Digest
2.1K views β€’ Dec 18, 2020
Frequency Encoding in Feature Engineering with Python

About this video

Feature Engineering python- In this video we will be feature encoding techniques and How to do frequency encoding also known as count or frequency encoding. we will discuss it with examples using python. Even if you use any other language such as Rstudio or scala , this video will be extremely helpful.

I this technique we simply replace our categories by the count or occurrence of that particular category.

I would encourage you to checkout my complete feature engineering playlist which will help you to learn and understand other feature engineering techniques also.

Feature Engineering playlist : https://youtube.com/playlist?list=PLyB8AGpv661FvHtb9jbNYSsnSANV4bkFG

pandas playlist : https://youtube.com/playlist?list=PLyB8AGpv661FAEgt1cNQKq_KeVpfFK21T

Source code for this video:
----------------------------------------------------------------------------
#!/usr/bin/env python
# coding: utf-8

import pandas as pd
from sklearn.model_selection import train_test_split

data = pd.read_csv('houseprice.csv', usecols=['MSZoning','Street','LotShape','Utilities','LandSlope','SalePrice'])

data.head()
data.isnull().mean()

X_train,X_test,y_train,y_test = train_test_split(data[['MSZoning','Street','LotShape','Utilities','LandSlope']],
data['SalePrice'], test_size =.3, random_state =111)

X_train.head()
X_train.shape
X_test.shape
y_train.shape
# In[32]:


y_train.head()


# In[33]:


Ms = X_train['MSZoning'].value_counts().to_dict()

Ms

cat_vars = ['MSZoning','Street','LotShape','Utilities','LandSlope']

encoder_dictionary ={}
for var in cat_vars:
encoder_dictionary[var] = (X_train[var].value_counts()/len(X_train)).to_dict()

encoder_dictionary


for var in cat_vars:
X_train[var] = X_train[var].map(encoder_dictionary[var])

X_train.head()


---------- End Source Code--------------------------------------------------

Related Tags:
How to deal with categorical data
Categorical encoding python
Machine learning tutorial
How to encode categorical variables
Count Encoding
One hot encoding
Feature engineering
Data Analytics

Tags and Topics

Browse our collection to discover more content in these categories.

Video Information

Views

2.1K

Likes

46

Duration

15:15

Published

Dec 18, 2020

User Reviews

4.5
(2)
Rate:

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.

Trending Now