R:svmRadial在插入符号中工作不正常

R:svmRadial在插入符号中工作不正常,r,svm,r-caret,R,Svm,R Caret,我试着运行《应用预测建模》一书中的代码,该书是关于通过插入符号“训练”函数用径向核训练SVM的部分 我复制了代码,没有添加任何内容。代码运行时没有任何错误,但结果与书中所写的不一致。所有的概率几乎相同,所有的物体都被归类为一类。以下是代码: library(caret) data("GermanCredit") GermanCredit <- GermanCredit[, -nearZeroVar(GermanCredit)] # remove some other columns tha

我试着运行《应用预测建模》一书中的代码,该书是关于通过插入符号“训练”函数用径向核训练SVM的部分

我复制了代码,没有添加任何内容。代码运行时没有任何错误,但结果与书中所写的不一致。所有的概率几乎相同,所有的物体都被归类为一类。以下是代码:

library(caret)
data("GermanCredit")
GermanCredit <- GermanCredit[, -nearZeroVar(GermanCredit)]
# remove some other columns that do not add useful information
GermanCredit$CheckingAccountStatus.lt.0 <- NULL
GermanCredit$SavingsAccountBonds.lt.100 <- NULL
GermanCredit$EmploymentDuration.lt.1 <- NULL
GermanCredit$EmploymentDuration.Unemployed <- NULL
GermanCredit$Personal.Male.Married.Widowed <- NULL
GermanCredit$Property.Unknown <- NULL
GermanCredit$Housing.ForFree <- NULL

#Split the data into training (80%) and test sets (20%)
set.seed(100)
inTrain <- createDataPartition(GermanCredit$Class, p = .8)[[1]]
GermanCreditTrain <- GermanCredit[ inTrain, ]
GermanCreditTest  <- GermanCredit[-inTrain, ]

set.seed(1056)
svmFit <- train(Class ~ .,
           data = GermanCreditTrain,
           method = "svmRadial",
           preProcess = c("center", "scale"),
           tuneLength = 10,
           trControl = trainControl(method = "repeatedcv",                                        repeats = 5,
                                    classProbs = TRUE)) 
所以,准确度甚至不会改变。我尝试了不同的参数集,但结果是一样的

所有样本的概率几乎相同:“坏”类约为0.304,“好”类约为0.695(差异仅在第四位)

本书的结果可在以下位置获得:

他们有

> svmFit
Support Vector Machines with Radial Basis Function Kernel 

800 samples
 41 predictors
  2 classes: 'Bad', 'Good' 

Pre-processing: centered, scaled 
Resampling: Cross-Validated (10 fold, repeated 5 times) 

Summary of sample sizes: 720, 720, 720, 720, 720, 720, ... 

Resampling results across tuning parameters:

  C     Accuracy  Kappa  Accuracy SD  Kappa SD
  0.25  0.744     0.362  0.0499       0.113   
  0.5   0.74      0.35   0.0516       0.117   
  1     0.746     0.348  0.0522       0.125   
  2     0.743     0.325  0.0467       0.116   
  4     0.744     0.322  0.0477       0.12    
  8     0.75      0.323  0.0464       0.13    
  16    0.745     0.302  0.0457       0.13    
  32    0.739     0.28   0.0451       0.126   
  64    0.743     0.284  0.0444       0.135   
  128   0.734     0.265  0.0445       0.124   

Tuning parameter 'sigma' was held constant at a value of 0.008918477
Accuracy was used to select the optimal model using  the largest     value.
The final values used for the model were sigma = 0.00892 and C = 8. 
此外,全班都得到了这样的结果,但老师的电脑上有旧版本的R,得到了正确的结果。所以我的问题是:在R、caret、kernlab或其他更新版本中的一些更改中是否存在问题,或者我在其他方面是否做错了?如何更改此代码以获得适当的结果?插入符号版本为6.0-77


提前感谢。

请编辑您的问题并添加预期输出(从书中?)。添加输出并链接到全文使用当前开发版本进行尝试。CRAN上的最新版本可能有问题。您好,@topepo!我刚刚从github安装了dev版本。它似乎工作得很好。谢谢。
> svmFit
Support Vector Machines with Radial Basis Function Kernel 

800 samples
 41 predictors
  2 classes: 'Bad', 'Good' 

Pre-processing: centered, scaled 
Resampling: Cross-Validated (10 fold, repeated 5 times) 

Summary of sample sizes: 720, 720, 720, 720, 720, 720, ... 

Resampling results across tuning parameters:

  C     Accuracy  Kappa  Accuracy SD  Kappa SD
  0.25  0.744     0.362  0.0499       0.113   
  0.5   0.74      0.35   0.0516       0.117   
  1     0.746     0.348  0.0522       0.125   
  2     0.743     0.325  0.0467       0.116   
  4     0.744     0.322  0.0477       0.12    
  8     0.75      0.323  0.0464       0.13    
  16    0.745     0.302  0.0457       0.13    
  32    0.739     0.28   0.0451       0.126   
  64    0.743     0.284  0.0444       0.135   
  128   0.734     0.265  0.0445       0.124   

Tuning parameter 'sigma' was held constant at a value of 0.008918477
Accuracy was used to select the optimal model using  the largest     value.
The final values used for the model were sigma = 0.00892 and C = 8.