funcml: A Formula-First Framework for Machine Learning in R
One consistent API across 20+ learners, resampling, tuning, interpretation, and causal estimation
Imad El Badisy
2025-06-01
Machine learning in R has long suffered from a fragmentation problem. Fitting a random forest, a regularized linear model, and a neural network each requires learning a different package, a different formula syntax, and a different set of conventions for prediction and evaluation. funcml was built to close that gap.
What is funcml?
funcml provides a unified, formula-first interface to supervised learning in R. Six top-level verbs cover the full ML workflow:
Verb
What it does
fit()
Train any learner via a common formula interface
evaluate()
Resampling-based performance with any metric
tune()
Grid or random hyperparameter search
compare_learners()
Benchmark multiple models side by side
interpret()
14 model-agnostic interpretability methods
estimate()
Plug-in g-computation for ATE/CATE estimation
Install from CRAN:
install.packages("funcml")
A minimal example
library(funcml)# fit a random forestfit_rf <-fit(Sepal.Length ~ ., data = iris, model ="ranger")# evaluate with 5-fold CVevaluate(data = iris, formula = Sepal.Length ~ ., model ="ranger", resampling =cv(5), seed =1)
interpret() wraps 14 methods, from permutation importance and partial dependence plots to SHAP values and accumulated local effects, behind a single call:
interpret(fit_rf, data = iris, method ="pdp", features ="Petal.Width")$result$curves |>head()
When the research question goes beyond prediction, estimate() wraps plug-in g-computation to estimate average and conditional treatment effects:
set.seed(1)n <-200X1 <-rnorm(n); X2 <-rnorm(n)A <-rbinom(n, 1, plogis(0.3* X1))Y <-1+0.5* A +0.4* X1 -0.2* X2 +rnorm(n)mydata <-data.frame(Y, A, X1, X2)# ATE of treatment A on outcome Y, adjusted for covariates Xestimate(data = mydata,formula = Y ~ A + X1 + X2,model ="ranger",treatment ="A",estimand ="ATE",seed =1)
<funcml_estimand> ATE via g-computation
Treatment: A (1 vs 0)
Estimate: 0.4531 | SE: 0.0156 | 95% normal CI [0.4225, 0.4836]
The learner registry
funcml ships with 26 learners spanning linear models, tree ensembles, SVMs, neural networks, additive models, boosting, and stacking. All are accessed by name: