# loading example data
data(vi_smol)
#mean encoding
#-------------
df <- target_encoding_mean(
df = vi_smol,
response = "vi_numeric",
predictor = "soil_type", #categorical
encoded_name = "soil_type_encoded"
)
if(interactive()){
plot(
x = df$soil_type_encoded,
y = df$vi_numeric,
xlab = "encoded variable",
ylab = "response"
)
}
#rank encoding
#----------
df <- target_encoding_rank(
df = vi_smol,
response = "vi_numeric",
predictor = "soil_type",
encoded_name = "soil_type_encoded"
)
if(interactive()){
plot(
x = df$soil_type_encoded,
y = df$vi_numeric,
xlab = "encoded variable",
ylab = "response"
)
}
#leave-one-out
#-------------
df <- target_encoding_loo(
df = vi_smol,
response = "vi_numeric",
predictor = "soil_type",
encoded_name = "soil_type_encoded"
)
if(interactive()){
plot(
x = df$soil_type_encoded,
y = df$vi_numeric,
xlab = "encoded variable",
ylab = "response"
)
}
Run the code above in your browser using DataLab