{ "url": "http://arxiv.org/abs/2404.16899v1", "title": "mlr3summary: Concise and interpretable summaries for machine learning models", "abstract": "This work introduces a novel R package for concise, informative summaries of\nmachine learning models.\n We take inspiration from the summary function for (generalized) linear models\nin R, but extend it in several directions:\n First, our summary function is model-agnostic and provides a unified summary\noutput also for non-parametric machine learning models;\n Second, the summary output is more extensive and customizable -- it comprises\ninformation on the dataset, model performance, model complexity, model's\nestimated feature importances, feature effects, and fairness metrics;\n Third, models are evaluated based on resampling strategies for unbiased\nestimates of model performances, feature importances, etc.\n Overall, the clear, structured output should help to enhance and expedite the\nmodel selection process, making it a helpful tool for practitioners and\nresearchers alike.", "authors": "Susanne Dandl, Marc Becker, Bernd Bischl, Giuseppe Casalicchio, Ludwig Bothmann", "published": "2024-04-25", "updated": "2024-04-25", "primary_cat": "cs.LG", "cats": [ "cs.LG" ], "label": "Original Paper", "paper_cat": "LLM Fairness", "gt": "Machine learning (ML) increasingly supports decision-making processes in various domains. A data scientist has a wide range of models available, ranging from intrinsically interpretable models such as linear models to highly complex models such as random forests or gradient boosted trees. Intrinsically interpretable models can come at the expense of generalization performance, i.e., the model\u2019s capability to predict accurately on future data. Being able to interpret predictive models is either often a strict requirement for scientific inference or at least a very desirable property to audit models in other (more technical) contexts. Many methods have been proposed for interpreting black-box ML models in the field of interpretable ML (IML). For comparing (generalized) linear models (GLMs), the stats package in R offers a summary function, which only requires the model (fitted with lm or glm) as input. As an example, glm is applied to a preprocessed version of the German credit dataset (Hofmann 1994) (available in the package via data(\"credit\", package = \"mlr3summary\")): arXiv:2404.16899v1 [cs.LG] 25 Apr 2024 2 mlr3summary: Concise and interpretable summaries for machine learning models > logreg = glm(risk ~., data = credit , + family = binomial(link = \"logit\")) > summary(logreg) Call: glm(formula = risk ~., data = credit, family = binomial(link = \"logit\")) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 1.057e+00 3.646e-01 2.900 0.00373 ** age 9.103e-03 8.239e-03 1.105 0.26925 ... Residual deviance: 656.19 on 515 degrees of freedom AIC: 670.19 ... This (shortened) summary informs about the significance of variables (Pr(>|z|)), their re- spective effect size and direction (Estimate), as well as the goodness-of-fit of the model (Residual deviance and AIC). Unfortunately, many other non-parametric ML models cur- rently cannot be analyzed similarly: either targeted implementations exist for specific model classes, or an array of different model-agnostic interpretability techniques (e.g., to derive fea- ture importance) scattered across multiple packages (Molnar, Bischl, and Casalicchio 2018; Biecek 2018; Zargari Marandi 2023) must be employed. However, especially in applied data science, a user often performs model selection or model comparison across an often diverse pool of candidate models, so a standardized diagnostic output becomes highly desirable. Another issue is that in the glm-based summary, the goodness-of-fit is only evaluated on the training data, but not on hold-out/test data. While this might be appropriate for GLM- type models \u2013 provided proper model diagnosis has been performed \u2013 this is not advisable for non-parametric and non-linear models, which can overfit the training data.1 Here, hold- out test data or in general resampling techniques like cross-validation should be used for proper estimation of the generalization performance Simon (2007). Such resampling-based performance estimation should also be used for loss-based IML methods. For interpretability methods that only rely on predictions, this might also be advisable but might not lead to huge differences in results (Molnar, K\u00f6nig, Herbinger, Freiesleben, Dandl, Scholbeck, Casal- icchio, Grosse-Wentrup, and Bischl 2022; Molnar, Freiesleben, K\u00f6nig, Herbinger, Reisinger, Casalicchio, Wright, and Bischl 2023). Contributions With the mlr3summary package, we provide a novel model-agnostic summary function for ML models and learning algorithms in R. This is facilitated by building upon mlr3 (Lang, Binder, Richter, Schratz, Pfisterer, Coors, Au, Casalicchio, Kotthoff, and Bischl 2019; Bischl, Sonabend, Kotthoff, and Lang 2024) \u2013 a package ecosystem for applied ML, including resampling-based performance assessment. The summary function returns a struc- tured overview that gives information on the underlying dataset and model, generalization performances, complexity of the model, fairness metrics, and feature importances and effects. For the latter two, the function relies on model-agnostic methods from the field of IML. The 1For completeness\u2019 sake: Overfitting can happen for GLMs, e.g., in high-dimensional spaces with limited sample size. Susanne Dandl, Marc Becker, Bernd Bischl, Giuseppe Casalicchio, Ludwig Bothmann 3 output is customizable via a flexible control argument to allow adaptation to different appli- cation scenarios. The mlr3summary package is released under LGPL-3 on GitHub (https:// github.com/mlr-org/mlr3summary) and CRAN (https://cran.r-project.org/package= mlr3summary). Documentations in the form of help pages are available as well as unit tests. The example code of this manuscript is available via demo(\"credit\", package = \"mlr3summary\").", "main_content": "Most R packages that offer model summaries are restricted to parametric models and extend the stats summary method (e.g., modelsummary (Arel-Bundock 2022), broom (Robinson, Hayes, and Couch 2023)). Performance is only assessed based on training data \u2013 generalization errors are not provided. Packages that can handle diverse ML models focus primarily on performance assessment (e.g., mlr3 (Lang et al. 2019), caret (Kuhn and Max 2008)). Packages that primarily consider feature importances and effects do not provide overviews in a concise, decluttered format but provide extensive reports (e.g., modelDown (Romaszko, Tatarynowicz, Urba\u0144ski, and Biecek 2019) and modelStudio (Baniecki and Biecek 2019) based on DALEX (Biecek 2018), or explainer (Zargari Marandi 2023)). While it is possible to base the assessment on hold-out/test data, assessment based on resampling is not automatically supported by these packages. Overall, to the best of our knowledge, there is no R package yet that allows for a concise yet informative overview based on resampling-based performance assessment, model complexity, feature importance and effect directions, and fairness metrics. 3. Design, functionality, and example The core function of the mlr3summary package is the S3-based summary function for mlr3 Learner objects. It has three arguments: object reflects a trained model \u2013 a model of class Learner fitted with mlr3; resample_result reflects the results of resampling \u2013 a ResampleResult object fitted with mlr3; control reflects some control arguments \u2013 a list created with summary_control (details in Section 3.2). The mlr3 package is the basis of mlr3summary because it provides a unified interface to diverse ML models and resampling strategies. A general overview of the mlr3 ecosystem is given in Bischl et al. (Bischl et al. 2024). With mlr3, the modelling process involves the following steps: (1) initialize a regression or classification task, (2) choose a regression or classification learner, (3) train a model with the specified learner on the initialized task, (4) apply a resampling strategy. The last step is necessary to receive valid estimates for performances, importances, etc., as mentioned in Section 1. The following lines of code illustrate steps (1)-(4) on the (preprocessed) credit dataset from Section 1 using a ranger random forest. As a resampling strategy, we conduct 3-fold cross-validation. > task = TaskClassif$new(id = \"credit\", backend = credit , + target = \"risk\") > rf = lrn(\"classif.ranger\", predict_type = \"prob\") + target = \"risk\") > rf = lrn(\"classif.ranger\", predict_type = \"prob\") > rf$train(task) > cv3 = rsmp(\"cv\", folds = 3L) > rr = resample(task = task , learner = rf , resampling = cv3, 4 mlr3summary: Concise and interpretable summaries for machine learning models + store_models = TRUE) Internally, the resample function fits, in each iteration, the model on the respective training data, uses the model to predict the held-out test data, and stores the predictions in the result object. To compute performances, complexities, importances, and other metrics, the summary function iteratively accesses the models and datasets within the resulting resample object, which requires setting the parameter store_models = TRUE within the resample function. For the final summary output, the results of each iteration are aggregated (e.g., averages and standard deviations (sds)). 3.1. Summary function and output This section shows the summary call and output for the random forest of the previous credit example and provides some details on each displayed paragraph. > summary(object = rf , resample_result = rr) General provides an overview of the task, the learner (including its hyperparameters), and Susanne Dandl, Marc Becker, Bernd Bischl, Giuseppe Casalicchio, Ludwig Bothmann 5 the resampling strategy.2 Residuals display the distribution of residuals of hold-out data over the resampling iterations. For regression models, the residuals display the difference between true and predicted outcome. For classifiers that return class probabilities, the residuals are defined as the difference between predicted probabilities and a one-hot-encoding of the true class. For classifiers that return classes, a confusion matrix is shown. Performance displays averages and sds (in [ ]) of performance measures over the iterations.3 The shown performance values are the area-under-the-curve (auc), the F-score (fbeta), the binary Brier score (bbrier), and Mathew\u2019s correlation coefficient (mcc). The arrows display whether lower or higher values refer to a better performance. \u201c(macro)\u201d indicates a macro aggregation, i.e., measures are computed for each iteration separately before averaging. \u201c(micro)\u201d would indicate that measures are computed across all iterations (see Bischl et al. (2024) for details). Complexity displays averages and sds of two model complexity measures proposed by Molnar, Casalicchio, and Bischl (Molnar et al. 2020): sparsity shows the number of used features that have a non-zero effect on the prediction (evaluated by accumulated local effects (ale) (Apley and Zhu 2020)); interaction_strength shows the scaled approximation error between a main effect model (based on ale) and the prediction function.4 Importance shows the averages and sds of feature importances over the iterations. The first column (pdp) displays importances based on the sds of partial dependence curves (Friedman 2001; Greenwell, Boehmke, and McCarthy 2018), the second column (pfi.ce) shows the results for permutation feature importance Breiman (2001); Fisher, Rudin, and Dominici (2019). Effects shows average effect plots over the iterations \u2013 partial dependence plots (pdp) and ale plots (Friedman 2001; Apley and Zhu 2020). For binary classifiers, the effect plots are only shown for the positively-labeled class (here, task$positive = \"good\"). For multi-class classifiers, the effect plots are given for each outcome class separately (one vs. all). For categorical features, the bars are ordered according to the factor levels of the feature. The learner can also be a complete pipeline from mlr3pipelines (Binder, Pfisterer, Lang, Schneider, Kotthoff, and Bischl 2021), where the most common case would be an ML model with associated pre-processing steps. Then, the summary output also shows some basic information about the pipeline.5 Since preprocessing steps are treated as being part of the learner, the summary output is displayed on the original data (e.g., despite one-hot encoding of categorical features, importance results are not shown for each encoding level separately). The learner can also be an AutoTuner from mlr3tuning, where automatic processes for tuning the hyperparameters are conducted. Examples on pipelining and tuning are given in the demo of the package. 3.2. Customizations 2Currently, this is the only paragraph that is based on object, all other paragraphs are based on resample_result. 3Please note that there is no unbiased estimator of the variance, see (Nadeau and Bengio 1999) and Section 5 for a discussion. 4The interaction strength has a value in [0, 1], 0 means no interactions, 1 means no main effects but interactions. 5Linear pipelines can be displayed in the console, non-linear parts are suppressed in the output. 6 mlr3summary: Concise and interpretable summaries for machine learning models The output of the summary function can be customized via a control argument which requires a list created with the function summary_control as an input. If no control is specified, the following default setting is used: > summary_control(measures = NULL , + complexity_measures = c(\"sparsity\", \"interaction_strength\"), + importance_measures = NULL , n_important = 15L, + effect_measures = c(\"pdp\", \"ale\"), + fairness_measures = NULL , protected_attribute = NULL , + hide = NULL , digits = max(3L, getOption(\"digits\") 3L)) Performances are adaptable via measures, complexities via complexity_measures, importances via importance_measures and effects via effect_measures within summary_control. Examples are given in the demo of the package. The default for measures and importance_ measures is NULL, which results in a collection of commonly reported measures being chosen, based on the task type \u2013 for concrete measures see the help page (?summary_control). n_important reflects that, by default, only the 15 most important features are displayed in the output. This is especially handy for high-dimensional data. With hide, paragraphs of the summary output can be omitted (e.g., \"performance\") and with digits, the number of printed digits is specified. Fairness assessment for classification and regression models is also available in mlr3summary based on the mlr3fairness package (Pfisterer, Siyi, and Lang 2023). Therefore, a protected attribute must be specified. This can be done either within the task by updating the feature roles or by specifying a protected_attribute in summary_control. The following shows the code and output when specifying sex as a protected attribute. The shown default fairness measures are demographic parity (dp), conditional use accuracy equality (cuae) and equalized odds (eod), other measures are possible via fairness_measures in summary_control. > summary(object = rf , resample_result = rr , + control = summary_control(protected_attribute = \"sex\")) 4. Runtime assessment To assess how the runtime scales with differing numbers of features p \u2208{5, 10, 25, 50, 100} and numbers of observations n \u2208{50, 100, 500, 1000, 2000}, we conducted a simulation study. Given X1, X2, X3 \u223cU(0, 1), X4 \u223cBern(0.75), the data generating process is y = f(x) + \u03f5 with f(x) = 4x1 +4x2 +4x4x2 3 and \u03f5 \u223cN(0, 0.1\u00b7f(x)). As noise variables, X5 as a categorical feature with five classes, and X6, ..., Xp \u223cN(0, 1) were added to the data. We trained random forests and linear main effect models on the datasets and conducted 3-fold cross-validation. The first two figures in Figure 1 show that runtimes of the linear model were lower compared to the random forest. To improve runtimes, we added parallelization over the resampling Susanne Dandl, Marc Becker, Bernd Bischl, Giuseppe Casalicchio, Ludwig Bothmann 7 iterations (via the future package (Bengtsson 2021)) as another feature to mlr3summary \u2013 results for the random forest (with 3 cores) are on the right. Overall, scaling of runtimes is worse in p than in n. Figure 1: Runtimes of the summary function for linear models (left), and random forests without (middle) and with (right) parallelization, for differing numbers of features p and observations n. 5. Outlook and discussion In conclusion, this paper introduces a novel R package for concise model summaries. The summary output is highly adaptable due to a control argument and might be extended in the future. We also plan to offer a report function for detailed visualizations and model comparisons. To assess importance and effects of single features, mlr3summary builds upon the iml and fastshap packages. These packages only offer a limited set of interpretation methods. Recommended alternatives to permutation feature importances like conditional feature importance Molnar et al. (2022), are currently not available in a proper R package (published on CRAN). Our summary also currently lacks proper statistical tests for importances or confidence intervals for performances. This is because unbiased estimates of the variance are required which is a challenge for resampling strategies and the available methods that propose unbiased estimates are computationally infeasible (e.g., due to many model refits) (Molnar et al. 2023; Stephen Bates and Tibshirani 2023). Addressing this issue requires some concerted efforts from the research community. If methods are readily available in R, we are happy to integrate them in mlr3summary. Acknowledgments This work has been partially supported by the Federal Statistical Office of Germany." }