Oscillations are proxies for local feature importance at the instance level. Find more detailes in Ceteris Paribus Oscillations Chapter.

calculate_oscillations(x, sort = TRUE, ...)

Arguments

x

a ceteris_paribus explainer produced with the ceteris_paribus() function

sort

a logical value. If TRUE then rows are sorted along the oscillations

...

other arguments

Value

an object of the class ceteris_paribus_oscillations

References

Predictive Models: Visual Exploration, Explanation and Debugging https://pbiecek.github.io/PM_VEE

Examples

library("DALEX") # smaller data, quicker example titanic_small <- select_sample(titanic_imputed, n = 500, seed = 1313) # build a model model_titanic_glm <- glm(survived ~ gender + age + fare, data = titanic_small, family = "binomial") explain_titanic_glm <- explain(model_titanic_glm, data = titanic_small[,-8], y = titanic_small[,8])
#> Preparation of a new explainer is initiated #> -> model label : lm ( default ) #> -> data : 500 rows 7 cols #> -> target variable : 500 values #> -> predict function : yhat.glm will be used ( default ) #> -> predicted values : numerical, min = 0.0795294 , mean = 0.302 , max = 0.9859411 #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -0.8204691 , mean = 8.796651e-12 , max = 0.8567173 #> -> model_info : package stats , ver. 3.6.1 , task regression ( default ) #> A new explainer has been created!
cp_rf <- ceteris_paribus(explain_titanic_glm, titanic_small[1,]) calculate_oscillations(cp_rf)
#> _vname_ _ids_ oscillations #> 1 gender 515 0.20738245 #> 2 age 515 0.05371374 #> 5 fare 515 0.04197095 #> 3 class 515 0.00000000 #> 4 embarked 515 0.00000000 #> 6 sibsp 515 0.00000000 #> 7 parch 515 0.00000000
# \donttest{ library("randomForest") apartments_rf_model <- randomForest(m2.price ~ construction.year + surface + floor + no.rooms + district, data = apartments) explainer_rf <- explain(apartments_rf_model, data = apartments_test[,-1], y = apartments_test$m2.price)
#> Preparation of a new explainer is initiated #> -> model label : randomForest ( default ) #> -> data : 9000 rows 5 cols #> -> target variable : 9000 values #> -> predict function : yhat.randomForest will be used ( default ) #> -> predicted values : numerical, min = 1979.109 , mean = 3507.828 , max = 5832.287 #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -736.7624 , mean = 3.695662 , max = 1247.71 #> -> model_info : package randomForest , ver. 4.6.14 , task regression ( default ) #> A new explainer has been created!
apartment <- apartments_test[1,] cp_rf <- ceteris_paribus(explainer_rf, apartment) calculate_oscillations(cp_rf)
#> _vname_ _ids_ oscillations #> 5 district 1001 1146.23567 #> 2 surface 1001 274.15654 #> 3 floor 1001 228.76663 #> 4 no.rooms 1001 172.02984 #> 1 construction.year 1001 57.86286
# }