|
564 | 564 | act.fct = jaspResults[["actfct"]]$object, |
565 | 565 | linear.output = FALSE |
566 | 566 | ) |
567 | | - predictions <- as.factor(max.col(predict(fit, newdata = grid))) |
568 | | - levels(predictions) <- unique(dataset[, options[["target"]]]) |
| 567 | + probabilities <- predict(fit, newdata = grid) |
| 568 | + predictions <- levels(dataset[, options[["target"]]])[apply(probabilities, 1, which.max)] |
569 | 569 | } else if (type == "rpart") { |
570 | 570 | classificationResult <- jaspResults[["classificationResult"]]$object |
571 | 571 | fit <- rpart::rpart(formula, data = dataset, method = "class", control = rpart::rpart.control(minsplit = options[["minObservationsForSplit"]], minbucket = options[["minObservationsInNode"]], maxdepth = options[["interactionDepth"]], cp = classificationResult[["penalty"]])) |
572 | | - predictions <- as.factor(max.col(predict(fit, newdata = grid))) |
573 | | - levels(predictions) <- unique(dataset[, options[["target"]]]) |
| 572 | + probabilities <- predict(fit, newdata = grid) |
| 573 | + predictions <- colnames(probabilities)[apply(probabilities, 1, which.max)] |
574 | 574 | } else if (type == "svm") { |
575 | 575 | classificationResult <- jaspResults[["classificationResult"]]$object |
576 | 576 | fit <- e1071::svm(formula, |
|
580 | 580 | predictions <- predict(fit, newdata = grid) |
581 | 581 | } else if (type == "naivebayes") { |
582 | 582 | fit <- e1071::naiveBayes(formula, data = dataset, laplace = options[["smoothingParameter"]]) |
583 | | - predictions <- as.factor(max.col(predict(fit, newdata = grid, type = "raw"))) |
584 | | - levels(predictions) <- unique(dataset[, options[["target"]]]) |
| 583 | + probabilities <- predict(fit, newdata = grid, type = "raw") |
| 584 | + predictions <- colnames(probabilities)[apply(probabilities, 1, which.max)] |
585 | 585 | } else if (type == "logistic") { |
586 | 586 | if (classificationResult[["family"]] == "binomial") { |
587 | 587 | fit <- stats::glm(formula, data = dataset, family = stats::binomial(link = options[["link"]])) |
|
0 commit comments