0

I created a model in R for my df as

fit <- randomForest(y ~ x1 + 
                     x2 + x3 + 
                     x4+ x5+x6+ x7+x8, 
                     data = data_train,ntree=35,
                     keep.forest=FALSE, importance=TRUE)

gives result as

 Call:
  randomForest(formula = y ~ x1 + x2 
 +      x3 + x4 + x5 + 
   x6 +      x7 + x8, data = 
data_train, ntree = 35,      keep.forest = FALSE, importance = TRUE) 
           Type of random forest: regression
                 Number of trees: 35
   No. of variables tried at each split: 2

        Mean of squared residuals: 2901510
                % Var explained: 53.45

but while I am predicting using

p <- predict(data_test, fit, type='prob')

Shows error

Error in ets(object, lambda = lambda, biasadj = biasadj, 
allow.multiplicative.trend = allow.multiplicative.trend,  : 
 y should be a univariate time series

When I am using

predict(fit, newdata= data_test)

Showing error

Error in predict.randomForest(fit, newdata = data_test) : 
 No forest component in the object

how can I solve this.. I am new in using RandomForest in R

3
  • Could you please share some reproducible data using dput? Commented Sep 9, 2022 at 13:39
  • Why do you have keep.forest = FALSE? Try changing that to TRUE and re-attempt your second prediction approach. Commented Sep 10, 2022 at 2:04
  • Please read the description of the ML tag. Commented Sep 10, 2022 at 5:32

1 Answer 1

1

As @bzki suggested By putting keep.forest = TRUE It works fine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.