Skip to content

Commit 8b97f30

Browse files
committed
modelstudio v3.1.1
- closes #112 - add new tests - add IEMA citation - update readme and description
1 parent 5dd6685 commit 8b97f30

File tree

7 files changed

+115
-28
lines changed

7 files changed

+115
-28
lines changed

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: modelStudio
22
Title: Interactive Studio for Explanatory Model Analysis
3-
Version: 3.1.0.9000
3+
Version: 3.1.1
44
Authors@R:
55
c(person("Hubert", "Baniecki", role = c("aut", "cre"),
66
email = "[email protected]",
@@ -15,9 +15,9 @@ Description: Automate the explanatory analysis of machine learning predictive
1515
models and frameworks. The main function computes various (instance and
1616
model-level) explanations and produces a customisable dashboard, which
1717
consists of multiple panels for plots with their short descriptions. It is
18-
possible to easily save the dashboard and share it with others. Tools for
19-
Explanatory Model Analysis unite with tools for Exploratory Data Analysis
20-
to give a broad overview of the model behavior.
18+
possible to easily save the dashboard and share it with others. modelStudio
19+
facilitiates the process of Interactive Explanatory Model Analysis introduced
20+
in Baniecki et al. (2023) <10.1007/s10618-023-00924-w>.
2121
Depends: R (>= 3.6)
2222
License: GPL-3
2323
Encoding: UTF-8

NEWS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# modelStudio (development)
2-
* ...
1+
# modelStudio 3.1.1
2+
* added new parameter to `modelStudio()`: `open_plots = c("fi")`, which is a vector listing plots to be initially opened (and on which positions) [(#112)](https://github.com/ModelOriented/modelStudio/issues/112)
3+
* fixed future warning with `DALEX::loss_default()` since `DALEX >=2.5.0`
34

45
# modelStudio 3.1.0
56
* changed y-axis variable labels in `SV` to the same as in `BD`

R/modelStudio.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#' @param B Number of permutation rounds used for calculation of SV. Default is \code{10}.
4343
#' See \href{https://modelstudio.drwhy.ai/articles/ms-perks-features.html#more-calculations-means-more-time}{\bold{vignette}}
4444
#' @param B_fi Number of permutation rounds used for calculation of FI. Default is \code{B}.
45+
#' @param open_plots A vector listing plots to be initially opened (and on which positions). Default is \code{c("fi")}.
4546
#' @param eda Compute EDA plots and Residuals vs Feature plot, which adds the data to the dashboard. Default is \code{TRUE}.
4647
#' @param show_info Verbose a progress on the console. Default is \code{TRUE}.
4748
#' @param verbose An alias for \code{show_info}. If provided, it will override the value.
@@ -186,6 +187,7 @@ modelStudio.explainer <- function(explainer,
186187
B = 10,
187188
B_fi = B,
188189
eda = TRUE,
190+
open_plots = c("fi"),
189191
show_info = TRUE,
190192
parallel = FALSE,
191193
options = ms_options(),
@@ -213,6 +215,14 @@ modelStudio.explainer <- function(explainer,
213215
if (is.null(max_features_fi)) max_features_fi <- max_features
214216
if (!is.null(verbose)) show_info <- verbose
215217
if (is.null(N)) stop("`N` argument must be an integer")
218+
if (length(open_plots) > prod(facet_dim))
219+
stop(paste0("`open_plots` is of length larger than defined by `facet_dim` dimensions.",
220+
"Increase `facet_dim` or shorten `open_plots`."))
221+
available_plots <- c('bd', 'sv', 'cp', 'fi', 'pd', 'ad', 'rv', 'fd', 'tv', 'at')
222+
if (!all(open_plots %in% c(available_plots, toupper(available_plots))))
223+
stop(paste0("`open_plots` must be a vector with the following values: 'bd',",
224+
" 'sv', 'cp', 'fi', 'pd', 'ad', 'rv', 'fd', 'tv', 'at'."))
225+
open_plots <- toupper(open_plots)
216226
#if (identical(N_fi, numeric(0))) N_fi <- NULL
217227

218228
if (is.null(new_observation)) {
@@ -250,7 +260,11 @@ modelStudio.explainer <- function(explainer,
250260
loss_function <- DALEX::loss_root_mean_square
251261
}
252262
} else {
253-
loss_function <- DALEX::loss_default(explainer$model_info$type)
263+
if (package_version(packageVersion("DALEX")) < package_version("2.5.0")) {
264+
loss_function <- DALEX::loss_default(explainer$model_info$type)
265+
} else {
266+
loss_function <- DALEX::get_loss_default(explainer$model_info$type)
267+
}
254268
}
255269

256270
variable_splits_type <- ifelse('variable_splits_type' %in% kwargs_names,
@@ -504,6 +518,7 @@ modelStudio.explainer <- function(explainer,
504518
version_text = version_text,
505519
measure_text = measure_text,
506520
drop_down_data = jsonlite::toJSON(drop_down_data),
521+
open_plots = as.list(open_plots),
507522
eda = eda,
508523
widget_id = widget_id,
509524
is_target_binary = is_binary(y)

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
The `modelStudio` package **automates the explanatory analysis of machine learning predictive models**. It generates advanced interactive model explanations in the form of a **serverless HTML site** with only one line of code. This tool is model-agnostic, therefore compatible with most of the black-box predictive models and frameworks (e.g.&nbsp;`mlr/mlr3`, `xgboost`, `caret`, `h2o`, `parsnip`, `tidymodels`, `scikit-learn`, `lightgbm`, `keras/tensorflow`).
1616

17-
The main `modelStudio()` function computes various (instance and model-level) explanations and produces a&nbsp;**customisable dashboard**, which consists of multiple panels for plots with their short descriptions. It is possible to easily **save** the dashboard and&nbsp;**share** it with others. Tools for [Explanatory Model Analysis](https://ema.drwhy.ai/) unite with tools for Exploratory Data Analysis to give a broad overview of the model behavior.
17+
The main `modelStudio()` function computes various (instance and model-level) explanations and produces a&nbsp;**customisable dashboard**, which consists of multiple panels for plots with their short descriptions. It is possible to easily **save** the dashboard and&nbsp;**share** it with others. Tools for [Explanatory Model Analysis](https://ema.drwhy.ai) unite with tools for Exploratory Data Analysis to give a broad overview of the model behavior.
1818

1919
<p align="center"><b>
2020
<a href="https://rai-covid.drwhy.ai">explain COVID-19<a> &emsp;
@@ -316,28 +316,39 @@ or with [`r2d3::save_d3_html()`](https://rstudio.github.io/r2d3/articles/publish
316316
<img src="man/figures/controls.png">
317317
</p>
318318

319-
## Citation
319+
## Citations
320320

321321
If you use `modelStudio`, please cite our [JOSS article](https://joss.theoj.org/papers/10.21105/joss.01798):
322322

323323
```
324-
@article{modelStudio,
325-
author = {Hubert Baniecki and Przemyslaw Biecek},
326-
title = {{modelStudio: Interactive Studio with Explanations for ML Predictive Models}},
327-
year = {2019},
324+
@article{baniecki2019modelstudio,
325+
title = {{modelStudio: Interactive Studio with Explanations for ML Predictive Models}},
326+
author = {Hubert Baniecki and Przemyslaw Biecek},
328327
journal = {Journal of Open Source Software},
329-
volume = {4},
330-
number = {43},
331-
pages = {1798},
332-
url = {https://doi.org/10.21105/joss.01798}
328+
year = {2019},
329+
volume = {4},
330+
number = {43},
331+
pages = {1798},
332+
url = {https://doi.org/10.21105/joss.01798}
333333
}
334334
```
335335

336-
## More resources
336+
For a description of the Interactive EMA process, refer to our [DMKD article](https://doi.org/10.1007/s10618-023-00924-w):
337+
338+
```
339+
@article{baniecki2023grammar,
340+
title = {The grammar of interactive explanatory model analysis},
341+
author = {Hubert Baniecki and Dariusz Parzych and Przemyslaw Biecek},
342+
journal = {Data Mining and Knowledge Discovery},
343+
year = {2023},
344+
pages = {1--37},
345+
url = {https://doi.org/10.1007/s10618-023-00924-w}
346+
}
347+
```
337348

338-
- A preprint: [The Grammar of Interactive Explanatory Model Analysis](https://arxiv.org/abs/2005.00497v4)
349+
## More resources
339350

340-
- Theoretical introduction to the plots: [Explanatory Model Analysis: Explore, Explain, and Examine Predictive Models](https://ema.drwhy.ai/)
351+
- Theoretical introduction to the plots: [Explanatory Model Analysis: Explore, Explain, and Examine Predictive Models](https://ema.drwhy.ai)
341352

342353
- Vignettes: [perks and features](https://modelstudio.drwhy.ai/articles/ms-perks-features.html), [R & Python examples](https://modelstudio.drwhy.ai/articles/ms-r-python-examples.html), [modelStudio in R Markdown HTML](https://modelstudio.drwhy.ai/articles/ms-rmarkdown.html)
343354

@@ -348,4 +359,4 @@ If you use `modelStudio`, please cite our [JOSS article](https://joss.theoj.org/
348359

349360
## Acknowledgments
350361

351-
Work on this package was financially supported by the `NCN Opus grant 2016/21/B/ST6/02176` and `NCBR grant POIR.01.01.01-00-0328/17`.
362+
Work on this package was financially supported by the National Science Centre (Poland) grant `2016/21/B/ST6/02176` and National Centre for Research and Development grant `POIR.01.01.01-00-0328/17`.

inst/d3js/modelStudio.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var TIME = options.time,
2626
versionText = options.version_text,
2727
measureText = options.measure_text,
2828
dropDownData = options.drop_down_data,
29+
openPlots= options.open_plots,
2930
EDA = options.eda,
3031
WIDGET_ID = options.widget_id,
3132
IS_TARGET_BINARY = options.is_target_binary,
@@ -502,14 +503,15 @@ function initializeStudio() {
502503
IS_BUTTON_CLICKED = false;
503504
});
504505
}
505-
506-
if (facetData.length >= 1) {
507-
svg.selectAll('.enterChoiceButton').filter('#enterChoiceButton0').dispatch('click');
508-
svg.select("#chosePlotButton0").select("#FI").dispatch('click');
506+
507+
for (let i = 0; i < openPlots.length; i++) {
508+
if (facetData.length > i) {
509+
svg.selectAll(".enterChoiceButton").filter("#enterChoiceButton"+i).dispatch('click');
510+
svg.select("#chosePlotButton"+i).select("#"+openPlots[i]).dispatch('click');
511+
}
509512
}
510-
511-
if (facetData.length >= 2) {
512-
svg.selectAll('.enterChoiceButton').filter('#enterChoiceButton1').dispatch('click');
513+
if (facetData.length > openPlots.length) {
514+
svg.selectAll(".enterChoiceButton").filter("#enterChoiceButton"+openPlots.length).dispatch('click');
513515
}
514516
}
515517

man/modelStudio.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_3_1.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
context("Test v3.1.1")
2+
3+
set.seed(1313)
4+
v <- FALSE
5+
6+
model <- glm(survived ~., data = DALEX::titanic_imputed, family = "binomial")
7+
8+
explainer <- DALEX::explain(model,
9+
data = DALEX::titanic_imputed,
10+
y = DALEX::titanic_imputed$survived,
11+
verbose = v)
12+
13+
testthat::test_that("max_features_fi, **_axis_title", {
14+
ms <- testthat::expect_silent(
15+
modelStudio::modelStudio(explainer,
16+
B = 2,
17+
max_features_fi = 2,
18+
max_features = 2,
19+
options = ms_options(cp_axis_title = "pred",
20+
bd_axis_title = "attribution"),
21+
verbose = v)
22+
)
23+
testthat::expect_is(ms, "r2d3")
24+
})
25+
26+
testthat::test_that("open_plots", {
27+
ms <- testthat::expect_silent(
28+
modelStudio::modelStudio(explainer,
29+
B = 2,
30+
open_plots = c("fi", "bd", "rv"),
31+
verbose = v)
32+
)
33+
testthat::expect_is(ms, "r2d3")
34+
35+
testthat::expect_error(
36+
modelStudio::modelStudio(explainer,
37+
B = 2,
38+
open_plots = c("bd", "test"),
39+
verbose = v)
40+
)
41+
testthat::expect_error(
42+
modelStudio::modelStudio(explainer,
43+
B = 2,
44+
facet_dim = c(2, 1),
45+
open_plots = c("pd", "ad", "cp"),
46+
verbose = v)
47+
)
48+
testthat::expect_silent(
49+
modelStudio::modelStudio(explainer,
50+
B = 2,
51+
facet_dim = c(2, 1),
52+
open_plots = c("SV", "FI"),
53+
verbose = v)
54+
)
55+
})

0 commit comments

Comments
 (0)