diff --git a/R/modelStudio.R b/R/modelStudio.R index 699e260..af8e3fe 100644 --- a/R/modelStudio.R +++ b/R/modelStudio.R @@ -77,8 +77,7 @@ #' #' # make a studio for the model #' modelStudio(explainer_titanic, -#' new_observations, -#' N = 200, B = 5) # faster example +#' new_observations) #' #' \donttest{ #' diff --git a/R/ms_update_observations.R b/R/ms_update_observations.R index 135d6a7..4b5f9d6 100644 --- a/R/ms_update_observations.R +++ b/R/ms_update_observations.R @@ -41,31 +41,34 @@ #' library("modelStudio") #' #' # fit a model -#' model_apartments <- glm(m2.price ~. , data = apartments) +#' model_titanic <- glm(survived ~., data = titanic_imputed, family = "binomial") #' #' # create an explainer for the model -#' explainer_apartments <- explain(model_apartments, -#' data = apartments, -#' y = apartments$m2.price) +#' explainer_titanic <- explain(model_titanic, +#' data = titanic_imputed, +#' y = titanic_imputed$survived) #' #' # make a studio for the model -#' ms <- modelStudio(explainer_apartments) -#' ms +#' ms <- modelStudio(explainer_titanic) #' #' # add new observations #' ms <- ms_update_observations(ms, -#' explainer_apartments, -#' new_observation = apartments[100:101,], -#' new_observation_y = apartments$m2.price[100:101]) +#' explainer_titanic, +#' new_observation = titanic_imputed[100:101,], +#' new_observation_y = titanic_imputed$survived[100:101]) #' ms #' +#' \donttest{ +#' #' # overwrite the observations with new ones #' ms <- ms_update_observations(ms, -#' explainer_apartments, -#' new_observation = apartments[100:101,], +#' explainer_titanic, +#' new_observation = titanic_imputed[100:101,], #' overwrite = TRUE) #' ms #' +#' } +#' #' @export #' @rdname ms_update_observations ms_update_observations <- function(object, diff --git a/R/ms_update_options.R b/R/ms_update_options.R index cdab8e7..b1ed989 100644 --- a/R/ms_update_options.R +++ b/R/ms_update_options.R @@ -30,16 +30,15 @@ #' library("modelStudio") #' #' # fit a model -#' model_apartments <- glm(m2.price ~. , data = apartments) +#' model_titanic <- glm(survived ~., data = titanic_imputed, family = "binomial") #' #' # create an explainer for the model -#' explainer_apartments <- explain(model_apartments, -#' data = apartments, -#' y = apartments$m2.price) +#' explainer_titanic <- explain(model_titanic, +#' data = titanic_imputed, +#' y = titanic_imputed$survived) #' #' # make a studio for the model -#' ms <- modelStudio(explainer_apartments) -#' ms +#' ms <- modelStudio(explainer_titanic) #' #' # update the options #' new_ms <- ms_update_options(ms, diff --git a/man/modelStudio.Rd b/man/modelStudio.Rd index 18aa326..83d939a 100644 --- a/man/modelStudio.Rd +++ b/man/modelStudio.Rd @@ -80,7 +80,7 @@ Theoretical introduction to the plots: library("DALEX") library("modelStudio") -#:# ex1 classification on 'titanic_imputed' dataset +#:# ex1 classification on 'titanic' data # fit a model model_titanic <- glm(survived ~., data = titanic_imputed, family = "binomial") @@ -97,12 +97,11 @@ rownames(new_observations) <- c("Lucas","James") # make a studio for the model modelStudio(explainer_titanic, - new_observations, - N = 200, B = 5) # faster example + new_observations) \donttest{ -#:# ex2 regression on 'apartments' dataset +#:# ex2 regression on 'apartments' data library("ranger") model_apartments <- ranger(m2.price ~. ,data = apartments) @@ -133,13 +132,11 @@ modelStudio(explainer_apartments, #:# ex3 xgboost model on 'HR' dataset library("xgboost") -# fit a model HR_matrix <- model.matrix(status == "fired" ~ . -1, HR) +# fit a model xgb_matrix <- xgb.DMatrix(HR_matrix, label = HR$status == "fired") - -params <- list(max_depth = 7, objective = "binary:logistic", eval_metric = "auc") - +params <- list(max_depth = 3, objective = "binary:logistic", eval_metric = "auc") model_HR <- xgb.train(params, xgb_matrix, nrounds = 300) # create an explainer for the model diff --git a/man/ms_update_observations.Rd b/man/ms_update_observations.Rd index dd95904..521e1d1 100644 --- a/man/ms_update_observations.Rd +++ b/man/ms_update_observations.Rd @@ -56,28 +56,27 @@ library("DALEX") library("modelStudio") # fit a model -model_apartments <- glm(m2.price ~. , data = apartments) +model_titanic <- glm(survived ~., data = titanic_imputed, family = "binomial") # create an explainer for the model -explainer_apartments <- explain(model_apartments, - data = apartments, - y = apartments$m2.price) +explainer_titanic <- explain(model_titanic, + data = titanic_imputed, + y = titanic_imputed$survived) # make a studio for the model -ms <- modelStudio(explainer_apartments) -ms +ms <- modelStudio(explainer_titanic) # add new observations ms <- ms_update_observations(ms, - explainer_apartments, - new_observation = apartments[100:101,], - new_observation_y = apartments$m2.price[100:101]) + explainer_titanic, + new_observation = titanic_imputed[100:101,], + new_observation_y = titanic_imputed$survived[100:101]) ms # overwrite the observations with new ones ms <- ms_update_observations(ms, - explainer_apartments, - new_observation = apartments[100:101,], + explainer_titanic, + new_observation = titanic_imputed[100:101,], overwrite = TRUE) ms diff --git a/man/ms_update_options.Rd b/man/ms_update_options.Rd index e2a12a5..b4b4995 100644 --- a/man/ms_update_options.Rd +++ b/man/ms_update_options.Rd @@ -62,16 +62,15 @@ library("DALEX") library("modelStudio") # fit a model -model_apartments <- glm(m2.price ~. , data = apartments) +model_titanic <- glm(survived ~., data = titanic_imputed, family = "binomial") # create an explainer for the model -explainer_apartments <- explain(model_apartments, - data = apartments, - y = apartments$m2.price) +explainer_titanic <- explain(model_titanic, + data = titanic_imputed, + y = titanic_imputed$survived) # make a studio for the model -ms <- modelStudio(explainer_apartments) -ms +ms <- modelStudio(explainer_titanic) # update the options new_ms <- ms_update_options(ms,