Machine learning problem - train and test with different classes

I have a datasets composed like this:

library(caret)

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?

How would the model be able to tell if an observation is completely different if it never saw an example of a completely different observation? And, how different would an observation have to be to be considered "completely different?" This would have to be decided quantitatively somehow and it isn't something that a model is going to be able to learn unless you provide it the data.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.