Weight of Evidence¶

class
category_encoders.woe.
WOEEncoder
(verbose=0, cols=None, drop_invariant=False, return_df=True, handle_unknown='value', handle_missing='value', random_state=None, randomized=False, sigma=0.05, regularization=1.0)[source]¶ Weight of Evidence coding for categorical features.
Parameters:  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 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 will assume WOE=0.
 handle_unknown: str
options are ‘return_nan’, ‘error’ and ‘value’, defaults to ‘value’, which will assume WOE=0.
 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.
 regularization: float
the purpose of regularization is mostly to prevent division by zero. When regularization is 0, you may encounter division by zero.
References
[Ra54881acb8a41] Weight of Evidence (WOE) and Information Value Explained, from https://www.listendata.com/2015/03/weightofevidencewoeandinformation.html
Methods
fit
(self, X, y, \*\*kwargs)Fit encoder according to X and binary y. fit_transform
(self, X[, y])Encoders that utilize the target must make sure that the training data are transformed with: get_feature_names
(self)Returns the names of all transformed / added columns. get_params
(self[, deep])Get parameters for this estimator. set_params
(self, \*\*params)Set the parameters of this estimator. transform
(self, X[, y, override_return_df])Perform the transformation to new categorical data. 
fit
(self, X, y, **kwargs)[source]¶ Fit encoder according to X and binary y.
Parameters:  X : arraylike, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and n_features is the number of features.
 y : arraylike, shape = [n_samples]
Binary target values.
Returns:  self : encoder
Returns self.

fit_transform
(self, X, y=None, **fit_params)[source]¶  Encoders that utilize the target must make sure that the training data are transformed with:
 transform(X, y)
 and not with:
 transform(X)

get_feature_names
(self)[source]¶ Returns the names of all transformed / added columns.
Returns:  feature_names: list
A list with all feature names transformed or added. Note: potentially dropped features are not included!

transform
(self, 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.
Parameters:  X : arraylike, shape = [n_samples, n_features]
 y : arraylike, shape = [n_samples] when transform by leave one out
None, when transform without target information (such as transform test set)
Returns:  p : array, shape = [n_samples, n_numeric + N]
Transformed values with encoding applied.