Automates feature engineering using evolutionary algorithms
inspired by genetic programming. Starting from raw input features, the
package evolves candidate transformation recipes through selection,
crossover, and mutation, evaluating fitness via cross-validation or
train/validation splits with gradient-boosted tree models ('LightGBM' or
'XGBoost'). Built-in transformers include arithmetic, logarithmic, and
power operations, interaction terms, target encoding, quantile and
log-based binning, principal component analysis, truncated singular value
decomposition, Uniform Manifold Approximation and Projection (UMAP)
dimensionality reduction, and minimum spanning tree (MST) graph-based
clustering. The evolutionary search yields an optimised feature recipe
that can be applied to new data for prediction. Methods are described in
McInnes et al. (2018)
evoFE (Evolutionary Feature Engineering) is an R package that uses a genetic algorithm to automatically discover, combine, and optimize feature transformations for tabular datasets. Instead of manually engineering interaction terms, ratios, or binning strategies, evoFE searches the space of possible feature recipes to maximize the predictive performance of LightGBM, XGBoost, or other ML models.
The final output is a reusable evo_recipe object that can be easily applied to new data at prediction time.
log(ratio(x1, x2))).cv) and stratified Train/Validation/Holdout Split (split) strategies.register_transformer() or custom ML backends with register_evaluator().mlr3mbo Bayesian optimization loop via make_tunable().print(), summary(), and plot() to inspect and visualize the evolution.record = TRUE.You can install the released version of evoFE from CRAN with:
install.packages("evoFE")
Alternatively, you can install the development version directly from GitHub:
# Install devtools if you haven't already
# install.packages("devtools")
# Install evoFE from GitHub
devtools::install_github("tanopereira/evoFE", build_vignettes = TRUE)
Several of evoFE's core transformers (like Genie and Lumbermark clustering) are implemented in C++ and parallelized using OpenMP. On macOS, R packages compile single-threaded by default. To enable multi-threading:
libomp via Homebrew:brew install libomp
~/.R/Makevars file to use OpenMP:SHLIB_OPENMP_CFLAGS = -Xpreprocessor -fopenmp
SHLIB_OPENMP_CXXFLAGS = -Xpreprocessor -fopenmp
CPPFLAGS += -I/opt/homebrew/opt/libomp/include
LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
quitefastmst, genieclust, lumbermark, and deadwood from source:install.packages(c("quitefastmst", "genieclust", "lumbermark", "deadwood"), type = "source")
Here is a quick example using the mtcars dataset for a binary classification task:
library(evoFE)
data(mtcars)
df <- mtcars
df$am <- as.integer(df$am) # target: 0 = automatic, 1 = manual
# Evolve features
set.seed(42)
recipe <- evolve_features(
data = df,
target_col = "am",
task = "classification",
evaluator = "xgboost",
generations = 5,
pop_size = 8,
cv_folds = 3,
verbose = TRUE
)
# View the winning recipe overview and detailed summary
print(recipe)
summary(recipe)
# Plot the evolution fitness curve
plot(recipe, type = "fitness")
# Engineer features on new data
engineered_df <- predict(recipe, df[1:5, ])
# Run predictions using the trained model
predictions <- predict_model(recipe, df[1:5, ])
evoFE ships with 42 built-in transformers that the genetic algorithm can select from during evolution.
| Category | Transformers |
|---|---|
| Arithmetic | log, sqrt, reciprocal, power, displaced_log, add, subtract, multiply, divide, normalized_difference, log_ratio |
| Rank / Distribution | rank_transform |
| Group-by Aggregations | groupby_mean, groupby_sd, groupby_max, groupby_min, groupby_median, groupby_quantile, groupby_ratio, groupby_zscore |
| Supervised Encoding | target_encode, pooled_target_encode, target_encode_multiclass, woe_encode |
| Unsupervised Encoding & Binning | frequency_encode, one_hot_encode, concat, quantile_binning, quantile_binning_cat, log_binning, log_binning_cat, datetime_extract |
| Dimensionality Reduction | pca, truncated_svd, random_projection, umap |
| Manifold & Graph Learning | genie, genie_centroid_dist, umap_genie, lumbermark, lumbermark_centroid_dist, umap_lumbermark, mst_score, deadwood |
This project is licensed under the MIT License - see the LICENSE file for details.