Using the mlr package, I have developed a task using word frequency data to categorize tweets into two categories (TRUE and FALSE). Now I am using this task to classify out-of-sample tweets. Sorry, I cannot share my data, but I will show my code here:

task = makeClassifTask(data = train, target = "category")
mod = train("classif.randomForest", task)

newdata.pred = predict(mod, newdata = outofsample)

My output is shown here:

Prediction: 17981 observations
predict.type: response
time: 0.29
... (#rows: 17981, #cols: 1)

And as a dataframe:

1   TRUE            
2   FALSE           
3   FALSE           
4   FALSE           
5   FALSE           

I now want to use my categorization to remove any tweets falling in the "FALSE" category. But if I have 17981 tweets, why do I only see 6 observations? I cannot find anything wrong with the "train" dataframe or "outofsample" dataframe (they both have the appropriate number of observations and are listed as dataframes in the global environment, but I did notice that the object "task" creates a list of 6. Is this just a coincidence? How do I retrieve the classification for all of my tweets? And how do I link this information to the out of sample dataset to delete tweets by ID number, if this classification method does not include ID number?

Please don't judge me too harshly, I'm very new to machine learning and R in general. Any advice would be a big help.


The actual predictions can be found in newdata.pred$data.

Note that mlr is no longer maintained:

{mlr} is considered retired from the mlr-org team. We won’t add new features anymore and will only fix severe bugs. We suggest to use the new mlr3 framework from now on and for future projects.

See the docs: https://mlr.mlr-org.com/


df = ISLR::Auto
df$cylinders = as.factor(df$cylinders)
df$name <- NULL

task = makeClassifTask(data = df, target = "cylinders")
mod = train("classif.randomForest", task)

newdata.pred = predict(mod, newdata = df)
result = data.frame(newdata.pred$data)

    truth response
1       8        8
2       8        8
3       8        8
4       8        8
5       8        8
6       8        8
7       8        8
8       8        8
9       8        8
10      8        8
11      8        8
12      8        8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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