Showing 2 of 6 files from the diff.

@@ -53,32 +53,38 @@
Loading
53 53
predict_diagnostics <-  function(explainer, new_observation, variables = NULL, ..., nbins = 20, neighbors = 50, distance = gower::gower_dist) {
54 54
  test_explainer(explainer, has_data = TRUE, function_name = "predict_diagnostics")
55 55
56 -
  neighbours_id <- select_neighbours_id(new_observation, explainer$data, n = neighbors, distance = distance)
56 +
57 +
  if (nrow(explainer$data) <= neighbors) {
58 +
    warning("Value of neighbors has to be lower than number of rows in explainer$data. Setting neighbors to nrow(explainer$data)")
59 +
    neighbors <- nrow(explainer$data) - 1
60 +
  }
61 +
62 +
  neighbors_id <- select_neighbors_id(new_observation, explainer$data, n = neighbors, distance = distance)
57 63
58 64
59 65
  # if variables = NULL then histograms with distribution of residuals are compared against each other
60 66
  if (is.null(variables)) {
61 67
    residuals_all <- explainer$residual_function(explainer$model, explainer$data, explainer$y, explainer$predict_function)
62 -
    residuals_sel <- residuals_all[neighbours_id]
63 -
    residuals_other <- residuals_all[-neighbours_id]
68 +
    residuals_sel <- residuals_all[neighbors_id]
69 +
    residuals_other <- residuals_all[-neighbors_id]
64 70
65 71
    cut_points <- signif(pretty(residuals_other, nbins), 3)
66 72
    test.res <- ks.test(residuals_other, residuals_sel)
67 73
68 -
    df1 <- data.frame(as.data.frame(table(cut(residuals_sel, cut_points))/length(residuals_sel)), direction = "neighbours")
74 +
    df1 <- data.frame(as.data.frame(table(cut(residuals_sel, cut_points))/length(residuals_sel)), direction = "neighbors")
69 75
    df2 <- data.frame(as.data.frame(-table(cut(residuals_other, cut_points))/length(residuals_other)), direction = "all")
70 76
71 77
    res <- list(variables = variables,
72 -
                histogram_neighbours = df1,
78 +
                histogram_neighbors = df1,
73 79
                histogram_all = df2,
74 80
                test = test.res,
75 81
                cut_points = cut_points,
76 -
                neighbours_id = neighbours_id)
82 +
                neighbors_id = neighbors_id)
77 83
  } else {
78 84
    # if variables is not null then we need to plot either categorical or continouse fidelity plot
79 85
    cp_neighbors <- ingredients::ceteris_paribus(explainer,
80 -
                                                 new_observation = explainer$data[neighbours_id, ],
81 -
                                                 y = explainer$y[neighbours_id],
86 +
                                                 new_observation = explainer$data[neighbors_id, ],
87 +
                                                 y = explainer$y[neighbors_id],
82 88
                                                 variables = variables,
83 89
                                                 ...)
84 90
    cp_new_instance <- ingredients::ceteris_paribus(explainer,
@@ -88,7 +94,7 @@
Loading
88 94
    res <- list(variables = variables,
89 95
                cp_neighbors = cp_neighbors,
90 96
                cp_new_instance = cp_new_instance,
91 -
                neighbours_id = neighbours_id)
97 +
                neighbors_id = neighbors_id)
92 98
  }
93 99
  class(res) <- "predict_diagnostics"
94 100
  res
@@ -99,7 +105,7 @@
Loading
99 105
individual_diagnostics <- predict_diagnostics
100 106
101 107
102 -
select_neighbours_id <- function(observation, data, variables = NULL, distance = gower::gower_dist, n = 50, frac = NULL) {
108 +
select_neighbors_id <- function(observation, data, variables = NULL, distance = gower::gower_dist, n = 50, frac = NULL) {
103 109
  if (is.null(variables)) {
104 110
    variables <- intersect(colnames(observation),
105 111
                           colnames(data))

@@ -34,7 +34,7 @@
Loading
34 34
plot.predict_diagnostics <- function(x, ...) {
35 35
  # if variables are not specified then gow with histogram
36 36
  if (is.null(x$variables)) {
37 -
    df <- rbind(x$histogram_neighbours, x$histogram_all)
37 +
    df <- rbind(x$histogram_neighbors, x$histogram_all)
38 38
    p.value <- x$test$p.value
39 39
    statistic <- x$test$statistic
40 40
    cut_points <- x$cut_points
Files Coverage
R 87.07%
Project Totals (31 files) 87.07%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading