📄 readme
字号:
Introduction============Python (http://www.python.org/) is a powerful scripting language whichsupports easy-to-use object-oriented programming and has gained more andmore popularity. This python-to-libsvm interface is developed so users caneasily experiment with libsvm using python.The interface is developed with SWIG, the Simplified Wrapper and InterfaceGenerator (http://www.swig.org/). SWIG can be used to connect librarieswritten in C and C++ to a variety of high-level scripting languages.The original idea and the SWIG interface file was provided by Carl Staelin(staelin@hpl.hp.com) from HP Labs. The interface was integrated into thelibsvm package by Li-lun Wang (llwang@infor.org) from National TaiwanUniversity. Chih-Chung Chang (b4506055@csie.ntu.edu.tw) from NationalTaiwan University also contributed a lot of useful suggestions and help.Installation============The build process for the various Unix systems is as follows:Before you build the module, you need to find out the python includedirectory, which is typically located at /usr/local/include/python2.1 or/usr/include/python. You can set the variable PYTHON_INCLUDEDIR inMakefile manually or use something like the following: make PYTHON_INCLUDEDIR=/usr/include/python allAlthough the interface is generated by SWIG, it is not necessary to haveSWIG installed because the generated svmc_wrap.c is included in this package.If you prefer to generate the interface with SWIG on your own, you can simply remove the generated files with make morecleanbefore building the module.When the build process completes, a shared object called svmc.so will becreated.For win32 systems, the shared library svmc.dll is ready in this package.Usage=====To use the module, the files svm.py and the shared library (namely svmc.soor svmc.dll) must be placed in the current directory, the python librarydirectory, or the directory where the environment variable PYTHONHOMEpoints to. The user then imports everything in svm.py to use libsvm inpython: from svm import *There are three classes in svm.py, namely svm_parameter, svm_problem, andsvm_model.svm_parameter is used to set the parameters of the training process. Theattributes in svm_parameter include svm_type, kernel_type, degree, gamma,coef0, nu, cache_size, C, eps, p, shrinking, and nr_weight. Available svmtypes include C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, and NU_SVR. Availablekernel types include LINEAR, POLY, RBF, and SIGMOID. The user can setup theparameters with the constructor and keyword arguments: param = svm_parameter(kernel_type = LINEAR, C = 10)The user can also modify the parameters later: param.kernel_type = RBFsvm_problem is used to hold the training data for the problem. Theconstructor takes two arguments; the first of them is the list of labels,and the other is the list of samples. For example prob = svm_problem([1,-1],[[1,0,1],[-1,0,-1]])or equivalently prob = svm_problem([1,-1],[{1:1,3:1},{1:-1,3:-1}])Once the parameter and problem are ready, we can construct the model: m = svm_model(prob, param)To predict a new sample with the model: r = m.predict([1, 1, 1])To save the model to a file: m.save('test.model')and to load the model from a file: m = svm_model('test.model')Examples========There are two examples in this package. The one is svm_test.py, and theother is test_cross_validation.py.svm_test.py tests four kernels, i.e., linear, polynomial, RBF, andsigmoid, on the XOR problem with C-SVM.test_cross_validation.py makes use of cross_validation.py which is animplementation of cross validation in python. This example demonstratesloading data from file and does a ten-fold cross validation on theheart_scale dataset.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -