class category_encoders.m_estimate.MEstimateEncoder(verbose=0, cols=None, drop_invariant=False, return_df=True, handle_unknown='value', handle_missing='value', random_state=None, randomized=False, sigma=0.05, m=1.0)[source]

M-probability estimate of likelihood.

Supported targets: binomial and continuous. For polynomial target support, see PolynomialWrapper.

This is a simplified version of target encoder, which goes under names like m-probability estimate or additive smoothing with known incidence rates. In comparison to target encoder, m-probability estimate has only one tunable parameter (m), while target encoder has two tunable parameters (min_samples_leaf and smoothing).

verbose: int

integer indicating verbosity of the output. 0 for none.

cols: list

a list of columns to encode, if None, all string columns will be encoded.

drop_invariant: bool

boolean for whether or not to drop encoded columns with 0 variance.

return_df: bool

boolean for whether to return a pandas DataFrame from transform (otherwise it will be a numpy array).

handle_missing: str

options are ‘return_nan’, ‘error’ and ‘value’, defaults to ‘value’, which returns the prior probability.

handle_unknown: str

options are ‘return_nan’, ‘error’ and ‘value’, defaults to ‘value’, which returns the prior probability.

randomized: bool,

adds normal (Gaussian) distribution noise into training data in order to decrease overfitting (testing data are untouched).

sigma: float

standard deviation (spread or “width”) of the normal distribution.

m: float

this is the “m” in the m-probability estimate. Higher value of m results into stronger shrinking. M is non-negative.



A Preprocessing Scheme for High-Cardinality Categorical Attributes in Classification and Prediction Problems, equation 7, from



On estimating probabilities in tree pruning, equation 1, from



Additive smoothing, from



fit(X, y, **kwargs)

Fit encoder according to X and binary y.

fit_transform(X[, y])

Encoders that utilize the target must make sure that the training data are transformed with:


Returns the names of all transformed / added columns.


Get parameters for this estimator.


Set the parameters of this estimator.

transform(X[, y, override_return_df])

Perform the transformation to new categorical data.

fit(X, y, **kwargs)[source]

Fit encoder according to X and binary y.

Xarray-like, shape = [n_samples, n_features]

Training vectors, where n_samples is the number of samples and n_features is the number of features.

yarray-like, shape = [n_samples]

Binary target values.


Returns self.


Returns the names of all transformed / added columns.

feature_names: list

A list with all feature names transformed or added. Note: potentially dropped features are not included!

transform(X, y=None, override_return_df=False)[source]

Perform the transformation to new categorical data.

When the data are used for model training, it is important to also pass the target in order to apply leave one out.

Xarray-like, shape = [n_samples, n_features]
yarray-like, shape = [n_samples] when transform by leave one out

None, when transform without target information (such as transform test set)

parray, shape = [n_samples, n_numeric + N]

Transformed values with encoding applied.