Error in the predict function


#1

I m getting an error in predict function .

logsTest.preds <- predict(rf.cv1, logsTest.ngram.tfidf.df)

error: Error in eval(predvars, data, env) : object 'kimijima_pls' not found

the logsTest.ngram.tfidf.df dataframe does not even have that object . Even the logsTrain.ngram.tfidf.df doesnot have it which is used for making the model rf.cv1

i have used regular expressions to remove words like [.kimi.] and hence it doesnt show in colnames of logsTrain.ngram.tfidf.df and logsTest.ngram.tfidf.df


#2

As I understand it, this error arises when the predict function doesn't know the source of the test data variable to be tested against. I have no way, of course, of knowing how it decided that kimilma_pls was the object it decided it was looking for. In any event look at the signature for predict: it wants at least the name of the model and it will take additional arguments specifying the specific types of prediction.


#3

The rf.cv1 is the model created using randomForest method which is made using the logsTrain.ngram.tfidf.df
The logsTest.ngram.tfidf.df is the test data which has been cleaned in the same way as the training data (logsTrain.ngram.tfidf.df)
Also the same colnames are present in both logsTrain and logsTest.ngram.tfidf.df ,and kimijima_pls not there in either.


#4

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.


#5

I second the motion. There's a huge difference in trying to troubleshoot the output of stats::predict and randomForest::predict


#6

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