
Cramer's V of Categorical Random Forest predictions vs. observations
Source:R/f_categorical_rf.R
f_categorical_rf.RdFits a univariate random forest model y ~ x with the character or factor response y and the numeric, character or factor predictor x using ranger::ranger() and returns the Cramer's V (see cor_cramer()) between the observed responses and the model predictions. Cases are weighted with case_weights() to prevent issues arising from class imbalance.
Cases are weighted with case_weights() to prevent issues arising from class imbalance.
Supports cross-validation via the arguments arguments cv_training_fraction (numeric between 0 and 1) and cv_iterations (integer between 1 and n) introduced via ellipsis (...). See preference_order() for further details.
See also
Other preference_order_functions:
f_binomial_gam(),
f_binomial_glm(),
f_binomial_rf(),
f_count_gam(),
f_count_glm(),
f_count_rf(),
f_numeric_gam(),
f_numeric_glm(),
f_numeric_rf(),
preference_order()
Examples
data(vi_smol, package = "spatialData")
df <- data.frame(
y = vi_smol[["vi_factor"]],
x = vi_smol[["soil_type"]]
)
#no cross-validation
f_categorical_rf(df = df)
#> [1] 0.4672802
#cross-validation
f_categorical_rf(
df = df,
cv_training_fraction = 0.5,
cv_iterations = 10
)
#> [1] 0.4542574 0.4698654 0.4501119 0.4086847 0.4306535 0.4283688 0.4753788
#> [8] 0.4458692 0.4788032 0.4696353
#numeric predictor
df <- data.frame(
y = vi_smol[["vi_categorical"]],
x = vi_smol[["swi_max"]]
)
f_categorical_rf(df = df)
#> [1] 0.531158