2015-08-15 23 views
1

我想了解更多關於caret包的信息,並遇到了我不確定如何解決的包版問題。錯誤:嘗試在使用脫字號包時應用非功能

#loading up libraries 
library(MASS) 
library(caret) 
library(randomForest) 
data(survey) 
data<-survey 

#create training and test set 
split <- createDataPartition(data$W.Hnd, p=.8)[[1]] 
train<-data[split,] 
test<-data[-split,] 


#creating training parameters 
control <- trainControl(method = "cv", 
         number = 10, 
         p =.8, 
         savePredictions = TRUE, 
         classProbs = TRUE, 
         summaryFunction = "twoClassSummary") 

#fitting and tuning model 
tuningGrid <- data.frame(.mtry = floor(seq(1 , ncol(train) , length = 6))) 
rf_tune <- train(W.Hnd ~ . , 
      data=train, 
      method = "rf" , 
      metric = "ROC", 
      trControl = control) 

總是收到錯誤:

Error in evalSummaryFunction(y, wts = weights, ctrl = trControl, lev = classLevels, : 
    attempt to apply non-function 

我已經證實,我的DV(W.Hnd)是一個因素水平,使一個隨機森林將是適當的使用進行分類。我的假設是caret不知道適用於randomForest算法嗎?除此之外,我不知道。

回答

5

你在「twoClassSummary」附近有引號,它使得它成爲一個字符向量。 R試圖將此作爲引起錯誤的函數應用。

刪除引號並再次嘗試腳本。這應該能夠正確調用功能twoClassSummary

#creating training parameters 
control <- trainControl(method = "cv", 
         number = 10, 
         p =.8, 
         savePredictions = TRUE, 
         classProbs = TRUE, 
         summaryFunction = twoClassSummary) 
相關問題