Skip to contents

modelblueprint is a model-agnostic container for managing machine learning model lifecycles in R. Wrap any predict()-compatible model - lm, glm, XGBoost, H2O, and more - with its training data, pipeline functions, and metadata, then run diagnostics with a single function call.

Installation

# Install from GitHub
pak::pak("mattyoreilly/modelblueprint")

Overview

library(modelblueprint)

mb <- modelblueprint(
  model  = glm(vs ~ wt + hp, data = mtcars, family = binomial),
  train  = mtcars,
  y_name = "vs",
  expo_name = "exposure",
  model_display_name = "logistic_vs"
)

# Predict
predict(mb, mtcars)

# One-way analysis - pulled directly from blueprint slots
one_way(mb, var = "wt")

# Partial dependence plot
pdp(mb, var = "wt")

# Gains chart with Gini coefficient — one chart per available set by default;
# pass set = "train" (or "test"/"holdout") for a single chart
gain(mb)

# Calibration chart
pred_vs_obs(mb)

# Grouped residuals with loess trend
residuals_grouped(mb)

# Or run the whole diagnostic suite in one call: writes gain, calibration,
# residual, one-way, stability, PDP and SHAP plots as structured HTML files
# under <getwd()>/<model_display_name>/
model_validation(mb)

# Save and restore
savemb(mb, path = "models/", filename = "logistic_vs")
mb2 <- loadmb("models/logistic_vs.tar.gz")

Key features

  • Model-agnostic - works with any R model implementing predict(), including H2O
  • Pipe-friendly - filter(), mutate(), and left_join() methods return new modelblueprints
  • Diagnostic plots - one-way, PDP, gains, calibration, and residual plots built in
  • Persistence - save and restore full model pipelines including H2O models
  • S7 class system - type-safe properties with informative validation errors

Supported models

Model Package Regression Classification
Linear model base R
GLM (Gaussian, Binomial, Poisson) base R
Decision tree rpart
Random forest randomForest
Gradient boosting xgboost
H2O GLM / GBM / AutoML h2o
Any predict()-compatible model -