Calculates out-of-fold mean features (also known as target encoding) for train and test data. This strategy is widely used to avoid overfitting or causing leakage while creating features using the target variable. This method is experimental. If the results you get are unexpected, please report them in github issues.
kFoldMean(train_df, test_df, colname, target, n_fold = 5, seed = 42)
train dataset
test dataset
name of categorical column
the target or dependent variable, should be a string.
the number of folds to use for doing kfold computation, default=5
the seed value, to ensure reproducibility, it could be any positive value, default=42
a train and test data table with out-of-fold mean value of the target for the given categorical variable
train <- data.frame(region=c('del','csk','rcb','del','csk','pune','guj','del'),
win = c(0,1,1,0,0,0,0,1))
test <- data.frame(region=c('rcb','csk','rcb','del','guj','pune','csk','kol'))
train_result <- kFoldMean(train_df = train,
test_df = test,
colname = 'region',
target = 'win',
seed = 1220)$train
#> Warning: This method is experimental. If the results you get are unexpected,please report them in github issues.
test_result <- kFoldMean(train_df = train,
test_df = test,
colname = 'region',
target = 'win',
seed = 1220)$test
#> Warning: This method is experimental. If the results you get are unexpected,please report them in github issues.