Learn R Programming

dataPreparation (version 0.4.3)

build_target_encoding: Build target encoding

Description

Target encoding is the process of replacing a categorical value with the aggregation of the target variable. build_target_encoding is used to compute aggregations.

Usage

build_target_encoding(
  dataSet,
  cols_to_encode,
  target_col,
  functions = "mean",
  verbose = TRUE
)

Arguments

dataSet

Matrix, data.frame or data.table

cols_to_encode

columns to aggregate according to (list)

target_col

column to aggregate (character)

functions

functions of aggregation (list or character, default to "mean")

verbose

Should the algorithm talk? (Logical, default to TRUE)

Value

A list of data.table a data.table for each cols_to_encode each data.table containing a line by unique value of column and len(functions) + 1 columns.

Examples

Run this code
# NOT RUN {
# Build a data set
require(data.table)
dataSet <- data.table(student = c("Marie", "Marie", "Pierre", "Louis", "Louis"), 
                      grades = c(1, 1, 2, 3, 4))

# Perform target_encoding construction
build_target_encoding(dataSet, cols_to_encode = "student", target_col = "grades", 
                      functions = c("mean", "sum"))
# }

Run the code above in your browser using DataLab