I'm trying to use caret to do a basic model selection for a radial basis function network, but when i use the train() function from caret, the following error appears :
Error in UseMethod("train") :
no applicable method for 'train' applied to an object of class "c('matrix',
'double', 'numeric')"
I have no idea of what I'm doing wrong here, i hope you can help me with thtat one. Here's the code :
Data1<-as.matrix(runif(1000))
Data2<-as.matrix(runif(1000))
Data3<-as.matrix(runif(1000))
Data4<-as.matrix(runif(1000))
Data5<-as.matrix(runif(1000))
Data6<-as.matrix(runif(1000))
data<-cbind(Data1,Data2,Data3,Data4,Data5,Data6)
colnames(data)<-c("Feature1","Feature2","Feature3","Feture4","Feature5","Feature6")
targetfunction<-function(xi){
error<-rnorm(1,0,0.1)
return (sin(2*xi[1])*xi[2]+0.5*(xi[3]-0.5)^2+xi[4]+error)
}
target<-as.matrix(rep(0,times=1000))
for (i in 1:1000){
target[i]<-as.matrix(targetfunction(data[i,]))
}
library(mRMRe)
#Binding data and target
DM = cbind(data, target)
DM = mRMR.data(as.data.frame(DM))
s1 = mRMR.classic(data = DM, feature_count = 1, target_indices = c(7))
s2 = mRMR.classic(data = DM, feature_count = 2, target_indices = c(7))
s3 = mRMR.classic(data = DM, feature_count = 3, target_indices = c(7))
s4 = mRMR.classic(data = DM, feature_count = 4, target_indices = c(7))
s5 = mRMR.classic(data = DM, feature_count = 5, target_indices = c(7))
s6 = mRMR.classic(data = DM, feature_count = 6, target_indices = c(7))
#Optimal solutions for feature selection (Mutual information)
solutions(s1)
solutions(s2)
solutions(s3)
o = solutions(s4)
solutions(s5)
solutions(s6)
#for reproducibility
o = c(4,2,1,5)
#########################################################################################
#Model selection
#########################################################################################
library(caret)
library(RSNNS)
#Splitting data
prepValues = data[,o]
trainSet = prepValues[1:750,]
testset = prepValues[751:1000,]
colnames(trainSet) = c("x1","x2","x3","x4")
colnames(target) = "targ"
test = cbind(target[1:750], trainSet)
#Training model
rbf = train(trainSet, target[1:750], method = "rbf")