rpart 插入符号 "Argument params not matched" 错误

rpart caret "Argument params not matched" error

我在使用插入符包 rpart 模型时遇到问题。当我 运行 第 1 部分中的代码时,出现以下错误:

第 1 部分

library(rpart)
library(caret)

creditNames <- c("Checking", "Duration", "CreditHistory", "Purpose",
                 "CreditAmount", "Savings", "Employment", 
                 "InstallmentRate", "GenderMarital", "OtherDebtors",
                 "YearsAtResidence", "RealEstate", "Age", 
                 "OtherInstallment", "Housing", "ExistingCredit",
                 "Job", "NumLiable", "Phone", "Foreign", "Credit")

url="http://archive.ics.uci.edu/ml/machine-learning-databases/statlog/german/german.data"
credit_data <- read.table(url, sep=" ", header = FALSE, 
                  col.names = creditNames, 
                  stringsAsFactors = FALSE)

creditHistory <- c(A30="All Paid", A31="All Paid This Bank",
                   A32="Up To Date", A33="Late Payment",
                   A34="Critical Account")
credit_data$CreditHistory <- as.factor(creditHistory[credit_data$CreditHistory])

credit_data$Credit <- ifelse(credit_data$Credit == 1, "Good", "Bad")
credit_data$Credit <- factor(credit_data$Credit, levels = c("Good", "Bad"))

fitControl <- trainControl(method = 'cv', number = 6)

Grid <- expand.grid(
                    cp=.02)

vars <- names(credit_data)[c(5,13,3,7)]
samp.f <- as.formula(paste(names(credit_data)[21], paste(vars, collapse = " + "),sep="~"))

myvars <- c("Credit", "CreditAmount", "Age") #"CreditHistory", ,  "Employment"


samp.m <- train(samp.f,
                data=credit_data,
                method='rpart',
                trControl = fitControl,
                tuneLength=20,
                metric = "Accuracy",
                tuneGrid = Grid,
                na.action = na.omit,
                params=list(split='information'))

model fit failed for Fold1: cp=0.02 Error in (function (formula, data, weights, subset, na.action = na.rpart, : Argument params not matched

但是,当我 运行 第 2 部分中的代码时,我没有收到错误。

第 2 部分

for (test_cp in seq(.001,.02,.001)){
   test<-rpart(samp.f, dat=credit, cp=test_cp, maxdepth=5)
}

有什么建议吗?

我正在运行进行以下设置:

R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
other attached packages:
[1] caret_6.0-79    ggplot2_2.2.1   lattice_0.20-35 rpart_4.1-13 

rpart函数没有params选项,但是有parms选项。所以在train中你需要使用parms而不是params。

rpart(formula, data, weights, subset, na.action = na.rpart, method, model = FALSE, x = FALSE, y = TRUE, parms, control, cost, ...)

samp.m <- train(samp.f,
                data=credit_data,
                method='rpart',
                trControl = fitControl,
                tuneLength=20,
                metric = "Accuracy",
                tuneGrid = Grid,
                na.action = na.omit,
  #-->#         parms=list(split='information'))