encode_impact: Create impact encoder, that turns factor variables into...

Description Usage Arguments Details Examples

Description

Create impact encoder, that turns factor variables into integers. Where as the numeric encoder attributes arbitrary integers to the factor levels, the impact encoder produces ordered levels (with respect to the target).

Usage

1
encode_impact(vars = categoricals, target)

Arguments

vars

Function or formula that returns selected columns from a data.frame. Alternatively, character vector of column names.

target

Name of the target variable.

Details

An approximate description of the algorithm is that the levels of the factors are ordered according to the mean value of the target for each level, but credibility is also taken into account. Under the hood, a model with random effects is used.

Examples

1
2
3
4
5
6
df <- data.frame(A=sample(c('a1', 'a2'), 100, replace=TRUE), y = runif(100))
prep <- encode_impact(vars = 'A', target = 'y')
prep$fit(df)
prep$transform(df)
# or more succintly
prep$fit_transform(df)

rtsho/preprocessr documentation built on May 29, 2019, 8:58 a.m.