recursive_feature_elimination: Select features by Recursive Feature Elimination

Description Usage Arguments Value Examples

View source: R/recursive_feature_elimination.R

Description

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.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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"

UBC-MDS/feature-selection-r documentation built on April 27, 2020, 7:21 p.m.