Home LIBSVM notes
Post
Cancel

LIBSVM notes

LIBSVM – A Library for Support Vector Machines

svm的使用

其中参数:-s SVC是SVM分类器,SVR是SVM回归

1
2
3
4
5
0 -- C-SVC		(multi-class classification)
1 -- nu-SVC		(multi-class classification)
2 -- one-class SVM	
3 -- epsilon-SVR	(regression)
4 -- nu-SVR		(regression)

-t 核函数的类型: kernel_type : set type of kernel function (default 2)

1
2
3
4
5
0 -- linear: u'*v
1 -- polynomial: (gamma*u'*v + coef0)^degree
2 -- radial basis function: exp(-gamma*|u-v|^2)
3 -- sigmoid: tanh(gamma*u'*v + coef0)
4 -- precomputed kernel (kernel values in training_set_file)

分类,Classify a binary data with polynomial kernel (u’v+1)^3 and C = 10

1
svmtrain -s 0 -c 10 -t 1 -g 1 -r 1 -d 3 

回归

1

svm_light - select between classification (c), regression (r), and preference ranking (p)

LIBLINEAR – A Library for Large Linear Classification

Introduction

LIBLINEAR is a linear classifier for data with millions of instances and features. It supports

  • L2-regularized classifiers
  • L2-loss linear SVM, L1-loss linear SVM, and logistic regression (LR)
  • L1-regularized classifiers (after version 1.4)
  • L2-loss linear SVM and logistic regression (LR)
  • L2-regularized support vector regression (after version 1.9)
  • L2-loss linear SVR and L1-loss linear SVR.

Main features of LIBLINEAR include

  • Same data format as LIBSVM, our general-purpose SVM solver, and also similar usage
  • Multi-class classification: 1) one-vs-the rest, 2) Crammer & Singer
  • Cross validation for model evaulation
  • Automatic parameter selection
  • Probability estimates (logistic regression only)
  • Weights for unbalanced data
  • MATLAB/Octave, Java, Python, Ruby interfaces
Multiclass classification with libSvm
1
2
3
4
5
6
7
unzip libsvm.zip 
cd libsvm-3.21/
wget "http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/iris.scale"
more iris.scale 
./svm-train  svm-train iris.scale 
./svm-train   iris.scale 
./svm-predict  iris.scale iris.scale.model iris.scale.output 

预测

1
2
[root@bogon libsvm-3.21]# ./svm-predict  iris.scale iris.scale.model iris.scale.output 
Accuracy = 97.3333% (146/150) (classification)

iris的数据格式,包含3个类的数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
1 1:-0.722222 2:-0.166667 3:-0.864407 4:-0.833333 
1 1:-0.555556 2:0.5 3:-0.79661 4:-0.916667 
1 1:-0.833333 3:-0.864407 4:-0.916667 
1 1:-0.444444 2:0.416667 3:-0.830508 4:-0.916667 
1 1:-0.611111 2:0.0833333 3:-0.864407 4:-0.916667 
2 1:0.5 3:0.254237 4:0.0833333 
2 1:0.166667 3:0.186441 4:0.166667 
2 1:0.444444 2:-0.0833334 3:0.322034 4:0.166667 
2 1:-0.333333 2:-0.75 3:0.0169491 4:-4.03573e-08 
2 1:0.222222 2:-0.333333 3:0.220339 4:0.166667 
2 1:-0.222222 2:-0.333333 3:0.186441 4:-4.03573e-08 
2 1:0.111111 2:0.0833333 3:0.254237 4:0.25 
2 1:-0.666667 2:-0.666667 3:-0.220339 4:-0.25 
2 1:0.277778 2:-0.25 3:0.220339 4:-4.03573e-08 
2 1:-0.5 2:-0.416667 3:-0.0169491 4:0.0833333 
2 1:-0.611111 2:-1 3:-0.152542 4:-0.25 
2 1:-0.111111 2:-0.166667 3:0.0847457 4:0.166667 
2 1:-0.0555556 2:-0.833333 3:0.0169491 4:-0.25 
2 1:-1.32455e-07 2:-0.25 3:0.254237 4:0.0833333 
2 1:-0.277778 2:-0.25 3:-0.118644 4:-4.03573e-08 
2 1:0.333333 2:-0.0833334 3:0.152542 4:0.0833333 
2 1:-0.277778 2:-0.166667 3:0.186441 4:0.166667 
2 1:-0.166667 2:-0.416667 3:0.0508474 4:-0.25 
2 1:0.0555554 2:-0.833333 3:0.186441 4:0.166667 
2 1:-0.277778 2:-0.583333 3:-0.0169491 4:-0.166667 
2 1:-0.111111 3:0.288136 4:0.416667 
2 1:-1.32455e-07 2:-0.333333 3:0.0169491 4:-4.03573e-08 
2 1:0.111111 2:-0.583333 3:0.322034 4:0.166667 
2 1:-1.32455e-07 2:-0.333333 3:0.254237 4:-0.0833333 
2 1:0.166667 2:-0.25 3:0.118644 4:-4.03573e-08 
2 1:0.277778 2:-0.166667 3:0.152542 4:0.0833333 
2 1:0.388889 2:-0.333333 3:0.288136 4:0.0833333 
2 1:0.333333 2:-0.166667 3:0.355932 4:0.333333 
2 1:-0.0555556 2:-0.25 3:0.186441 4:0.166667 
2 1:-0.222222 2:-0.5 3:-0.152542 4:-0.25 
2 1:-0.333333 2:-0.666667 3:-0.0508475 4:-0.166667 
2 1:-0.333333 2:-0.666667 3:-0.0847458 4:-0.25 
2 1:-0.166667 2:-0.416667 3:-0.0169491 4:-0.0833333 
2 1:-0.0555556 2:-0.416667 3:0.38983 4:0.25 
2 1:-0.388889 2:-0.166667 3:0.186441 4:0.166667 
2 1:-0.0555556 2:0.166667 3:0.186441 4:0.25 
2 1:0.333333 2:-0.0833334 3:0.254237 4:0.166667 
2 1:0.111111 2:-0.75 3:0.152542 4:-4.03573e-08 
2 1:-0.277778 2:-0.166667 3:0.0508474 4:-4.03573e-08 
2 1:-0.333333 2:-0.583333 3:0.0169491 4:-4.03573e-08 
2 1:-0.333333 2:-0.5 3:0.152542 4:-0.0833333 
2 1:-1.32455e-07 2:-0.166667 3:0.220339 4:0.0833333 
2 1:-0.166667 2:-0.5 3:0.0169491 4:-0.0833333 
2 1:-0.611111 2:-0.75 3:-0.220339 4:-0.25 
2 1:-0.277778 2:-0.416667 3:0.0847457 4:-4.03573e-08 
2 1:-0.222222 2:-0.166667 3:0.0847457 4:-0.0833333 
2 1:-0.222222 2:-0.25 3:0.0847457 4:-4.03573e-08 
2 1:0.0555554 2:-0.25 3:0.118644 4:-4.03573e-08 
2 1:-0.555556 2:-0.583333 3:-0.322034 4:-0.166667 
2 1:-0.222222 2:-0.333333 3:0.0508474 4:-4.03573e-08 
3 1:0.111111 2:0.0833333 3:0.694915 4:1 
3 1:-0.166667 2:-0.416667 3:0.38983 4:0.5 
3 1:0.555555 2:-0.166667 3:0.661017 4:0.666667 
3 1:0.111111 2:-0.25 3:0.559322 4:0.416667 
3 1:0.222222 2:-0.166667 3:0.627119 4:0.75 
3 1:0.833333 2:-0.166667 3:0.898305 4:0.666667 
3 1:-0.666667 2:-0.583333 3:0.186441 4:0.333333 
3 1:0.666667 2:-0.25 3:0.79661 4:0.416667 
3 1:0.333333 2:-0.583333 3:0.627119 4:0.416667 

预测结果,more iris.scale.output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
This post is licensed under CC BY 4.0 by the author.