1.1000个ç¹å¾7个类å«MATLABä¸SVMå¾è®ç»å¤ä¹
1000个ç¹å¾7个类å«MATLABä¸SVMå¾è®ç»å¤ä¹
3天
svm模åè®ç»åçåæ°è¯´æ
ç°ç®å对å±å¹åæ¾ä¿¡æ¯è¿⾏说æï¼
#iter 为è¿ä»£æ¬¡æ°ï¼
nu ä¸å⾯çæä½åæ° -n nu ç¸åï¼
obj 为 SVM ⽂件转æ¢ä¸ºç⼆次è§åæ±è§£å¾å°çæ⼩å¼ï¼
rho 为å¤å³å½æ°ç常æ°é¡¹ b ï¼
nSV 为⽀æåé个æ°ï¼
nBSV 为边çä¸ç⽀æåé个æ°ï¼
Total nSV 为⽀æåéæ»ä¸ªæ°ã
è®ç»åç模åä¿å为⽂件 *.model ï¼⽤è®°äºæ¬æå¼å ¶å 容å¦ä¸ï¼
svm_type c_svc % è®ç»æé⽤ç svm ç±»åï¼æ¤å¤ä¸º C- SVC
kernel_type rbf % è®ç»é⽤çæ ¸å½æ°ç±»åï¼æ¤å¤ä¸º RBF æ ¸
gamma 0. % è®¾ç½®æ ¸å½æ°ä¸ç g ï¼é»è®¤å¼ä¸º 1/ k
nr_class 2 % åç±»æ¶çç±»å«æ°ï¼æ¤å¤ä¸ºä¸¤åç±»é®é¢
total_sv % æ»å ±ç⽀æåé个æ°
rho 0. % å³çå½æ°ä¸ç常æ°é¡¹ b
label 1 -1% ç±»å«æ ç¾
@å¾®ç豪èµæéåå享
nr_sv % åç±»å«æ ç¾å¯¹åºç⽀æåé个æ°
SV % 以ä¸ä¸º⽀æåé
1 1:0. 2:1 3:-0. 4:-0.
2 5:-0. 6:-1 7:-1 8:0.
3 9:-1 :-0. :-1 :-1 :1
0. 1:0. 2:1 3:0. 4:-0. 5:-0. 6:1 7:1 8:0. 9:1 :-0. :-0. :0.5
1 1:0. 2:1 3:-1 4:-0. 5:-0. 6:-1 7:-1 8:0. 9:-1 :-0. :0. :-1
1 1:0. 2:1 3:0. 4:-0. 5:-0. 6:-1 7:1 8:0. 9:-1 :-0. :-0. :1
4 ï¼é⽤交åéªè¯éæ©æä½³åæ° C ä¸ g
é常⽽⾔ï¼⽐è¾éè¦çåæ°æ¯ gamma (-g) è· cost (-c) ã⽽ cross validation (-v)
çåæ°å¸¸⽤ 5 ãé£ä¹å¦ä½å»éåæä¼çåæ° c å g å¢ï¼ libsvm ç python ⼦⽬å½ä¸⾯ç grid.py å¯ä»¥å¸®å©æ们ã æ¤æ¶ãå ¶ä¸å®
è£ python2.5 éè¦ï¼⼀è¬é»è®¤å®è£ å° c:/python
ä¸ï¼ï¼å° gnuplot 解åãå®è£ 解åå®æ¯åï¼è¿⼊ /libsvm/tools ⽬å½ä¸ï¼⽤⽂æ¬ç¼è¾å¨ï¼è®°äº
æ¬ï¼ edit é½å¯ä»¥ï¼ä¿®æ¹ grid.py ⽂件ï¼æ¾å°å ¶ä¸å ³äº gnuplot è·¯å¾çé£é¡¹ï¼å ¶é»è®¤è·¯å¾ä¸º
gnuplot_exe=r"c:/tmp/gnuplot/bin/pgnuplot.exe" ï¼ï¼æ ¹æ®å®é è·¯å¾è¿⾏ä¿®æ¹ï¼å¹¶ä¿åãç¶
åï¼å° grid.py å C:/Python ⽬å½ä¸ç python.exe ⽂件æ·è´å° libsvm/windows ⽬å½ä¸ï¼é®⼊以ä¸å½ä»¤ï¼ $ python grid.py
train.1.scale æ§⾏åï¼å³å¯å¾å°æä¼åæ° c å g ã
å¦å¤ï¼⾄äºä¸ libsvm å python çæ¥⼝çé®é¢ï¼å¨ libsvm2. ä¸æ⽼å¸å·²ç»å¸®å©æ们解å³ï¼å¨/libsvm/windows/python ⽬å½ä¸⾃å¸¦äº svmc.pyd è¿ä¸ª⽂件ï¼å°è¯¥⽂件⽂件å¤å¶å°
@å¾®ç豪èµæéåå享
libsvm/python ⽬å½ä¸ï¼åæ¶ï¼ä¹å° python.exe ⽂件å¤å¶å°è¯¥⽬å½ä¸ï¼é®⼊以ä¸å½ä»¤ä»¥æ£éªæ
æï¼æ³¨æï¼ .Py ⽂件ä¸å ³äº gnuplot è·¯å¾çé£é¡¹è·¯å¾⼀å®è¦æ ¹æ®å®é è·¯å¾ä¿®æ¹ï¼ï¼
python svm_test.py
å¦æè½çå°ç¨åºæ§⾏ç»æï¼è¯´æ libsvm å python ä¹é´çæ¥⼝å·²ç»é ç½®å®æï¼ä»¥åå°±å¯ä»¥ç´æ¥å¨python ç¨åº⾥è°⽤ libsvm çå½æ°äºï¼
5 ï¼ é⽤æä½³åæ° C ä¸ g 对æ´ä¸ªè®ç»éè¿⾏è®ç»è·å⽀æåéæºæ¨¡å
$ svmtrain âc x âg x âv x training_set_file [model_file]
x 为ä¸è¿°å¾å°çæä¼åæ° c å g çå¼ï¼ v çå¼⼀è¬å 5 ã
6 ï¼å©⽤è·åç模åè¿⾏æµè¯ä¸é¢æµ
使⽤ Svmtrain è®ç»å¥½ç模åè¿⾏æµè¯ãè¾⼊æ°ç X å¼ï¼ç»åº SVM é¢æµåºç Y å¼
$ Svmpredict test_file model_file output_file
å¦ï¼ ./svm-predict heart_scale heart_scale.model heart_scale.out
Accuracy = .% (/) (classification)
è¿⾥æ¾⽰çæ¯ç»æ
⼀ä¸ªå ·ä½ä½¿⽤çä¾⼦ã
以 libsvm ä¸ç heart_scale ä½ä¸ºè®ç»æ°æ®åæµè¯æ°æ®ï¼åæ¶å·²ç»å° python å®è£ ⾄ c çï¼å¹¶å°grid.py ⽂件ä¸å ³äº gnuplot è·¯å¾çé»è®¤å¼ä¿®æ¹ä¸ºå®é 解å缩åçè·¯å¾ï¼å°
heart_scale ã grid.py å python.exe æ·è´⾄ /libsvm/windows ⽂件夹ä¸ã
./svm-train heart_scale
optimization finished,c crm源码 #iter =
nu = 0.
obj = -., rho = 0.
nSV = , nBSV =
Total nSV =
æ¤æ¶ï¼å·²ç»å¾å° heart_scale.model ï¼è¿⾏é¢æµï¼
./svm-predict heart_scale heart_scale.model heart_scale.out
Accuracy = .% (/) (classification)
æ£ç¡®ç为 Accuracy = .% ã
./python grid.py heart_scale
å¾å°æä¼åæ° c= ï¼ g=0..
./svm-train -c -g 0. heart_scale å¾å° model åï¼ç± ./svm-predict heart_scale heart_scale.model
heart_scale.out å¾å°çæ£ç¡®
ç为 Accuracy = .%.è¿åè¿æç¹è¿·æï¼ä¸ºä»ä¹æ£ç¡®çéä½äºï¼
å½ç¶ä¹å¯ä»¥ç»åsubset.py å easy.py å®ç°⾃å¨åè¿ç¨ã
@å¾®ç豪èµæéåå享
å¦æè¦è®ç»å¤æ¬¡ï¼å¯ä»¥å个æ¹å¤çç¨åºç好å¤äºã
è¿⾥举个ä¾⼦ï¼
::@ echo off
cls
:: split the data and output the results
for /L %%i in (1,1,) do python subset.py b.txt b(%%i).in8 b(%%i).out2
for /L %%i in (1,1,) do python easy.py b(%%i).in8 b(%%i).out2 >> result.txt
è¿æ®µæ¹å¤ç代ç ⾸å è°⽤subset.py对⽂件b.txtæ§⾏次åå±éæºæ½æ ·(对æ°æ®è¿⾏-%åå²)ç¶åè°⽤easy.py è¿⾏次åæ°å¯»ä¼ï¼æè®°å½ç»æåå°result.txtä¸
ï¼å æ¬æ¬¡è®ç»çåç±»åç¡®çååæ°å¯¹ï¼ã
è¿å¯ä»¥è°⽤fselect.pyè¿⾏ç¹å¾éæ©ï¼è°⽤plotroc.pyè¿⾏rocæ²çº¿ç»å¶ã
å åå°è¿⾥å§ï¼å¸æè½å⼤家⼀èµ·å¦ä¹ libsvmï¼è¿⼀æ¥å¦å¥½svmã
æå¼APPè·åå ¨æ

已精ésvm模åè®ç»å...ä¼åææ¡£ç¯

MATLABä¸SVMï¼æ¯æåéæºï¼çç¨æ³
人é 读

OpencvSVMæ¯æåéæºåæ°ä¸ä¼åï¼
8人é 读

SVMåæ°è®¾ç½®ååç§åæ°æä¹
人é 读

sklearnsvmè°å_SVMè°ä¼è¯¦è§£Â·messiçå客