Sie sind auf Seite 1von 14

Felomeng Felomeng@live.

cn
libsvmSVM
C-SVM C-SVM

http://www.csie.ntu.edu.tw/~cjlin/libsvm
COPYRIGHT

=================

svm-train
svm-predict
svm-scale

Java
windows exe

Python

===========
to
ols easy.py
easy.py []
tools/README

Felomeng Felomeng@live.cn

============================
Unix makesvm-trainsvm-predict

Makefile Wi
ndows Windows
windows

<label> <index1>:<value1> <index2>:<value2>


.
.
.
\n<label>
<label>one-class SV
M
<index>:<value><index> 1 <
value>

heart_scale
tools/checkdata.pytools/README
svm-train heart_scaleheart_scale.model
heart_scale.t svm-predict heart_scale.t heart_scale.mod
el outputoutput

svm-scale:

svm-toy:

change 12 3
loadsave
run SVM
clear
svm-train
loadsave
12 3[0,1]
make

Felomeng Felomeng@live.cn

Qt Qt

http://www.trolltech.com

GTK+ GTK+ http://www.gtk.org

Windows windows 32
Visual C++ 2G

svm-train

=================
svm-train [] []

-s 0
0 -- C-SVC
1 -- nu-SVC
2 -- one-class SVM
3 -- epsilon-SVR
4 -- nu-SVR
-t 2
0 -- u'*v
1 --(gamma*u'*v + coef0)^degree
2 --exp(-gamma*|u-v|^2)
3 sigmoid tanh(gamma*u'*v + coef0)
4 ()
-d degree degree 3
-g gamma gamma 1/k
-r coef0 coef0 0
-c cost C-SVCepsilon-SVR nu-SVR C 1
-n nu nu-SVCone-class SVM nu-SVR nu 0.5
-p epsilon epsilon-SVR epsilon 0.1
-m MB 100
-e epsilon 0.001
-h 0 1 1
-b SVC SVR 0 1 0
-wi C-SVC i C *C 1
-v nn

Felomeng Felomeng@live.cn

-g k
-v n /
libsvm FAQ

svm-predict

===================
svm-predict []

-b 0 1 0one-class SVM 0
svm-train

svm-predict

svm-scale

=================
svm-scale []

-l x -1
-u x +1
-y y_lower y_uppery y
-s
-r

Felomeng Felomeng@live.cn

=====================
[0,1][-1,+1]
* C-SVC tools
* nu-SVC/one-class-SVM/nu-SVR nu
* -wi
C
*-m

========
> svm-scale -l -1 -u 1 -s range train > train.scale
> svm-scale -r range test > test.scale
[-1,1] range

> svm-train -s 0 -c 5 -t 2 -g 0.5 -e 0.1 data_file


RBF exp(-0.5|u-v|^2)C=10 0.1
> svm-train -s 3 -p 0.1 -t 0 data_file
u'v epsilon=0.1
> svm-train -c 10 -w1 1 -w-1 5 data_file
1 10=1*10-1 50=5*50
> svm-train -s 0 -c 100 -g 0.1 -v 5 data_file
C=100 gamma=0.1
> svm-train -s 0 -b 1 data_file

Felomeng Felomeng@live.cn
> svm-predict -b 1 test_file data_file.model output_file

===================

/
L x1,,xL K(x,y) x y
xi
<label>0:I 1:K(xi,x1)L:K(xi,xL)
x
<label>0:?1:K(x,x1)L:K(x,xL)
xi ID?
0/

15 1:1 2:1 3:1 4:1


45 2:3 4:3
25
3:1
15 1:1

3:1

Felomeng Felomeng@live.cn
15 0:1 1:4 2:6 3:1
45 0:2 1:6 2:18 3:0
25 0:3 1:1 2:0 3:1
15 0:? 1:2 2:0 3:1
?

25 0:3 1:1 2:0 3:1


45 0:2 1:6 2:18 3:0

[K(2,2) K(2,3)] = [18 0]


[K(3,2) K(3,3)] = [0 1]

=============
svm.h C/C++#include s
vm.h svm.cpp svm-train.c
svm-predict.c svm.h LIBSVM_VERSION

-struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_paramet


er *param);

svm_problem
struct svm_problem
{
int l;
double *y;

Felomeng Felomeng@live.cn
struct svm_node **x;
};
ly
x
svm_node

LABEL ATTR1 ATTR2 ATTR3 ATTR4


----- ----- ----- ----- ----- ----1
0
0.1 0.2 0
0
2
0
0.1 0.3 -1.2 0
1
0.4 0
0
0
0
2
0
0.1 0
1.4 0.5
3
-0.1 -0.2 0.1 1.1 0.1

ATTR5

svm_problem
l=5
y -> 1 2 1 2 3
x -> [ ] -> (2,0.1) (3,0.2) (-1,?)
[ ] -> (2,0.1) (3,0.3) (4,-1.2) (-1,?)
[ ] -> (1,0.4) (-1,?)
[ ] -> (2,0.1) (4,1.4) (5,0.5) (-1,?)
[ ] -> (1,-0.1) (2,-0.2) (3,0.1) (4,1.1) (5,0.1) (-1,?)
svm_node
struct svm_node
{
int index;
double value;
};
-1
svm_parameter
struct svm_parameter
{
int svm_type;

Felomeng Felomeng@live.cn
int kernel_type;
int degree;
/* for poly */
double gamma;
/* for poly/rbf/sigmoid */
double coef0; /* for poly/sigmoid */
/* these are for training only */
double cache_size; /* in MB */
double eps; /* stopping criteria */
double C;/* for C_SVC, EPSILON_SVR, and NU_SVR */
int nr_weight;
/* for C_SVC */
int *weight_label; /* for C_SVC */
double* weight;
/* for C_SVC */
double nu;
/* for NU_SVC, ONE_CLASS, and NU_SVR */
double p; /* for EPSILON_SVR */
int shrinking; /* use the shrinking heuristics */
int probability; /* do probability estimates */
};
svm_type C_SVCNU_SVCONE_CLASSEPSILON_SVR NU_SVR
C_SVC:
C-SVM
NU_SVC:
nu-SVM
ONE_CLASS:
one-class-SVM
EPSILON_SVR: epsilon-SVM
NU_SVR:
nu-SVM
kernel_type LINEARPOLYRBFSIGMOID
LINEAR:u'*v
POLY: (gamma*u'*v + coef0)^degree
RBF:
exp(-gamma*|u-v|^2)
SIGMOID: tanh(gamma*u'*v + coef0)
PRECOMPUTED:
cache_size MBC eps
nu-SVC 0.00001 0.001nu nu-SVM
nu-SVR one-class-SVM p epsilon-SVM epsilon e
psilon shirnking = 1 = 0probability = 1
= 0
nr_weightweight_label weight
1

Felomeng Felomeng@live.cn
nr_weight weight_label weight weight[i] weight_label
[i] weight_label[i] weight[i]
nr_weight 0
** svm_model svm_problem svm_train() s
vm_model svm_problem
** svm_train() svm_check_parameter()
-double svm_predict(const struct svm_model *model,
const struct svm_node *x);
x
x
x one-class +1 -1
-void svm_cross_validation(const struct svm_problem *prob,
const struct svm_parameter *param, int nr_fold, double *target);
nr_fold
prob
target
svm_prob svm_train()
-int svm_get_svm_type(const struct svm_model *model);
svm_type svm_type svm.h
-int svm_get_nr_class(const svm_model *model);
one-class 2
-void svm_get_labels(const svm_model *model, int* label)
label one-class
label
-double svm_get_svr_probability(const struct svm_model *model);
sigma>0
= + zz e^(-|z|/sigma)/(2sigma)

Felomeng Felomeng@live.cn

svr 0
-void svm_predict_values(const svm_model *model,
const svm_node *x, double* dec_values)
x
nr_class nr_class*(nr_class-1)/2
dec_values nr_class svm_get_nr_class label[0] vs. label
[1], , label[0] vs. label[nr_class 1], label[1] vs. label[2], , label[nr_class-2] vs. label[nar_cla
ss-1], label svm_get_lables
label[0] x one-class label[0]+1
-1
-double svm_predict_probability(const struct svm_model *model,
const struct svm_node *x, double* prob_estimates);
x
nr_class prob_estimates
nr_class svm_get_nr_class on
e-class prob_estimates svm_predict
-const char *svm_check_parameter(const struct svm_problem *prob,
const struct svm_parameter *param);
svm_train() svm_cross_validation()
NULL
-int svm_check_probability_model(const struct svm_model *model);
+1
0 sv svm_get_svr_probability svm_predict_probability
-int svm_save_model(const char *model_file_name,
const struct svm_model *model);
0-1
-struct svm_model *svm_load_model(const char *model_file_name);

Felomeng Felomeng@live.cn

-void svm_destroy_model(struct svm_model *model);

-void svm_destroy_param(struct svm_parameter *param);

Java

============
java libsvm.jar java
java -classpath libsvm.jar svm_train <>
java -classpath libsvm.jar svm_predict <>
java -classpath libsvm.jar svm_toy <>
java -classpath libsvm.jar svm_scale <>
java 1.55.0
java classes.zip
java
C
public class svm {
public static final int LIBSVM_VERSION=288;
public static svm_model svm_train(svm_problem prob, svm_parameter param);
public static void svm_cross_validation(svm_problem prob, svm_parameter param, int nr_fol
d, double[] target);
public static int svm_get_svm_type(svm_model model);
public static int svm_get_nr_class(svm_model model);
public static void svm_get_labels(svm_model model, int[] label);
public static double svm_get_svr_probability(svm_model model);
public static void svm_predict_values(svm_model model, svm_node[] x, double[] dec_value
s);
public static double svm_predict(svm_model model, svm_node[] x);
public static double svm_predict_probability(svm_model model, svm_node[] x, double[] pro
b_estimates);

Felomeng Felomeng@live.cn
public static void svm_save_model(String model_file_name, svm_model model) throws IOE
xception
public static svm_model svm_load_model(String model_file_name) throws IOException
public static String svm_check_parameter(svm_problem prob, svm_parameter param);
public static int svm_check_probability_model(svm_model model);
}
libsvm
java svm_node[]=-1

windows exe

=========================
windows windows visual C++
1. DOS visual studio libsvm
VC++ C:\Program Files\Microsoft Visual Studio 8.0\VC\bin\vcvars
32.bat
VC++
2.
nmake -f Makefile.win clean all
3. python Python
Makefile.win PYTHON_INC PYTHON_LIB python
nmake -f Makefile.win python
windows\python\svmc.pyd python
Visual C++ FAQ

Felomeng Felomeng@live.cn

======================================================================
======
tools README

Python

================
python README

======================
Chih-Chung Chang Chih-Jen
Lin 2001
http://www.csie.ntu.edu.tw/~cjlin/libsvm
http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf
cjlin@csie.ntu.edu.tw

NSC 89-2213-E-002-013

http://www.csie.ntu.edu.tw/~cjlin/libsvm/acknowledgements

Das könnte Ihnen auch gefallen