Package 'awe'

Title: Analyze, Wrap, Explain -- An End-to-End Framework for Exploratory Data Analysis, Modelling, and Explainable Machine Learning
Description: Provides a single, coherent workflow that carries a data set from import through exploratory data analysis, automatic model selection across a broad bank of regression and classification learners, model wrapping, ensembling, hyperparameter tuning, explainability (permutation importance, partial dependence, individual conditional expectation, and optional SHAP/LIME via 'DALEX'/'iml' when installed), evaluation, narrative storytelling, and reporting. The name 'awe' stands for the three pillars of the package: Analyze, Wrap, Explain. A single call to awe() returns an 'awe' object that can be summarised, plotted, explained, and reported with simple generic methods (summary(), plot(), explain(), report(), predict()). A consistent, ggplot2-based visual identity (theme_awe(), awe_palette()) is used throughout, with base-graphics fallbacks so the package never requires a plotting dependency.
Authors: Olushina Olawale Awe [aut, cre]
Maintainer: Olushina Olawale Awe <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2026-11-29 16:09:44 UTC
Source: https://github.com/olawaleawe/awe

Help Index


Analyze, Wrap, Explain: the end-to-end AWE pipeline

Description

A single call runs a data set through the whole analytical workflow: explore -> preprocess -> select features -> model -> wrap -> explain -> evaluate -> story. Each stage is also exported on its own (awe_explore(), awe_preprocess(), awe_select_features(), awe_model(), awe_wrap(), awe_explain(), awe_evaluate(), awe_story()) for users who want to run or customise individual steps – in the same spirit as caret's train(), but covering the whole workflow rather than just fitting.

Usage

awe(
  data,
  target,
  k = 5,
  test_prop = 0.25,
  stratify = TRUE,
  select_features = FALSE,
  top_n_features = NULL,
  models = NULL,
  explain = TRUE,
  seed = 42
)

Arguments

data

data.frame

target

character, name of the target/outcome column

k

number of cross-validation folds used for model selection

test_prop

proportion of data held out for evaluation

stratify

logical, whether the train/test split should be stratified by the target (see awe_preprocess)

select_features

logical, whether to run automatic feature selection (near-zero-variance + correlation filters, see awe_select_features) before modelling

top_n_features

optional integer cap on the number of predictors kept by feature selection (by univariate association with the target); NULL keeps everything that survives the nzv/correlation filters

models

optional character vector restricting which model candidates to try (see awe_model); NULL tries all available for the detected target type

explain

logical, whether to compute explanations (can be slow on large data; set to FALSE to skip)

seed

random seed used throughout for reproducibility

Value

an object of class awe, a list with elements explore, preprocess, feature_selection, model, wrapper, explainer, evaluation, and story

Examples

fit <- awe(mtcars, target = "mpg", k = 3)
print(fit)
summary(fit)

Compare cross-validated leaderboards across multiple AWE runs

Description

Stacks the leaderboards of several awe_model (or awe) results into one data.frame, tagged by run, so different feature sets, preprocessing choices, or target definitions can be compared side by side. See plot.AWECompare for a grouped comparison chart.

Usage

awe_compare(..., labels = NULL)

Arguments

...

two or more AWEModel or awe objects, or a single (optionally named) list of such objects

labels

optional character vector of run labels (default: names(...) if supplied via a named list, else "run1", "run2", ...)

Value

an object of class AWECompare

Examples

m1 <- awe_model(mtcars, target = "mpg", k = 3)
m2 <- awe_model(mtcars, target = "mpg", k = 3, models = c("linear_regression", "decision_tree"))
cmp <- awe_compare(full = m1, restricted = m2)
print(cmp)

Build a model ensemble from the top cross-validated candidates

Description

Combines the top top_n candidates from an awe_model leaderboard into a single ensemble: a performance-weighted average for continuous targets, or a performance-weighted majority vote for classification targets. The result is an AWEWrapper (subclassed AWEEnsemble) so it works everywhere a normal wrapper does – predict(), awe_evaluate, awe_explain, varImp.

Usage

awe_ensemble(model_result, top_n = 3)

Arguments

model_result

an AWEModel object (from awe_model())

top_n

how many of the best cross-validated candidates to combine

Value

an object of class c("AWEEnsemble", "AWEWrapper")

Examples

m <- awe_model(mtcars, target = "mpg", k = 3)
ens <- awe_ensemble(m, top_n = 3)
print(ens)
predict(ens, newdata = mtcars[1:5, ])

Evaluate a wrapped model on held-out data

Description

Computes classification metrics (accuracy, precision, recall, F1, confusion matrix) or regression metrics (RMSE, MAE, MAPE, R-squared) depending on the target type.

Usage

awe_evaluate(wrapper, newdata)

Arguments

wrapper

an AWEWrapper object

newdata

data.frame to evaluate on (e.g. a held-out test set)

Value

an object of class AWEEvaluation


Explain a wrapped model

Description

Computes permutation feature importance and partial dependence / individual conditional expectation curves using base R alone, so this always works. When DALEX (and, for SHAP specifically, iml or DALEX's own predict_parts) is installed, break-down/SHAP-style local explanations are added automatically.

Usage

awe_explain(
  wrapper,
  newdata = NULL,
  n_permutations = 5,
  pdp_vars = NULL,
  seed = 42
)

Arguments

wrapper

an AWEWrapper object

newdata

optional data to explain on (defaults to training data)

n_permutations

number of permutation repeats for importance

pdp_vars

character vector of variables to compute PDP/ICE for (default: all predictors, capped at 8 for speed)

seed

random seed

Value

an object of class AWEExplainer


Automatic exploratory data summary

Description

Produces a structured, no-decisions-required summary of a data set: dimensions, column types, missing values, outliers (IQR rule for numeric columns), skewness/kurtosis, and a simple correlation matrix for numeric columns.

Usage

awe_explore(data, target = NULL)

Arguments

data

a data.frame

target

optional name of the target column, excluded from "predictor-only" diagnostics but still summarised

Value

an object of class AWEExplore (a list)

Examples

e <- awe_explore(mtcars)
print(e)

Automatic model selection

Description

Trains a bank of candidate models appropriate to the detected target type (continuous, binary, or multiclass), evaluates each with k-fold cross-validation, and returns every fitted candidate plus the best one – in the spirit of caret's train(), but with zero required dependencies beyond base R and rpart.

Usage

awe_model(data, target, k = 5, models = NULL, seed = 42)

Arguments

data

data.frame (already preprocessed, e.g. via awe_preprocess())

target

character, name of the target column

k

number of cross-validation folds

models

optional character vector restricting which candidates to try (by name, e.g. c("linear_regression", "random_forest")). Default NULL tries every available candidate for the detected target type.

seed

random seed

Details

Candidates always include dependable base-R learners (lm/glm, rpart trees, and a base-R k-NN) so the function never fails for lack of a suggested package. When installed, the following are added automatically as extra candidates: randomForest, ranger, xgboost, nnet, e1071 (SVM, naive Bayes), kernlab (SVM), glmnet (ridge/lasso/elastic net/regularized logistic), gbm, class (k-NN classification), MASS (LDA/QDA/robust regression), earth (MARS), and pls (partial least squares). Routine engine warnings/messages (convergence notices, verbosity) are silenced; genuine fitting failures still drop that one candidate with an informative message. Use awe_registry to list every candidate name available for a given target type without fitting anything.

Value

an object of class AWEModel

Examples

m <- awe_model(mtcars, target = "mpg", k = 3)
print(m)
m2 <- awe_model(mtcars, target = "mpg", k = 3, models = c("linear_regression", "decision_tree"))

AWE colour palette and ggplot2 theme

Description

A small, consistent visual identity used across every plotting function in the package: a deep-green/gold palette (awe_palette()) and a clean ggplot2 theme (theme_awe()) built on theme_minimal() with refined gridlines, spacing, and typography. Both are exported so users can reuse them in their own ggplot2 plots.

Usage

awe_palette(n = 6)

theme_awe(base_size = 11)

Arguments

n

number of colours requested (recycled if larger than the base palette)

base_size

base font size passed to ggplot2::theme_minimal()

Value

awe_palette(): a character vector of hex colours. theme_awe(): a ggplot2 theme object.

Examples

awe_palette(3)

Lightweight automatic preprocessing

Description

Median/mode-imputes missing values, drops zero-variance columns, and returns a train/test split ready for modelling. This intentionally stays simple (no external dependency) so that awe() always works with base R alone; heavier pipelines (recipes, tidymodels) can be plugged in by preprocessing the data before calling awe().

Usage

awe_preprocess(data, target, test_prop = 0.25, stratify = TRUE, seed = 42)

Arguments

data

data.frame

target

character, name of the target column

test_prop

proportion of rows held out for testing

stratify

logical, whether to stratify the train/test split by the target. For binary/multiclass targets this samples test_prop of rows from each class, keeping class proportions consistent between train and test. For continuous targets it stratifies by quartile bins of the target so the two sets span a similar range. Set to FALSE for a simple random split.

seed

random seed for the split

Value

a list with train, test, and dropped_vars

Examples

sp <- awe_preprocess(iris, target = "Species", stratify = TRUE)
prop.table(table(sp$train$Species))
prop.table(table(sp$test$Species))

List available model candidate names

Description

Returns the names of every model candidate awe_model would try for a given target type, without fitting anything, distinguishing candidates that are always available (base R) from ones added only when an optional package is installed.

Usage

awe_registry(target_type = c("continuous", "binary", "multiclass"))

Arguments

target_type

one of "continuous", "binary", "multiclass"

Value

a data.frame with columns model and requires

Examples

awe_registry("continuous")

Generate a report from an AWE analysis

Description

Writes a self-contained Markdown report (always available) and, when rmarkdown (plus a working Pandoc) is installed, renders it to HTML as well.

Usage

awe_report(
  x,
  file = file.path(tempdir(), "awe_report"),
  format = c("md", "html")
)

Arguments

x

an awe object

file

output file path without extension (default: "awe_report" in tempdir())

format

one of "md", "html"

Value

invisibly, the path to the generated file


Save/load an AWE object to/from disk

Description

Thin, discoverable wrappers around saveRDS()/readRDS() for persisting any awe, AWEModel, AWEWrapper, or other AWE object between R sessions.

Usage

awe_save(x, file)

awe_load(file)

Arguments

x

an AWE object to save

file

path to write to / read from (.rds recommended)

Value

awe_save(): invisibly, file. awe_load(): the restored object.

Examples

m <- awe_model(mtcars, target = "mpg", k = 3)
f <- tempfile(fileext = ".rds")
awe_save(m, f)
m2 <- awe_load(f)
identical(m$best_name, m2$best_name)

Automatic feature selection

Description

Screens predictors using up to three filters, in the spirit of caret's nearZeroVar() / findCorrelation():

  • Near-zero-variance: drops predictors that are almost constant (a small number of unique values, one of which dominates).

  • Correlation: among numeric predictors, drops one of any pair correlated above corr_cutoff (keeping the one with lower mean absolute correlation to the rest).

  • Univariate association with the target: scores every remaining predictor's association with the target (correlation for numeric-numeric, ANOVA F-statistic for numeric-categorical or categorical-numeric, Cramer's V for categorical-categorical) and optionally keeps only the top top_n.

Usage

awe_select_features(
  data,
  target,
  nzv = TRUE,
  freq_cutoff = 19,
  unique_cutoff = 10,
  correlation = TRUE,
  corr_cutoff = 0.9,
  top_n = NULL
)

Arguments

data

data.frame

target

character, name of the target column (excluded from filtering; used only for the univariate scores)

nzv

logical, apply the near-zero-variance filter

freq_cutoff

ratio of the most common to second-most-common value above which a predictor is flagged as near-zero-variance

unique_cutoff

percentage of unique values below which a predictor is flagged as near-zero-variance

correlation

logical, apply the pairwise correlation filter

corr_cutoff

absolute correlation above which one of a pair of numeric predictors is dropped

top_n

optional integer, keep only the top top_n remaining predictors by univariate association with the target (NULL keeps all that survive the nzv/correlation filters)

Value

an object of class AWEFeatureSelection: a list with selected (character vector of kept predictors), dropped (named list of dropped variables per filter), scores (data.frame of univariate scores), and data (the input data subset to the selected predictors plus the target)

Examples

fs <- awe_select_features(mtcars, target = "mpg", top_n = 5)
fs$selected

Turn an AWE analysis into a plain-language narrative

Description

Automatically drafts an executive summary, key findings, and recommendations from the exploratory summary, model leaderboard, explainer, and evaluation components of an awe analysis.

Usage

awe_story(x)

Arguments

x

an awe object (from awe())

Value

an object of class AWEStory, and invisibly its text


Hyperparameter tuning by grid search

Description

A light-weight, dependency-free (beyond the modelling engine itself) grid-search tuner, in the spirit of caret's train() with a tuneGrid. Cross-validates every combination of hyperparameters in grid and refits the best combination on the full data set.

Usage

awe_tune(
  data,
  target,
  model = c("decision_tree", "random_forest", "glmnet", "svm_radial"),
  grid = NULL,
  k = 5,
  seed = 42
)

Arguments

data

data.frame

target

character, name of the target column

model

one of "decision_tree", "random_forest", "glmnet", "svm_radial"

grid

optional data.frame of hyperparameter combinations to try (column names depend on model: cp for decision_tree; mtry for random_forest; alpha for glmnet; cost/gamma for svm_radial). Default NULL uses a sensible built-in grid.

k

number of cross-validation folds

seed

random seed

Value

an object of class AWETune with results (the grid plus CV scores), best_params, and wrapper (an AWEWrapper fit with the best hyperparameters on the full data)

Examples

tn <- awe_tune(mtcars, target = "mpg", model = "decision_tree", k = 3)
tn$best_params

Wrap a fitted model into a common AWEWrapper interface

Description

Bundles a fitted model together with its training data, prediction function, target name, and metadata into a single object with a consistent predict() method, regardless of which underlying engine (lm, glm, rpart, randomForest, xgboost, ...) produced it. This is what the rest of the "wrap" and "explain" pipeline operates on.

Usage

awe_wrap(
  model_result,
  which = NULL,
  data = NULL,
  target = NULL,
  predict_fn = NULL
)

Arguments

model_result

an AWEModel object (from awe_model()), or a raw fitted model object

which

character, name of a specific candidate to wrap instead of the overall best model (only used when model_result is an AWEModel; see names(model_result$candidates_fitted)). Default NULL wraps the best model.

data

data.frame used for training (required if model_result is a raw model rather than an AWEModel)

target

character target name (required if model_result is a raw model)

predict_fn

optional custom prediction function function(model, newdata)

Value

an object of class AWEWrapper

Examples

m <- awe_model(mtcars, target = "mpg", k = 3)
w <- awe_wrap(m)                          # wraps the best model
w_tree <- awe_wrap(m, which = "decision_tree")  # wraps a specific candidate

Automatic bivariate EDA against a target variable

Description

Detects the type of each predictor and the target and chooses an appropriate paired plot: scatter (numeric x numeric), boxplot (numeric x categorical), or a mosaic-style proportion bar chart (categorical x categorical).

Usage

eda_bivariate(data, target, vars = NULL, max_vars = 12)

Arguments

data

data.frame

target

character, name of the target column

vars

optional character vector of predictors (default: all others)

max_vars

safety cap on the number of plots produced


Combined multi-panel EDA overview

Description

Arranges eda_univariate plots for several variables into a single multi-panel figure using patchwork (or gridExtra as a fallback) when ggplot2 is available, for a quick visual overview of a data set's distributions in one call.

Usage

eda_report(data, vars = NULL, max_vars = 9, ncol = 3)

Arguments

data

data.frame

vars

optional character vector of columns to plot (default: all)

max_vars

safety cap on number of panels

ncol

number of columns in the panel grid

Value

the combined plot object (invisibly, if only base graphics are available, in which case panels are drawn directly via par(mfrow))


Automatic univariate EDA

Description

Chooses an appropriate plot for every column: histogram + density for numeric variables, bar plot for categorical variables. Uses ggplot2 when installed, and falls back to base graphics otherwise, so the function never fails purely for lack of a suggested plotting package.

Usage

eda_univariate(data, vars = NULL, max_vars = 12)

Arguments

data

data.frame

vars

optional character vector of columns to plot (default: all)

max_vars

safety cap on number of plots produced in one call

Value

invisibly, a list of the plot objects (ggplot objects if ggplot2 is available, otherwise NULL, since base plots draw directly to the graphics device)


Explain generic

Description

Explain generic

Usage

explain(x, ...)

Arguments

x

object to explain

...

additional arguments passed to methods


Confusion-matrix heatmap

Description

Confusion-matrix heatmap

Usage

plot_confusion(evaluation)

Arguments

evaluation

an AWEEvaluation object (from awe_evaluate) on a classification target


Correlation heatmap

Description

Correlation heatmap

Usage

plot_correlation(data, vars = NULL)

Arguments

data

data.frame

vars

optional character vector of numeric columns (default: all numeric columns)


Feature-selection score plot

Description

Feature-selection score plot

Usage

plot_feature_selection(fs, top_n = 15)

Arguments

fs

an AWEFeatureSelection object (from awe_select_features())

top_n

how many top-scoring variables to display


Model leaderboard comparison plot

Description

Model leaderboard comparison plot

Usage

plot_leaderboard(model_result)

Arguments

model_result

an AWEModel object


Missing-value overview plot

Description

Missing-value overview plot

Usage

plot_missingness(data)

Arguments

data

data.frame


Regression diagnostic plots: residuals vs fitted, and a normal Q-Q plot

Description

Regression diagnostic plots: residuals vs fitted, and a normal Q-Q plot

Usage

plot_residuals(wrapper, newdata = NULL)

Arguments

wrapper

an AWEWrapper fit on a continuous target

newdata

data to evaluate on (default: the wrapper's training data)


ROC curve and AUC for a binary classifier

Description

Computes a receiver operating characteristic curve from a fitted AWEWrapper using its native class probabilities when the engine supplies them (see names(awe_registry("binary")) for which do), falling back to hard 0/1 predictions otherwise. AUC is computed rank-based (Mann-Whitney U), no extra dependency required.

Usage

plot_roc(wrapper, newdata = NULL, positive = NULL)

Arguments

wrapper

an AWEWrapper fit on a binary target

newdata

data to evaluate on (default: the wrapper's training data)

positive

the level treated as the positive class (default: the second factor level)

Value

invisibly, a list with roc (data.frame of fpr/tpr) and auc; the plot is drawn (or, with ggplot2, returned) as a side effect


Plot a decision tree from an AWE model

Description

Visualises a fitted rpart tree candidate (rpart.plot if installed, base rpart plotting otherwise).

Usage

plot_tree(x, which = "decision_tree")

Arguments

x

an AWEModel or AWEWrapper object

which

which candidate to plot if x is an AWEModel with multiple candidates (default: "decision_tree")


Plot an AWE analysis

Description

Plot an AWE analysis

Usage

## S3 method for class 'awe'
plot(
  x,
  type = c("importance", "pdp", "leaderboard", "tree", "roc", "confusion", "residuals"),
  var = NULL,
  which = "decision_tree",
  ...
)

Arguments

x

an awe object

type

one of "importance" (permutation importance), "pdp" (partial dependence for one variable, see var), "leaderboard" (cross-validated model comparison), "tree" (visualise a decision-tree candidate, see which), "roc" (ROC curve, binary targets only), "confusion" (confusion-matrix heatmap, classification only), or "residuals" (residual diagnostics, continuous targets only)

var

variable name, used when type = "pdp"

which

candidate model name, used when type = "tree" (default "decision_tree")

...

passed on to the underlying plot method


Grouped bar chart comparing model leaderboards across runs

Description

Grouped bar chart comparing model leaderboards across runs

Usage

## S3 method for class 'AWECompare'
plot(x, ...)

Arguments

x

an AWECompare object

...

unused


Plot an AWE explainer

Description

Plot an AWE explainer

Usage

## S3 method for class 'AWEExplainer'
plot(x, type = c("importance", "pdp"), var = NULL, top_n = 15, ...)

Arguments

x

an AWEExplainer object

type

"importance" for a permutation-importance bar chart, or "pdp" for a partial-dependence curve (with faint individual ICE curves in the background when ggplot2 is available)

var

variable name, used when type = "pdp"

top_n

how many variables to show when type = "importance"

...

unused


Report generic

Description

Report generic

Usage

report(x, ...)

Arguments

x

object to report on

...

additional arguments passed to methods


Variable importance

Description

A caret-style varImp() generic. Uses each engine's native importance measure when available (e.g. $variable.importance for rpart, importance() for randomForest, absolute t-values for lm/glm), and falls back to permutation importance (awe_explain) for any other model type.

Usage

varImp(object, ...)

## S3 method for class 'AWEWrapper'
varImp(object, ...)

## S3 method for class 'awe'
varImp(object, ...)

Arguments

object

model or wrapper object

...

additional arguments passed to methods

Value

a data.frame with columns variable and importance, sorted descending