0

I used caret package for cross validation but when I tried to use the prediction i got an error indicating : " replacement has 1118691 rows, data has 1118705". When I used the regular lm() it does the prediction just fine.What can be a solution for this error? I can't deliver my data set this time but when I tested my code on a toy data frame the prediction works.So I guess it is somthing that is related to the data itself. Here are my lines of code (works fine on the toy data):

df <- read.table(text = "dateTime         birds    wolfs     snakes
                           2014-05-21        9         7    a
                           2014-04-28        8         4    b
                           2014-04-13        2         8    c
                           2014-03-12        2         3    a
                           2014-02-04        8         3    a
                           2014-02-29        1         2    a
                           2014-01-17        7         1    b
                           2014-01-16        1         5    c
                           2014-09-20        9         7    c
                           2014-08-21        8         7    c ",header = TRUE)
fitControl3 <- trainControl(## 10-fold CV
     method = "repeatedcv",
     number = 3,
     ## repeated 3 times
     repeats = 3)
df$lm_pred<-predict(df_model,newdata=df,type='raw')
smci
  • 32,567
  • 20
  • 113
  • 146
mql4beginner
  • 2,193
  • 5
  • 34
  • 73
  • Are there any `NA` values? They may not be entering the model, result in the discrepancy in number of rows. – Roman Luštrik Jul 20 '15 at 09:06
  • There are NA values but when I tried: df$lm_pred<-predict(df_model,newdata=df,type='raw' ,na.action = na.omit) it didn't helped. – mql4beginner Jul 20 '15 at 09:07
  • And neither it should. I think you should work on a smaller subset first, reproduce the error, solve it and then move to the full dataset. – Roman Luštrik Jul 20 '15 at 10:30

0 Answers0