Feature selector that implements recursive feature elimination

Implements a greedy algorithm that iteratively calls the user-supplied scorer function and eliminates features based on its return value.

recursive_feature_elimination(scorer, X, y, n_features_to_select)

Arguments

scorer

A custom user-supplied function that accepts a data.frame as input and returns the column name of the column with the lowest weight.

X

A data.frame of shape (n_samples, n_features) with training samples.

y

A data.frame of shape (n_samples, n_outputs) with true outputs used for training.

n_features_to_select

The target number of features.

Value

Vector of column names of non-eliminated features.

Examples

custom_scorer_fn <- function(data) { model <- lm(Y ~ ., data) names(which.min(model$coefficients[-1]))[[1]] } df <- tgp::friedman.1.data() data <- dplyr::select(df, -Ytrue) X <- dplyr::select(data, -Y) y <- dplyr::select(data, Y) features <- featureselection::recursive_feature_elimination(custom_scorer_fn, X, y, 4) # [1] "X1" "X2" "X4" "X5" "Y"