libsvm-2.2
所属分类 :Windows编程
开发工具 :Visual C++
文件大小 :217KB
下载次数 :19
上传日期 :2006-03-24 21:12:28
上 传 者 :
jiangb
说明: libsvm-2.2.rar,由c++编写,上传共享,多多交流 (libsvm- 2.2.rar, c++, upload sharing, many exchanges)
文件列表 :
libsvm-2.2 (0, 2001-02-27) libsvm-2.2\java (0, 2001-02-27) libsvm-2.2\svm-toy (0, 2001-02-27) libsvm-2.2\svm-toy\gtk (0, 2001-02-27) libsvm-2.2\svm-toy\qt (0, 2001-02-27) libsvm-2.2\svm-toy\windows (0, 2001-02-27) libsvm-2.2\windows (0, 2001-02-27) libsvm-2.2\COPYRIGHT (1498, 2001-01-13) libsvm-2.2\heart_scale (26960, 2001-02-27) libsvm-2.2\java\libsvm.jar (33451, 2001-01-15) libsvm-2.2\java\Makefile (441, 2001-01-12) libsvm-2.2\java\svm.java (38378, 2001-01-15) libsvm-2.2\java\svm.m4 (37830, 2001-01-15) libsvm-2.2\java\svm_model.java (538, 2001-01-12) libsvm-2.2\java\svm_node.java (67, 2000-12-01) libsvm-2.2\java\svm_parameter.java (887, 2001-01-03) libsvm-2.2\java\svm_predict.java (1556, 2001-01-13) libsvm-2.2\java\svm_problem.java (88, 2000-12-01) libsvm-2.2\java\svm_toy.java (10224, 2001-01-15) libsvm-2.2\java\svm_train.java (4603, 2001-01-15) libsvm-2.2\java\test_applet.html (81, 2000-12-01) libsvm-2.2\Makefile (424, 2001-01-12) libsvm-2.2\scale.c (3832, 2001-02-27) libsvm-2.2\svm-predict.c (1680, 2001-01-13) libsvm-2.2\svm-toy\gtk\callbacks.cpp (8996, 2001-01-15) libsvm-2.2\svm-toy\gtk\callbacks.h (1765, 2000-06-28) libsvm-2.2\svm-toy\gtk\interface.c (6457, 2000-06-28) libsvm-2.2\svm-toy\gtk\interface.h (203, 2000-06-28) libsvm-2.2\svm-toy\gtk\main.c (398, 2000-06-28) libsvm-2.2\svm-toy\gtk\Makefile (519, 2000-04-21) libsvm-2.2\svm-toy\gtk\svm-toy.glade (6402, 2000-06-28) libsvm-2.2\svm-toy\qt\Makefile (423, 2000-06-30) libsvm-2.2\svm-toy\qt\svm-toy.cpp (9141, 2001-01-15) libsvm-2.2\svm-toy\windows\svm-toy.cpp (10092, 2001-01-15) libsvm-2.2\svm-train.c (4566, 2001-01-15) libsvm-2.2\svm.cpp (39066, 2001-01-16) libsvm-2.2\svm.h (1140, 2001-01-12) libsvm-2.2\windows\scale.exe (45056, 2001-02-27) libsvm-2.2\windows\svmpredict.exe (61440, 2001-01-16) ... ...
Libsvm is a simple, easy-to-use, and efficient software for SVM
classification and regression. It can solve C-SVM classification,
nu-SVM classification, one-class-SVM, epsilon-SVM regression,
and nu-SVM regression. This document explains the use of libsvm.
Libsvm is available at
http://www.csie.ntu.edu.tw/~cjlin/libsvm
Please read the COPYRIGHT file before using libsvm.
Installation
============
On Unix systems, type `make' to build the `svm-train' and `svm-predict'
programs. Run them without arguments to show the usages of them.
On other systems, consult `Makefile' to build them or use the pre-built
binaries (Windows binaries are in the subdirectory `windows').
The format of training and testing data file is:
: : ...
.
.
.
is the target value of the training data. For classification,
it should be an integer which identifies a class (multi-class classification
is supported). For regression, it's any real number. For one-class SVM,
it's not used so can be any number. is an integer starting from 1,
is a real number. The labels in the testing data file are only used to
calculate accuracy or error. If they are unknown, just fill this column with a
number.
There is a sample training data for classification in this package:
heart_scale.
Type `./svm-train heart_scale', and the program will read the training
data and output the model file `heart_scale.model'. Then you can
type `./svm-predict heart_scale heart_scale.model output' to see the
rate of classification on training data. The `output' file contains
the prediction value of the model.
There are some other useful programs in this package.
scale:
This is a tool for scaling input data file.
Type `make scale' to build it.
svm-toy:
This is a simple graphical interface which shows how SVM
separate data in a plane. You can click in the window to
draw data points. Use "change" button to choose class
1 or 2, "load" button to load data from a file, "save" button
to save data to a file, "run" button to obtain an SVM model,
and "clear" button to clear the window.
You can enter options in the bottom of the window, the syntax of
options is the same as `svm-train'.
Type `make' in respective directories to build them.
You need Qt library to build the Qt version.
(You can download it from http://www.trolltech.com)
You need GTK+ library to build the GTK version.
(You can download it from http://www.gtk.org)
We use Visual C++ to build the Windows version.
The pre-built Windows binaries are in the windows subdirectory.
`svm-train' Usage
=================
Usage: svm-train [options] training_set_file [model_file]
options:
-s svm_type : set type of SVM (default 0)
0 -- C-SVC
1 -- nu-SVC
2 -- one-class SVM
3 -- epsilon-SVR
4 -- nu-SVR
-t kernel_type : set type of kernel function (default 2)
0 -- linear
1 -- polynomial: (gamma*u'*v + coef0)^degree
2 -- radial basis function: exp(-gamma*|u-v|^2)
3 -- sigmoid: tanh(gamma*u'*v + coef0)
-d degree : set degree in kernel function (default 3)
-g gamma : set gamma in kernel function (default 1/k)
-r coef0 : set coef0 in kernel function (default 0)
-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
-m cachesize : set cache memory size in MB (default 40)
-e epsilon : set tolerance of termination criterion (default 0.001)
-h shrinking: whether to use the shrinking heuristics, 0 or 1 (default 1)
Tips on practical use
=====================
* Scale your data. For example, scale each attribute to [0,1] or [-1,+1].
* For C-SVC, try small and large C, like 1 to 1000 and decide which are
better for your data. For the better C's, try several gamma's.
* nu in nu-SVC/one-class-SVM/nu-SVR approximates the fraction of training
errors and support vectors. For regression, nu-SVR may be easier to use
than epsilon-SVR.
Examples
=============
> svm-train -s 0 -c 1000 -t 1 -g 1 -r 1 -d 3 data_file
Train a classifier with polynomial kernel (u'v+1)^3 and C = 1000
> svm-train -s 1 -n 0.1 -t 2 -g 0.5 -e 0.00001 data_file
Train a classifier by nu-SVM (nu = 0.1) with RBF kernel
exp(-0.5|u-v|^2) and stopping tolerance 0.00001
> svm-train -s 3 -p 0.1 -t 0 -c 10 data_file
Solve SVM regression with linear kernel u'v and C=10, and epsilon = 0.1
in the loss function.
Library Usage
=============
These functions and structures are declared in the header file `svm.h'.
You need to #include "svm.h" in your C/C++ source files and link your
program with `svm.cpp'. You can see `svm-train.c' and `svm-predict.c'
for examples showing how to use them.
Before you classify test data, you need to construct an SVM model
(`svm_model') using training data. A model can also be saved in
a file for later use. Once an SVM model is available, you can use it
to classify new data.
- Function: struct svm_model *svm_train(const struct svm_problem *prob,
const struct svm_parameter *param);
This function constructs and returns an SVM model according to
the given training data and parameters.
struct svm_problem describes the problem:
struct svm_problem
{
int l;
double *y;
struct svm_node **x;
};
where `l' is the number of training data, and `y' is an array containing
their target values. (integers in classification, real numbers in
regression) `x' is an array of pointers, each of which points to a sparse
representation (array of svm_node) of one training vector.
For example, if we have the following training data:
LABEL ATTR1 ATTR2 ATTR3 ATTR4 ATTR5
----- ----- ----- ----- ----- -----
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
then the components of svm_problem are:
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,?)
where (index,value) is stored in the structure `svm_node':
struct svm_node
{
int index;
double value;
};
index = -1 indicates the end of one vector.
struct svm_parameter describes the parameters of an SVM model:
struct svm_parameter
{
int svm_type;
int kernel_type;
double 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
double nu; // for NU_SVC, ONE_CLASS, and NU_SVR
double p; // for EPSILON_SVR
int shrinking; // use the shrinking heuristics
};
svm_type can be one of C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR.
C_SVC: C-SVM classification
NU_SVC: nu-SVM classification
ONE_CLASS: one-class-SVM
EPSILON_SVR: epsilon-SVM regression
NU_SVR: nu-SVM regression
kernel_type can be one of LINEAR, POLY, RBF, SIGMOID.
LINEAR: u'*v
POLY: (gamma*u'*v + coef0)^degree
RBF: exp(-gamma*|u-v|^2)
SIGMOID: tanh(gamma*u'*v + coef0)
cache_size is the size of the kernel cache, specified in megabytes.
C is the cost of constraints violation. (we usually use 1 to 1000)
eps is the stopping criterion. (we usually use 0.00001 in nu-SVC,
0.001 in others). nu is the parameter in nu-SVM, nu-SVR, and
one-class-SVM. p is the epsilon in epsilon-insensitive loss function
of epsilon-SVM regression. shrinking = 1 means shrinking is conducted;
= 0 otherwise.
*NOTE* Because svm_model contains pointers to svm_problem, you can
not free the memory used by svm_problem if you are still using the
svm_model produced by svm_train().
- Function: double svm_predict(const struct svm_model *model,
const struct svm_node *x);
This function does classification or regression on a test vector x
given a model.
For a classification model, the predicted class for x is returned.
For a regression model, the function value of x calculated using
the model is returned. For one-class model, +1 or -1 is returned.
- Function: int svm_save_model(const char *model_file_name,
const struct svm_model *model);
This function saves a model to a file; returns 0 on success, or -1
if an error occurs.
- Function: struct svm_model *svm_load_model(const char *model_file_name);
This function returns a pointer to the model read from the file,
or a null pointer if the model could not be loaded.
- Function: void svm_destroy_model(struct svm_model *model);
This function frees the memory used by a model.
Java version
============
The precompiled java class archive `libsvm.jar' and its source files are
in the java subdirectory. To run the programs, use
java -classpath libsvm.jar svm_train
java -classpath libsvm.jar svm_predict
java -classpath libsvm.jar svm_toy
We have tried IBM's and Sun's JDK.
You may need to add Java runtime library (like classes.zip) to the classpath.
You may need to increase maximum Java heap size.
Library usages are similar to the C version. These functions are available:
public class svm {
public static svm_model svm_train(svm_problem prob, svm_parameter param);
public static double svm_predict(svm_model model, svm_node[] x);
public static void svm_save_model(String model_file_name, svm_model model) throws IOException
public static svm_model svm_load_model(String model_file_name) throws IOException
}
Note that in Java version, svm_node[] is not ended with a node whose index = -1.
ADDITIONAL INFORMATION
============
Chih-Chung Chang and Chih-Jen Lin
LIBSVM 2.0: Solving Different Support Vector Formulations.
http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm2.ps.gz
Chih-Chung Chang and Chih-Jen Lin
Libsvm: Introduction and Benchmarks
http://www.csie.ntu.edu.tw/~cjlin/papers/q2.ps.gz
Acknowledgments:
This work was supported in part by the National Science
Council of Taiwan via the grant NSC 89-2213-E-002-013.
The authors thank Chih-Wei Hsu and Jen-Hao Lee
for many helpful discussions and comments.
近期下载者 :
相关文件 :
收藏者 :