Description Usage Arguments Value Examples
View source: R/recursive_feature_elimination.R
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.
1 | recursive_feature_elimination(scorer, X, y, n_features_to_select)
|
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. |
Vector of column names of non-eliminated features.
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"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.