I'm a new R user. I got an error with the caret package I can't explain.
My experiment is made of 305 observations of 8 variables, and 3 classes. I want to train a model (here a neural network) and then predict classes for a test set of observations, with the probability for each class. As I want to try several models, I want to use the 'caret' package.
When running the following script, R stops with the following error while trying to predict :
Error in dimnames(out)[[2]] <- rev(modelFit$obsLevels) :
la longueur de 'dimnames' [2] n'est pas égale à l'étendue du tableau
De plus : Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
There were missing values in resampled performance measures.
My Test object contains 14 observations with the 8 variables required. There are no missing data in any set.
Someone can help ?
Many thanks in advance ! Luc
Script:
library(nnet)
library(caret)
Vars <- read.csv('/home/moumou/ter/Lit.csv',header=FALSE)
Clas <- read.csv('/home/moumou/ter/Lot.csv',header=FALSE)
Test <- read.csv('/home/moumou/ter/Lie.csv',header=FALSE)
colnames(Vars) <- paste('col',1:ncol(Vars),sep='')
colnames(Clas) <- paste('cls',1:ncol(Clas),sep='')
colnames(Test) <- paste('col',1:ncol(Test),sep='')
dt1 <- data.frame(Clas,Vars)
summary(dt1)
dt2 <- as.data.frame(Test)
summary(dt2)
model <- train(cls1 + cls2 + cls3 ~ col1 + col2 + col3 + col4 + col5 + col6 + col7 + col8 , data = dt1, method='nnet')
pred <- predict(model,newdata=dt2,type='prob')