我正在运行函数帮助中包含的示例的轻微变化,timeseriesWF
但使用用户定义的函数 ( svmR
) 而不是svm
. 但是我得到Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "c('double', 'numeric')"
但不明白为什么该示例适用svm
但不适用svmR
:
library(DMwR)
library(e1071)
getSymbols('^GSPC',from='2008-01-01',to='2012-12-31')
data.model <- specifyModel(
Next(100*Delt(Ad(GSPC))) ~ Delt(Ad(GSPC),k=1:10)+Delt(Vo(GSPC),k=1:3))
data <- as.data.frame(modelData(data.model))
colnames(data)[1] <- 'PercVarClose'
svmR <- function(form,train,test,b.t=0.1,s.t=-0.1,...) {
require(e1071)
t <- svm(form,train,...)
p <- predict(t,test)
}
spExp <- experimentalComparison(
c(dataset(PercVarClose ~ .,data,'SP500_2008_2012')),
variants('timeseriesWF',
learner='svmR',learner.pars=list(cost=10),
type=c('slide','grow'),relearn.step=200,
evaluator.pars=list(stats='nmse')),
mcSettings(2,0.5,0.25))
编辑:linux 和 windows 运行不同版本的包。