Print principal components after using pca on fairness object
# S3 method for fairness_pca
print(x, ...)
x |
|
---|---|
... | other print parameters |
data("german")
y_numeric <- as.numeric(german$Risk) - 1
lm_model <- glm(Risk ~ .,
data = german,
family = binomial(link = "logit")
)
rf_model <- ranger::ranger(Risk ~ .,
data = german,
probability = TRUE,
num.trees = 200,
num.threads = 1
)
explainer_lm <- DALEX::explain(lm_model, data = german[, -1], y = y_numeric)
#> Preparation of a new explainer is initiated
#> -> model label : lm ( default )
#> -> data : 1000 rows 9 cols
#> -> target variable : 1000 values
#> -> predict function : yhat.glm will be used ( default )
#> -> predicted values : No value for predict function target column. ( default )
#> -> model_info : package stats , ver. 4.1.1 , task classification ( default )
#> -> predicted values : numerical, min = 0.1369187 , mean = 0.7 , max = 0.9832426
#> -> residual function : difference between y and yhat ( default )
#> -> residuals : numerical, min = -0.9572803 , mean = 1.940006e-17 , max = 0.8283475
#> A new explainer has been created!
explainer_rf <- DALEX::explain(rf_model, data = german[, -1], y = y_numeric)
#> Preparation of a new explainer is initiated
#> -> model label : ranger ( default )
#> -> data : 1000 rows 9 cols
#> -> target variable : 1000 values
#> -> predict function : yhat.ranger will be used ( default )
#> -> predicted values : No value for predict function target column. ( default )
#> -> model_info : package ranger , ver. 0.13.1 , task classification ( default )
#> -> predicted values : numerical, min = 0.07168254 , mean = 0.6978111 , max = 0.9984286
#> -> residual function : difference between y and yhat ( default )
#> -> residuals : numerical, min = -0.7164325 , mean = 0.002188894 , max = 0.6471445
#> A new explainer has been created!
fobject <- fairness_check(explainer_lm, explainer_rf,
protected = german$Sex,
privileged = "male"
)
#> Creating fairness classification object
#> -> Privileged subgroup : character ( Ok )
#> -> Protected variable : factor ( Ok )
#> -> Cutoff values for explainers : 0.5 ( for all subgroups )
#> -> Fairness objects : 0 objects
#> -> Checking explainers : 2 in total ( compatible )
#> -> Metric calculation : 10/13 metrics calculated for all models ( 3 NA created )
#> Fairness object created succesfully
# same explainers with different cutoffs for female
fobject <- fairness_check(explainer_lm, explainer_rf, fobject,
protected = german$Sex,
privileged = "male",
cutoff = list(female = 0.4),
label = c("lm_2", "rf_2")
)
#> Creating fairness classification object
#> -> Privileged subgroup : character ( Ok )
#> -> Protected variable : factor ( Ok )
#> -> Cutoff values for explainers : female: 0.4, male: 0.5
#> -> Fairness objects : 1 object ( compatible )
#> -> Checking explainers : 4 in total ( compatible )
#> -> Metric calculation : 10/13 metrics calculated for all models ( 3 NA created )
#> Fairness object created succesfully
fpca <- fairness_pca(fobject)
#> Warning: Found metric with NA: FNR, FOR, NEW_METRIC, omiting it
print(fpca)
#> Fairness PCA :
#> PC1 PC2 PC3 PC4
#> [1,] -2.8164818 1.008126 0.5950553 -5.828671e-16
#> [2,] -0.9287005 -1.064519 -1.1119402 1.193490e-15
#> [3,] 2.2694809 2.226724 -0.1505011 9.714451e-16
#> [4,] 1.4757015 -2.170330 0.6673859 -9.436896e-16
#>
#> Created with:
#> [1] "lm_2" "rf_2" "lm" "ranger"
#>
#> First two components explained 93 % of variance.