【问题标题】:Error: attempt to apply non-function when using caret package错误:使用 caret 包时尝试应用非函数
【发布时间】:2015-08-17 17:35:15
【问题描述】:

我试图更多地了解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 算法?除此之外我不知道。

【问题讨论】:

    标签: r machine-learning r-caret


    【解决方案1】:

    “twoClassSummary”周围有引号,这使它成为一个字符向量。 R 试图将此作为函数应用,这会导致错误。

    删除引号并再次尝试您的脚本。这应该可以正确调用函数twoClassSummary

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-03
      • 2015-10-27
      • 2021-03-17
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 2014-09-11
      • 1970-01-01
      相关资源
      最近更新 更多