0

我将弹性网络分类器用于需要介于 0 和 1 之间的概率输出的模型,并且我发现 SVM 的分类精度比 glmnet 模型好得多(这并不奇怪)。我知道 e1071 支持 SV 回归,有没有办法指定链接函数并获得支持向量逻辑回归?谢谢。顺便说一句,使用 R 3.01。

4

1 回答 1

1

probability=True我认为您需要做的就是在模型参数中设置,而不是使用 logit 链接函数(我不确定您会如何) 。

试试这个例子:

library(e1071)

data(iris)

#convert this into a two class problem with 0's and 1's in our response
subs_iris = subset(iris, Species != 'virginica')
subs_iris$Species = ifelse(subs_iris$Species == 'setosa',0,1)
attach(subs_iris)

x <- subset(subs_iris, select = -Species)
y <- Species
model <- svm(x, as.factor(y), probability=T)
(pred <- predict(model, x, probability=T))


1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21 
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 

22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42 
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 

43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63 
0   0   0   0   0   0   0   0   1   1   1   1   1   1   1   1   1   1   1   1   1 

64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84 
1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 

85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 
1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 

attr(,"probabilities")
              0          1
1   0.987105973 0.01289403
2   0.981947817 0.01805218
3   0.985437173 0.01456283
4   0.982502592 0.01749741
5   0.986736251 0.01326375
6   0.985797388 0.01420261
7   0.982548458 0.01745154
8   0.986618794 0.01338121
9   0.978261097 0.02173890
10  0.983057145 0.01694286
11  0.985273718 0.01472628
12  0.985044518 0.01495548
13  0.982882845 0.01711715
14  0.977350638 0.02264936
15  0.977353717 0.02264628
16  0.977337824 0.02266218
17  0.986633849 0.01336615
18  0.987559915 0.01244008
19  0.979015418 0.02098458
20  0.986641340 0.01335866
21  0.979223478 0.02077652
22  0.987128146 0.01287185
23  0.977319879 0.02268012
24  0.977318096 0.02268190
25  0.982043578 0.01795642
26  0.977302751 0.02269725
27  0.985124984 0.01487502
28  0.986267482 0.01373252
29  0.985675766 0.01432423
30  0.983434135 0.01656587
31  0.982646443 0.01735356
32  0.979790608 0.02020939
33  0.979143578 0.02085642
34  0.981984290 0.01801571
35  0.983332565 0.01666743
36  0.985862990 0.01413701
37  0.980783392 0.01921661
38  0.983998736 0.01600126
39  0.979876054 0.02012395
40  0.986253654 0.01374635
41  0.987705405 0.01229459
42  0.946960057 0.05303994
43  0.978967777 0.02103222
44  0.980641733 0.01935827
45  0.984315643 0.01568436
46  0.981331513 0.01866849
47  0.985423052 0.01457695
48  0.983645068 0.01635493
49  0.986290826 0.01370917
50  0.986350301 0.01364970
51  0.029433804 0.97056620
52  0.016430412 0.98356959
53  0.024776288 0.97522371
54  0.009426853 0.99057315
55  0.016452416 0.98354758
56  0.012704127 0.98729587
57  0.019445907 0.98055409
58  0.030085332 0.96991467
59  0.018511622 0.98148838
60  0.014208017 0.98579198
61  0.029383457 0.97061654
62  0.014964845 0.98503516
63  0.026215448 0.97378455
64  0.013069314 0.98693069
65  0.022539574 0.97746043
66  0.019169611 0.98083039
67  0.018805048 0.98119495
68  0.019024824 0.98097518
69  0.029443333 0.97055667
70  0.011480062 0.98851994
71  0.026777215 0.97322278
72  0.014014692 0.98598531
73  0.021568195 0.97843180
74  0.015284531 0.98471547
75  0.015807559 0.98419244
76  0.016950698 0.98304930
77  0.025482614 0.97451739
78  0.023218517 0.97678148
79  0.012583780 0.98741622
80  0.022016637 0.97798336
81  0.010875445 0.98912455
82  0.014092065 0.98590794
83  0.013192719 0.98680728
84  0.017883555 0.98211644
85  0.024212461 0.97578754
86  0.029433804 0.97056620
87  0.018419284 0.98158072
88  0.025893165 0.97410684
89  0.022054824 0.97794518
90  0.008828270 0.99117173
91  0.010761677 0.98923832
92  0.013793894 0.98620611
93  0.011470407 0.98852959
94  0.023992095 0.97600791
95  0.010806582 0.98919342
96  0.022895843 0.97710416
97  0.015274431 0.98472557
98  0.014182305 0.98581770
99  0.029373597 0.97062640
100 0.012725531 0.98727447
Levels: 0 1

说实话,我在$probabilities这里访问属性时遇到了一些困难,但理论上你应该没问题,只要看看每条记录属于“1”类的概率。

于 2013-07-19T20:02:05.030 回答