Reputation: 13
I want to use partial least squares discriminant analysis (PLS-DA) to solve a classification problem where there are multiple classes to be predicted. I know PLS-DA is not limited to the two class problem, and I believe that using plsda from the Caret package can handle this ok, but when I try to build a PLS-DA model in the mlr package, I get an error telling me my task is a "multiclass-problem, but learner 'classif.plsdaCaret' does not support that!"
Is it possible to build a multiclass PLS-DA model using mlr and am I simply using the wrong learner? Here is a reproducible example:
# LOAD PACKAGES ----
#install.packages("BiocManager")
#BiocManager::install("mixOmics")
library(mlr)
library(tidyverse)
library(mixOmics)
# LOAD IN DATA ----
data(liver.toxicity)
liverTib <- as.tibble(cbind(liver.toxicity$treatment$Treatment.Group,
liver.toxicity$gene)
)
names(liverTib)[1] <- "Treatment"
liverTib
# MAKE TASK, LEARNER AND ATTEMPT TO BULD MODEL
liverTask <- makeClassifTask(data = liverTib, target = "Treatment")
plsda <- makeLearner("classif.plsdaCaret")
liverModel <- train(plsda, liverTask)
Upvotes: 1
Views: 1422
Reputation: 5580
In the development version of mlr
(v2.14.0.9000) multiclass classification via plsdaCaret
model is enabled. You can download the package from GitHub using this code:
install.packages("remotes")
remotes::install_github("mlr-org/mlr")
A PLS-DA example with 3 classes:
library(mlr)
#> Loading required package: ParamHelpers
tsk <- makeClassifTask("iris", iris, target = "Species")
lrn1 <- makeLearner("classif.plsdaCaret")
mod1 <- train(lrn1, tsk)
prd <- predict(mod1, tsk)
calculateConfusionMatrix(prd)
#> predicted
#> true setosa versicolor virginica -err.-
#> setosa 50 0 0 0
#> versicolor 0 31 19 19
#> virginica 0 8 42 8
#> -err.- 0 8 19 27
Created on 2019-07-18 by the reprex package (v0.3.0)
(This pull request solved the issue.)
Upvotes: 1
Reputation: 698
The current implementation does not support multiclass, see here: https://mlr.mlr-org.com/articles/tutorial/integrated_learners.html
You can change the code for the learner (https://github.com/mlr-org/mlr/blob/master/R/RLearner_classif_plsdaCaret.R) to make multiclass possible (see here for an instruction: https://mlr.mlr-org.com/articles/tutorial/create_learner.html).
Upvotes: 0