featR puts 14 feature-selection methods for R behind one calling convention
and one return type: statistical filters, regularized and tree-based models,
and wrappers, plus two dimensionality-reduction helpers. Every supervised
selection function takes (data, target, ...) and returns an fs_result, so
comparing the lasso with Boruta or recursive feature elimination is a one-word
change. The modeling engines (glmnet, caret, Boruta, randomForest, brms, and
others) are optional; each function checks for the one it needs and tells you
what to install.
Documentation: https://elkronos.github.io/featR/
Install the released version from CRAN:
install.packages("featR")Or the development version from GitHub:
# install.packages("remotes")
remotes::install_github("elkronos/featR")Keep the mtcars columns correlated with mpg above 0.5, then drop the
redundant ones:
library(featR)
relevant <- fs_supervised(mtcars, target = "mpg", threshold = 0.5)
pruned <- fs_correlation(mtcars[, selected(relevant)], threshold = 0.8)
selected(pruned)
#> [1] "hp" "drat" "wt" "vs" "am" "carb"
summary(pruned) # ranked scores, kept features marked
# Same question, different method (needs glmnet)
selected(fs_lasso(mtcars, target = "mpg", seed = 1))
#> [1] "wt" "cyl" "hp" "am" "carb" "drat"The Getting started guide walks through this example and the calling convention.
| Family | Function | What it does |
|---|---|---|
| Filters | fs_unsupervised() |
Target-free threshold filter: variance, MAD, IQR, range, missing proportion, distinct-value count |
fs_supervised() |
Absolute correlation (numeric target) or ANOVA F (factor target) against a threshold | |
fs_correlation() |
Drops features until no pair is correlated above a threshold | |
fs_chi() |
Chi-squared tests between categorical features and a categorical target | |
fs_infogain() |
Information gain, optionally as gain ratio | |
| Regularization and embedded | fs_lasso() |
Cross-validated lasso (glmnet) |
fs_elastic() |
Elastic net tuned over an alpha grid (caret, glmnet) | |
fs_randomforest() |
Random-forest permutation importance with held-out evaluation | |
fs_mars() |
Multivariate adaptive regression splines (caret, earth) | |
| Wrappers | fs_recursivefeature() |
Recursive feature elimination (caret), evaluated on held-out rows |
fs_svm() |
SVM with SVM-RFE or random-forest RFE (caret, kernlab) | |
fs_boruta() |
Boruta all-relevant selection | |
fs_stepwise() |
Stepwise linear regression by AIC (MASS) | |
fs_bayes() |
Bayesian comparison of predictor subsets by LOO (brms, loo) | |
| Dimensionality reduction | fs_pca() |
Principal components; returns its own list, not an fs_result |
fs_svd() |
Exact SVD, or an approximate truncated one (RSpectra); returns its own list, not an fs_result |
Not sure which to use? See Choosing a method.
Any selection that looks at the outcome is part of model fitting, so error estimates from the rows that chose the features are optimistic. Validation and leakage lists which numbers featR reports are held-out estimates and which are not, and shows a pipeline that keeps them honest.
MIT (c) Justin Chase. See LICENSE.md.