I have a datasets composed like this:


data <- iris
train <- data [1:75,]
test <- data[76:150,]

So, I have 3 classes in total but:

  1. Train: setosa and versicolor
  2. Test: versicolor and virginica

I tryed to set a decision tree, but obviusly it doesn't work because train and test haven't the same classes. My R code is:

trainctrl <- trainControl(method = "cv", number = 5, verboseIter = FALSE)
dt.model <- train(Species~., data=train, method = "rpart", 
                  tuneLength = 10,
                  preProcess = c("center", "scale"),
                  trControl = trainctrl)

test$prediction <-predict(dt.model, test)

Is there a model that if in the test meets a virginica class flower is able to tell me that it is another species? In other words, I want a model that can tell me that that flower is completely different from the ones he trained on. Is it possible?


1 Answer 1


Regular classification methods are discriminative, i.e. they find how to distinguish the classes in the training set from one another. In other words, they are only interested in the differences between the classes.

This implies that a classification model cannot be applied to different classes than the ones it was trained on, since it has zero information about how to distinguish the new classes.

However there are also methods which attempt to represent what characterizes a full class instead of only the differences between classes. In particular one-class classification can be used to train a model which recognizes if an instance belongs to some target class or not. Note that this is a different paradigm than regular classification. The model is trained using only positive instances, i.e. only instances which belong to the target class.

In your example you could train a one-class classification model which recognizes the class versicolor, then apply it to a test set containing some other classes. Of course, one should expect a lower performance than regular classification since the model doesn't have as much information.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.