## What is cardinality in machine learning?

In the context of machine learning, “cardinality” refers to the number of possible values that a feature can assume. For example, the variable “US State” is one that has 50 possible values. Dealing with high cardinality turned out to be one of the most interesting parts of the challenge.

### How do you encode categorical data with high cardinality?

You could look into the category_encoders . There you have many different encoders, which you can use to encode columns with high cardinality into a single column. Among them there are what are known as Bayesian encoders, which use information from the target variable to transform a given feature.

#### What is ordinal encoding?

Label Encoding or Ordinal Encoding This type of encoding is used when the variables in the data are ordinal, ordinal encoding converts each label into integer values and the encoded data represents the sequence of labels.

**What is Ordinalencoder in Python?**

Encode categorical features as an integer array. The input to this transformer should be an array-like of integers or strings, denoting the values taken on by categorical (discrete) features. The features are converted to ordinal integers. This results in a single column of integers (0 to n_categories – 1) per feature.

**What is cardinality in dataset?**

Cardinality is a mathematical term that refers to the number of elements in a given set. Database administrators may use cardinality to count tables and values.

## How do you handle cardinality?

Reducing Cardinality by using a simple Aggregating function Leave instances belonging to a value with high frequency as they are and replace the other instances with a new category which we will call other. Keep adding the frequency of these sorted (descending) unique values until a threshold is reached.

### How do you encode ordinal values?

A numerical variable can be converted to an ordinal variable by dividing the range of the numerical variable into bins and assigning values to each bin. For example, a numerical variable between 1 and 10 can be divided into an ordinal variable with 5 labels with an ordinal relationship: 1-2, 3-4, 5-6, 7-8, 9-10.

#### What is the difference between LabelEncoder and OrdinalEncoder?

The only different is that LabelEncoder returned an array, while OrdinalEncoder returned each element inside an array of arrays.

**Why do we need hot encoding?**

One hot encoding makes our training data more useful and expressive, and it can be rescaled easily. By using numeric values, we more easily determine a probability for our values. In particular, one hot encoding is used for our output values, since it provides more nuanced predictions than single labels.

**Is high cardinality good or bad?**

Having high cardinality data isn’t a bad thing, and knowing that our data is complex can help us find issues specifically tied to this. If you have performance or stability issues in your database, then it’s worth trying to lower the cardinality to fix those problems.

## How do you encode ordinal categorical variables?

https://www.youtube.com/watch?v=umFe7NLfQFw