3
$\begingroup$

In randomforest classification using h20 package, there are factor levels which are present in testing data but not in training data.There is a warning message in predicting the values of testing data, it says : test/validation dataset column 'x' has levels not trained on. Please help

$\endgroup$

1 Answer 1

2
$\begingroup$

This is the expected behaviour; if you cannot change your data, then just ignore the warning. (Sorry, I am not aware of any H2O option to suppress the warning.)

The better solution, and their motivation for giving you the warning, is to get better training data, and ensure that it covers all possible values you want to predict. This might mean changing the way you split your training data into train and test (e.g. group by each possible output level, and then randomly split each group 80:20, or whatever, rather than randomly splitting the whole training data 80:20).

An alternative solution is to pre-process the data to replace unusual or rare values. E.g. if you are predicting a person's favourite colour, and you have red, green, blue, yellow, purple, black all well-represented in the training data. But then you have one record each of "mauve" and "light teal". You might be better off converting them to "purple" and "green". The model is not going to learn much from just a single example.

$\endgroup$
3
  • $\begingroup$ If i ignore the warning,there is an error while : submission<-data.frame(unique_id=test$unique_id,target=predictions$predict) ::::Error in read.table(file = file, header = header, sep = sep, quote = quote, : 'file' must be a character string or connection $\endgroup$
    – PA17
    Commented Feb 15, 2019 at 12:25
  • $\begingroup$ @PA17 That looks like a different problem, unrelated to the factor level issue. But it is really hard to be sure, out of context. If you are sure that error only happens after ignoring the factor levels warning, can you update your question with a reproducible example (I.e. a bit like your question over on StackOverflow, but also including the data - and including only the minimum amount of data that is needed to show the problem). $\endgroup$ Commented Feb 15, 2019 at 12:57
  • $\begingroup$ to be precise : the error is:::: Error in read.table(file = file, header = header, sep = sep, quote = quote, : unused argument (optional = TRUE).....i think the test data is a h20 frame, so i think we cannot slice the unique_id column.. is that so? $\endgroup$
    – PA17
    Commented Feb 15, 2019 at 13:53

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.