【问题标题】:Why do I get the same error values when training SVMs in R?为什么在 R 中训练 SVM 时会得到相同的错误值?
【发布时间】:2020-11-08 01:08:14
【问题描述】:

我正在尝试对来自 Framingham Heart study 的数据集进行建模。该数据有一些分类变量,结构如下(TenYearCHD 是因变量):

'data.frame':   2928 obs. of  16 variables:
 $ male           : int  1 1 0 0 0 0 1 1 0 0 ...
 $ age            : int  39 48 61 46 43 63 52 43 50 43 ...
 $ education      : int  4 1 3 3 2 1 1 1 1 2 ...
 $ currentSmoker  : int  0 1 1 1 0 0 0 1 0 0 ...
 $ cigsPerDay     : int  0 20 30 23 0 0 0 30 0 0 ...
 $ BPMeds         : int  0 0 0 0 0 0 0 0 0 0 ...
 $ prevalentStroke: int  0 0 0 0 0 0 0 0 0 0 ...
 $ prevalentHyp   : int  0 0 1 0 1 0 1 1 0 0 ...
 $ diabetes       : int  0 0 0 0 0 0 0 0 0 0 ...
 $ totChol        : int  195 245 225 285 228 205 260 225 254 247 ...
 $ sysBP          : num  106 128 150 130 180 ...
 $ diaBP          : num  70 80 95 84 110 71 89 107 76 88 ...
 $ BMI            : num  27 25.3 28.6 23.1 30.3 ...
 $ heartRate      : int  80 75 65 85 77 60 76 93 75 72 ...
 $ glucose        : int  77 70 103 85 99 85 79 88 76 61 ...
 $ TenYearCHD     : int  0 0 1 0 0 1 0 0 0 0 ...

当我使用 tune.svm() 训练 SVM 时,所有模型都给出相同的错误(误分类)率,而不管成本值。

我尝试手动缩放数据,并让scale = TRUE 进入tune.svm()。我还尝试过对分类变量进行一次热编码。我遇到并尝试过的任何事情都没有任何改变。我这里有什么明显的遗漏吗?

我的模型调优代码:

library(e1071)

dat.train = as.data.frame(scale(dat))

svm1.tune = tune.svm(
  as.factor(TenYearCHD) ~ .,
  data = dat.train,
  type = "C-classification",
  kernel = "linear",
  scale = FALSE,
  cost = seq(from = 0.1, to = 5, by = 0.5),
  cross = 10
)

【问题讨论】:

  • 请贴出你试过的代码。
  • 您正在使用完整数据集(缩放)训练数据。将其划分为训练/测试。
  • 我已经做到了。不过我把它漏掉了,因为我不认为它会有所作为?

标签: r data-science svm kaggle


【解决方案1】:

事实证明,这是由于数据集非常不平衡和使用了错误的内核所致。一旦我通过一些过采样来平衡数据集,不同成本函数的误差就会不同。当我使用径向内核而不是线性内核时,它看起来会更好。

【讨论】:

    猜你喜欢
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 2021-04-06
    • 2018-08-04
    • 2015-03-12
    • 2015-07-04
    相关资源
    最近更新 更多