# Kodowanie zmiennych kategorycznych

EN: **Categorical feature encoding** · id `categoricalencoding` · aliases: kodowanie kategorii, categorical encoding, kodowanie cech kategorycznych

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Uczenie maszynowe](https://aiatlasgraph.com/t/ml.md) › [Przygotowanie cech (feature engineering)](https://aiatlasgraph.com/t/featureeng.md) › Kodowanie zmiennych kategorycznych

## Description

- PL: Przekształcanie cech kategorycznych w reprezentacje liczbowe: one-hot, porządkowe, docelowe (target encoding) lub wyuczone embeddingi.
- EN: Converting categorical features into numeric representations: one-hot, ordinal, target encoding or learned embeddings.

## In one sentence

- PL: Zamiana słownych kategorii, takich jak kolor czy miasto, na liczby, z których model może korzystać.
- EN: Turning word categories such as colour or city into numbers a model can work with.

## Problem it solves

- PL: Modele liczą na liczbach, a w danych są nazwy miast, typy produktów czy kody, których nie da się użyć wprost.
- EN: Models compute with numbers, but data holds city names, product types or codes they cannot use directly.

## What it does

- PL: Daje każdej kategorii osobny przełącznik albo zastępuje ją średnim wynikiem, jaki ta kategoria miała w przeszłości.
- EN: It gives each category its own on/off switch, or replaces it with the average outcome that category had in the past.

## Everyday example

- PL: Przewidując cenę mieszkania, zamieniasz nazwę dzielnicy na liczby, żeby model mógł porównać dzielnice.
- EN: When predicting flat prices, you turn district names into numbers so the model can compare districts.

## This concerns you if you…

- PL: masz w tabeli kolumny z nazwami zamiast liczb
- PL: jedna kolumna ma setki różnych wartości
- EN: have columns of names rather than numbers
- EN: one column has hundreds of distinct values

## Keywords

OneHotEncoder · OrdinalEncoder · TargetEncoder · high cardinality · entity embeddings · hashing trick · CatBoost ordered target statistics

## How it works

- PL: One-hot tworzy osobną kolumnę binarną dla każdej kategorii, a kodowanie porządkowe nadaje liczby całkowite. Target encoding zastępuje kategorię wygładzoną średnią celu w tej kategorii, liczoną z cross-fittingiem, by wiersz nie widział własnej etykiety. Sieci uczą się osobnych embeddingów kategorii.
- EN: One-hot creates a binary column per category; ordinal encoding assigns integers. Target encoding replaces a category with a smoothed mean of the target for that category, computed with cross-fitting so a row never sees its own label. Neural networks learn category embeddings.

## Limits

- PL: One-hot rozdmuchuje liczbę kolumn przy wielu kategoriach. Target encoding bez cross-fittingu i wygładzania przecieka etykietą i przeucza rzadkie kategorie. Nowe, niewidziane kategorie wymagają reguły zastępczej.
- EN: One-hot inflates column count when categories are many. Target encoding without cross-fitting and smoothing leaks the label and overfits rare categories. Unseen categories need a fallback rule.

## Key terms

- PL: **one-hot**: Jedna kolumna 0/1 dla każdej możliwej kategorii.
- PL: **target encoding**: Zastąpienie kategorii średnim wynikiem obserwowanym dla niej w treningu.
- PL: **kardynalność**: Liczba różnych wartości, jakie przyjmuje kolumna.
- EN: **one-hot**: One 0/1 column for each possible category.
- EN: **target encoding**: Replacing a category with the average outcome observed for it in training.
- EN: **cardinality**: The number of distinct values a column takes.

## Related topics

Untyped, symmetric "see also" links.

- [Rodzaje wycieku danych i ich wykrywanie (Types of data leakage and their detection)](https://aiatlasgraph.com/t/leakagetypes.md)

## Sources

- [scikit-learn — TargetEncoder (API documentation)](<https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.TargetEncoder.html>) `sklearn-targetencoder` · by scikit-learn developers

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/categoricalencoding · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
