Target (Mean) Encoding with Smoothing
Target encoding replaces each level of a categorical variable by the average outcome of the rows with that level, pulled towards the overall average when the level is rare. The pull is set by an m-estimate (m pseudo-rows at the overall mean) or by Micci-Barreca's sigmoid blend. Training rows are encoded out-of-fold, so a row's own outcome never enters its own code.
타깃 인코딩은 범주형 변수의 각 수준을 그 수준에 속한 행들의 결과 평균으로 바꾸되, 행이 적은 수준일수록 전체 평균 쪽으로 끌어당깁니다. 끌어당기는 정도는 m-추정(전체 평균을 가진 가상의 행 m개)이나 마이시-바레카의 시그모이드 혼합으로 정합니다. 학습 행은 교차 적합으로 인코딩하므로 한 행의 결과가 자기 자신의 값에 들어가지 않습니다.
How can I turn a categorical variable with many levels into one informative numeric column without leaking the outcome?
수준이 아주 많은 범주형 변수를 결과 정보가 새지 않게 하나의 숫자 열로 바꾸려면 어떻게 합니까?
The method reports the encoded value of every level with its count and raw mean, the cross-fitted codes, and a cross-validated comparison of a model on cross-fitted versus naive in-sample codes that shows the leakage.
When to use Target (Mean) Encoding with Smoothing
- A categorical predictor has many levels (postcodes, product ids) and one-hot coding would create too many columns.
- The outcome is numeric or binary.
When to use something else
- You need interpretable effects of each level with standard errors: use Binary Logistic Regression
- The outcome has several unordered classes and the categorical predictor has few levels: use Multinomial Logistic Regression
Assumptions and requirements
- Levels seen in new data behave like in the training data
- Rare levels are shrunk to the overall mean; the amount of shrinkage is a tuning choice
- Rows are independent
What the analysis reports
- Encoded value, count and raw mean per level
- Cross-fitted codes for training rows
- Cross-validated AUC or R-squared with cross-fitted and naive codes
- Leakage warning when naive codes overfit
How to report it
Categorical predictors were target-encoded with m-estimate smoothing (m = [value]) and 5-fold cross-fitting; a logistic model on the codes had a cross-validated AUC of [value].
Related methods
How this method is validated
이 방법의 검증 근거
- Independent computation. 1 reference test compares the results with scikit-learn and direct computations (formulas, enumeration or simulation) at a stated tolerance of 1e-10.
독립 계산. scikit-learn·직접 계산(식·열거·모의실험) 대조 참조 시험 1건 통과(허용오차 1e-10).
Tolerances are relative differences (absolute differences for values near zero). R comparisons and reference tests are re-run before each release of the analysis engine.
허용오차는 상대 차이입니다(0 근처 값은 절대 차이). R 대조와 참조 시험은 분석 엔진을 배포할 때마다 다시 돌립니다.
Run Target (Mean) Encoding with Smoothing on Quorant
- Data you need
- a table (CSV or Excel) with an outcome variable and predictor (feature) columns
- Price
- 250 credits for one analysis up to 10,000 rows (complexity level 2); larger or wider data costs more. Optional methodologist review: 1200 credits.
- Checking
- Compared with independent computations
- Before you pay
- A free pre-analysis diagnosis checks your data and gives an exact quote; nothing is deducted until you approve it.