| 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 |
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.
awe( data, target, k = 5, test_prop = 0.25, stratify = TRUE, select_features = FALSE, top_n_features = NULL, models = NULL, explain = TRUE, seed = 42 )awe( data, target, k = 5, test_prop = 0.25, stratify = TRUE, select_features = FALSE, top_n_features = NULL, models = NULL, explain = TRUE, seed = 42 )
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 |
select_features |
logical, whether to run automatic feature
selection (near-zero-variance + correlation filters, see
|
top_n_features |
optional integer cap on the number of predictors
kept by feature selection (by univariate association with the target);
|
models |
optional character vector restricting which model
candidates to try (see |
explain |
logical, whether to compute explanations (can be slow on large data; set to FALSE to skip) |
seed |
random seed used throughout for reproducibility |
an object of class awe, a list with elements
explore, preprocess, feature_selection,
model, wrapper, explainer, evaluation, and
story
fit <- awe(mtcars, target = "mpg", k = 3) print(fit) summary(fit)fit <- awe(mtcars, target = "mpg", k = 3) print(fit) summary(fit)
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.
awe_compare(..., labels = NULL)awe_compare(..., labels = NULL)
... |
two or more |
labels |
optional character vector of run labels (default:
|
an object of class AWECompare
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)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)
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.
awe_ensemble(model_result, top_n = 3)awe_ensemble(model_result, top_n = 3)
model_result |
an |
top_n |
how many of the best cross-validated candidates to combine |
an object of class c("AWEEnsemble", "AWEWrapper")
m <- awe_model(mtcars, target = "mpg", k = 3) ens <- awe_ensemble(m, top_n = 3) print(ens) predict(ens, newdata = mtcars[1:5, ])m <- awe_model(mtcars, target = "mpg", k = 3) ens <- awe_ensemble(m, top_n = 3) print(ens) predict(ens, newdata = mtcars[1:5, ])
Computes classification metrics (accuracy, precision, recall, F1, confusion matrix) or regression metrics (RMSE, MAE, MAPE, R-squared) depending on the target type.
awe_evaluate(wrapper, newdata)awe_evaluate(wrapper, newdata)
wrapper |
an |
newdata |
data.frame to evaluate on (e.g. a held-out test set) |
an object of class AWEEvaluation
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.
awe_explain( wrapper, newdata = NULL, n_permutations = 5, pdp_vars = NULL, seed = 42 )awe_explain( wrapper, newdata = NULL, n_permutations = 5, pdp_vars = NULL, seed = 42 )
wrapper |
an |
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 |
an object of class AWEExplainer
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.
awe_explore(data, target = NULL)awe_explore(data, target = NULL)
data |
a data.frame |
target |
optional name of the target column, excluded from "predictor-only" diagnostics but still summarised |
an object of class AWEExplore (a list)
e <- awe_explore(mtcars) print(e)e <- awe_explore(mtcars) print(e)
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.
awe_model(data, target, k = 5, models = NULL, seed = 42)awe_model(data, target, k = 5, models = NULL, seed = 42)
data |
data.frame (already preprocessed, e.g. via
|
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. |
seed |
random seed |
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.
an object of class AWEModel
m <- awe_model(mtcars, target = "mpg", k = 3) print(m) m2 <- awe_model(mtcars, target = "mpg", k = 3, models = c("linear_regression", "decision_tree"))m <- awe_model(mtcars, target = "mpg", k = 3) print(m) m2 <- awe_model(mtcars, target = "mpg", k = 3, models = c("linear_regression", "decision_tree"))
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.
awe_palette(n = 6) theme_awe(base_size = 11)awe_palette(n = 6) theme_awe(base_size = 11)
n |
number of colours requested (recycled if larger than the base palette) |
base_size |
base font size passed to |
awe_palette(): a character vector of hex colours.
theme_awe(): a ggplot2 theme object.
awe_palette(3)awe_palette(3)
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().
awe_preprocess(data, target, test_prop = 0.25, stratify = TRUE, seed = 42)awe_preprocess(data, target, test_prop = 0.25, stratify = TRUE, seed = 42)
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 |
seed |
random seed for the split |
a list with train, test, and dropped_vars
sp <- awe_preprocess(iris, target = "Species", stratify = TRUE) prop.table(table(sp$train$Species)) prop.table(table(sp$test$Species))sp <- awe_preprocess(iris, target = "Species", stratify = TRUE) prop.table(table(sp$train$Species)) prop.table(table(sp$test$Species))
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.
awe_registry(target_type = c("continuous", "binary", "multiclass"))awe_registry(target_type = c("continuous", "binary", "multiclass"))
target_type |
one of |
a data.frame with columns model and requires
awe_registry("continuous")awe_registry("continuous")
Writes a self-contained Markdown report (always available) and, when rmarkdown (plus a working Pandoc) is installed, renders it to HTML as well.
awe_report( x, file = file.path(tempdir(), "awe_report"), format = c("md", "html") )awe_report( x, file = file.path(tempdir(), "awe_report"), format = c("md", "html") )
x |
an |
file |
output file path without extension (default: "awe_report" in
|
format |
one of "md", "html" |
invisibly, the path to the generated file
Thin, discoverable wrappers around saveRDS()/readRDS() for
persisting any awe, AWEModel, AWEWrapper, or other
AWE object between R sessions.
awe_save(x, file) awe_load(file)awe_save(x, file) awe_load(file)
x |
an AWE object to save |
file |
path to write to / read from ( |
awe_save(): invisibly, file. awe_load(): the
restored object.
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)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)
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.
awe_select_features( data, target, nzv = TRUE, freq_cutoff = 19, unique_cutoff = 10, correlation = TRUE, corr_cutoff = 0.9, top_n = NULL )awe_select_features( data, target, nzv = TRUE, freq_cutoff = 19, unique_cutoff = 10, correlation = TRUE, corr_cutoff = 0.9, top_n = NULL )
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 |
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)
fs <- awe_select_features(mtcars, target = "mpg", top_n = 5) fs$selectedfs <- awe_select_features(mtcars, target = "mpg", top_n = 5) fs$selected
Automatically drafts an executive summary, key findings, and
recommendations from the exploratory summary, model leaderboard,
explainer, and evaluation components of an awe analysis.
awe_story(x)awe_story(x)
x |
an |
an object of class AWEStory, and invisibly its text
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.
awe_tune( data, target, model = c("decision_tree", "random_forest", "glmnet", "svm_radial"), grid = NULL, k = 5, seed = 42 )awe_tune( data, target, model = c("decision_tree", "random_forest", "glmnet", "svm_radial"), grid = NULL, k = 5, seed = 42 )
data |
data.frame |
target |
character, name of the target column |
model |
one of |
grid |
optional data.frame of hyperparameter combinations to try
(column names depend on |
k |
number of cross-validation folds |
seed |
random seed |
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)
tn <- awe_tune(mtcars, target = "mpg", model = "decision_tree", k = 3) tn$best_paramstn <- awe_tune(mtcars, target = "mpg", model = "decision_tree", k = 3) tn$best_params
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.
awe_wrap( model_result, which = NULL, data = NULL, target = NULL, predict_fn = NULL )awe_wrap( model_result, which = NULL, data = NULL, target = NULL, predict_fn = NULL )
model_result |
an |
which |
character, name of a specific candidate to wrap instead of
the overall best model (only used when |
data |
data.frame used for training (required if |
target |
character target name (required if |
predict_fn |
optional custom prediction function
|
an object of class AWEWrapper
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 candidatem <- 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
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).
eda_bivariate(data, target, vars = NULL, max_vars = 12)eda_bivariate(data, target, vars = NULL, max_vars = 12)
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 |
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.
eda_report(data, vars = NULL, max_vars = 9, ncol = 3)eda_report(data, vars = NULL, max_vars = 9, ncol = 3)
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 |
the combined plot object (invisibly, if only base graphics are
available, in which case panels are drawn directly via par(mfrow))
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.
eda_univariate(data, vars = NULL, max_vars = 12)eda_univariate(data, vars = NULL, max_vars = 12)
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 |
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
explain(x, ...)explain(x, ...)
x |
object to explain |
... |
additional arguments passed to methods |
Confusion-matrix heatmap
plot_confusion(evaluation)plot_confusion(evaluation)
evaluation |
an |
Correlation heatmap
plot_correlation(data, vars = NULL)plot_correlation(data, vars = NULL)
data |
data.frame |
vars |
optional character vector of numeric columns (default: all numeric columns) |
Feature-selection score plot
plot_feature_selection(fs, top_n = 15)plot_feature_selection(fs, top_n = 15)
fs |
an |
top_n |
how many top-scoring variables to display |
Model leaderboard comparison plot
plot_leaderboard(model_result)plot_leaderboard(model_result)
model_result |
an |
Missing-value overview plot
plot_missingness(data)plot_missingness(data)
data |
data.frame |
Regression diagnostic plots: residuals vs fitted, and a normal Q-Q plot
plot_residuals(wrapper, newdata = NULL)plot_residuals(wrapper, newdata = NULL)
wrapper |
an |
newdata |
data to evaluate on (default: the wrapper's training data) |
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.
plot_roc(wrapper, newdata = NULL, positive = NULL)plot_roc(wrapper, newdata = NULL, positive = NULL)
wrapper |
an |
newdata |
data to evaluate on (default: the wrapper's training data) |
positive |
the level treated as the positive class (default: the second factor level) |
invisibly, a list with roc (data.frame of fpr/tpr) and
auc; the plot is drawn (or, with ggplot2, returned) as a
side effect
Visualises a fitted rpart tree candidate (rpart.plot if
installed, base rpart plotting otherwise).
plot_tree(x, which = "decision_tree")plot_tree(x, which = "decision_tree")
x |
an |
which |
which candidate to plot if |
Plot an AWE analysis
## S3 method for class 'awe' plot( x, type = c("importance", "pdp", "leaderboard", "tree", "roc", "confusion", "residuals"), var = NULL, which = "decision_tree", ... )## S3 method for class 'awe' plot( x, type = c("importance", "pdp", "leaderboard", "tree", "roc", "confusion", "residuals"), var = NULL, which = "decision_tree", ... )
x |
an |
type |
one of |
var |
variable name, used when |
which |
candidate model name, used when |
... |
passed on to the underlying plot method |
Grouped bar chart comparing model leaderboards across runs
## S3 method for class 'AWECompare' plot(x, ...)## S3 method for class 'AWECompare' plot(x, ...)
x |
an |
... |
unused |
Plot an AWE explainer
## S3 method for class 'AWEExplainer' plot(x, type = c("importance", "pdp"), var = NULL, top_n = 15, ...)## S3 method for class 'AWEExplainer' plot(x, type = c("importance", "pdp"), var = NULL, top_n = 15, ...)
x |
an |
type |
|
var |
variable name, used when |
top_n |
how many variables to show when |
... |
unused |
Report generic
report(x, ...)report(x, ...)
x |
object to report on |
... |
additional arguments passed to methods |
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.
varImp(object, ...) ## S3 method for class 'AWEWrapper' varImp(object, ...) ## S3 method for class 'awe' varImp(object, ...)varImp(object, ...) ## S3 method for class 'AWEWrapper' varImp(object, ...) ## S3 method for class 'awe' varImp(object, ...)
object |
model or wrapper object |
... |
additional arguments passed to methods |
a data.frame with columns variable and importance,
sorted descending