Skip to content

Commit

Permalink
Remove #250 content
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymiuks committed Aug 29, 2020
1 parent abdf066 commit 7964d79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 37 deletions.
5 changes: 0 additions & 5 deletions R/explain.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' This will happen also if \code{verbose} is TRUE. Set both \code{verbose} and \code{precalculate} to FALSE to omit calculations.
#' @param colorize logical. If TRUE (default) then \code{WARNINGS}, \code{ERRORS} and \code{NOTES} are colorized. Will work only in the R console.
#' @param model_info a named list (\code{package}, \code{version}, \code{type}) containg information about model. If \code{NULL}, \code{DALEX} will seek for information on it's own.
#' @param positive_class a character indicating by name which class should be treated as positive for binary classification (ie. which class should be associated with 1 value). Keep in mind that some models assumes positive class on its own. Then parameter will not work.
#' @param type type of a model, either \code{classification} or \code{regression}. If not specified then \code{type} will be extracted from \code{model_info}.
#'
#' @return An object of the class \code{explainer}.
Expand Down Expand Up @@ -146,10 +145,6 @@ explain.default <- function(model, data = NULL, y = NULL, predict_function = NUL
verbose_cat(" -> model label : ", label, "\n", verbose = verbose)
}

if (!is.null(positive_class)) {
attr(model, "positive_class") <- positive_class
}

# REPORT: checks for data
if (is.null(data)) {
possible_data <- try(model.frame(model), silent = TRUE)
Expand Down
39 changes: 9 additions & 30 deletions R/misc_yhat.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ yhat.randomForest <- function(X.model, newdata, ...) {
# if result is a vector then ncol parameter is null
if (is.null(ncol(pred))) return(pred)
# binary classification
if (ncol(pred) == 2) {
if (!is.null(attr(X.model, "positive_class"))){
return(unlist(pred[, attr(X.model, "positive_class")], use.names = FALSE))
} else {
return(pred[,2])
}
}
if (ncol(pred) == 2) return(pred[,2])

} else {
pred <- predict(X.model, newdata, ...)
}
Expand All @@ -65,19 +60,14 @@ yhat.svm <- function(X.model, newdata, ...) {
if (X.model$type == 0) {
pred <- attr(predict(X.model, newdata = newdata, probability = TRUE), "probabilities")
if (ncol(pred) == 2) { # binary classification
if (!is.null(attr(X.model, "positive_class"))) {
pred <- pred[,attr(X.model, "positive_class")]
} else {
pred <- pred[,2]
}
pred <- pred[,2]
}
} else {
pred <- predict(X.model, newdata, ...)
}
pred
}


#' @rdname yhat
#' @export
yhat.gbm <- function(X.model, newdata, ...) {
Expand Down Expand Up @@ -133,7 +123,7 @@ yhat.glmnet <- function(X.model, newdata, ...) {
if(length(dim(pred)) > 2){
return(pred[,,1])
}
# For binary classifiaction matrix with one column is returned
# For binary classifiaction matrix with one column is returned
if (ncol(pred) == 1) {
return(as.numeric(pred))
}
Expand All @@ -159,13 +149,7 @@ yhat.ranger <- function(X.model, newdata, ...) {
# if result is a vector then ncol parameter is null
if (is.null(ncol(pred))) return(pred)
# binary classification
if (ncol(pred) == 2 & is.null(attr(X.model, "positive_class"))) {
return(pred[, 2])
} else if (ncol(pred) == 2 & !is.null(attr(X.model, "positive_class"))) {
# If model was fitted with numerical 0 and 1 values matrix will not have colnames. We have to add them
if (is.null(colnames(pred))) colnames(pred) <- 0:(ncol(pred)-1)
return(pred[, attr(X.model, "positive_class")])
}
if (ncol(pred) == 2) return(pred[,2])
}
pred
}
Expand All @@ -176,10 +160,8 @@ yhat.model_fit <- function(X.model, newdata, ...) {
if (X.model$spec$mode == "classification") {
response <- as.matrix(predict(X.model, newdata, type = "prob"))
colnames(response) <- X.model$lvl
if (ncol(response) == 2 & is.null(attr(X.model, "positive_class"))) {
if (ncol(response) == 2) {
response <- response[,2]
} else if (ncol(response) == 2 & !is.null(attr(X.model, "positive_class"))) {
response <- response[,attr(X.model, "positive_class")]
}
}
if (X.model$spec$mode == "regression") {
Expand All @@ -194,10 +176,8 @@ yhat.model_fit <- function(X.model, newdata, ...) {
yhat.train <- function(X.model, newdata, ...) {
if (X.model$modelType == "Classification") {
response <- predict(X.model, newdata = newdata, type = "prob")
if (ncol(response) == 2 & is.null(attr(X.model, "positive_class"))) {
if (ncol(response) == 2) {
response <- response[,2]
} else if (ncol(response) == 2 & !is.null(attr(X.model, "positive_class"))) {
response <- response[,attr(X.model, "positive_class")]
}
}
if (X.model$modelType == "Regression") {
Expand All @@ -222,10 +202,8 @@ yhat.lrm <- function(X.model, newdata, ...) {
yhat.rpart <- function(X.model, newdata, ...) {
response <- predict(X.model, newdata = newdata)
if (!is.null(dim(response))) {
if (ncol(response) == 2 & is.null(attr(X.model, "positive_class"))) {
if (ncol(response) == 2) {
response <- response[,2]
} else if (ncol(response) == 2 & !is.null(attr(X.model, "positive_class"))) {
response <- response[,attr(X.model, "positive_class")]
}
}
response
Expand Down Expand Up @@ -261,3 +239,4 @@ yhat.default <- function(X.model, newdata, ...) {
# newdata_pool <- catboost::catboost.load_pool(newdata)
# catboost::catboost.predict(X.model, newdata_pool)
# }

2 changes: 0 additions & 2 deletions man/explain.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7964d79

Please sign in to comment.