NastępnyNastępny poradnik
Tokenizacja i kodowanie par bajtów
Techniczne
PRZEWODNIK techniczny
Kodowanie docelowe zastępuje kategorię liczbowym podsumowaniem wyniku zaobserwowanego dla tej kategorii w dozwolonych danych szkoleniowych.
Posłuchaj tego przewodnikaOpowiadane przez sztuczną inteligencję · ~3 min
It can make categorical inputs with many distinct values easier to model, but it requires careful separation of training labels to avoid leakage.
Categorical features describe groups such as depots, suppliers or product types. One-hot encoding creates a separate indicator for each category. With many categories, target encoding offers another representation: replace each category with an outcome summary, such as a mean delay for regression or a positive-outcome rate for binary classification. The useful signal is also the source of risk. Imagine a category that appears once. Its unsmoothed category mean is that row's outcome. If this value becomes an input for predicting the same row, the model is being given the answer. Strong training performance in this setup can disappear on new data. Cross-fitting helps construct safer training representations. Split the training data into folds, calculate category summaries using the other folds, and encode the held-out fold with those summaries. Repeat until each training row has an encoding built without its own fold's labels. The downstream model learns from these representations. At evaluation or prediction time, apply mappings learned from the permitted training data. Smoothing reduces the influence of categories with few observations by pulling their summaries toward a global training mean. A rare depot should not receive an extreme encoding solely because of one unusual delivery. The amount of smoothing is a modeling choice that needs validation. Scikit-learn's TargetEncoder documents an important distinction: fit_transform uses internal cross-fitting, while fitting and then transforming the same training data does not provide that equivalent protection. Do not assume every library implements the same behavior. Keep the encoder within the evaluation pipeline, define how unseen categories are handled, and adapt the splitting strategy when time order or repeated entities make ordinary random folds inappropriate.
A delivery model represents a depot using its historical mean delay, computed from training data. The same learned mapping is then applied to evaluation records without looking at their outcomes.
In a hypothetical smoothing rule, a category with two outcomes of 10 and 20 is combined with four prior observations at a global mean of 6. The smoothed value is (30 plus 24) divided by six, or 9.
A training fold contains a category seen in only one row. Encoding that row from its own outcome would reveal its label, so the team constructs its training representation from other folds.
An analyst uses scikit-learn's TargetEncoder in a Pipeline. They check its documented cross-fitting behavior instead of assuming that fit followed by transform is equivalent to fit_transform.
Categorical encoders will remain useful where operational data contains large numbers of changing identifiers. Teams can improve reliability by monitoring new categories, rare categories and shifts in their outcome patterns. They should also retain the training cutoff and encoder version alongside each deployed model, so a prediction can be traced to the mapping used. Automated pipelines could make leakage checks easier, but the key design decision remains human: determine which outcomes were available when a prediction would have been made, and ensure every derived feature respects that boundary.
Darmowy newsletter
Trzy zweryfikowane historie AI każdego poranka w dni robocze, napisane prostym angielskim. Bezpłatne na zawsze, bez reklam.
Jedno e‑mail każdego dnia roboczego. Wypisz się jednym kliknięciem. Nigdy nie sprzedajemy ani nie udostępniamy Twojego adresu.
Sprawdź się
Natychmiastowa informacja zwrotna na każde pytanie oraz udostępnialny certyfikat z weryfikowalnym ID po zaliczeniu kursu.
Wspieraj darmową edukację AI. AI Understanding jest organizacją non-profit 501(c)(3) — bez reklam, bez płatnej ściany, zawsze. Przekaż darowiznę
Target encoding replaces a category with a numerical summary of the outcome observed for that category in permitted training data. It can make categorical inputs with many distinct values easier to model, but it requires careful separation of training labels to avoid leakage.
Przy tylko jednej obserwacji średnia kategorii jest równa wartości docelowej, co powoduje wyciek odpowiedzi na dane wejściowe.
Inne zagięcia dostarczają statystyk kategorii, więc etykiety rozłożonej zakładki nie definiują jej reprezentacji.
Licznik to 30 plus cztery razy sześć, czyli 54. Mianownik to dwa plus cztery, czyli sześć. Wynik to dziewięć.
Małe próbki mogą dawać niestabilne ekstrema, a wygładzanie łagodzi ich wpływ przy użyciu informacji z szerszej populacji uczącej.
Udokumentowane zachowanie fit_transform obejmuje dopasowanie krzyżowe; dopasowanie, po którym następuje transformacja w tych samych wierszach, nie jest równoważne.
Ucz się dalej
Wybrano więcej przewodników na ten temat
NastępnyNastępny poradnik
Tokenizacja i kodowanie par bajtów
Techniczne