📄 readme
字号:
Python-to-libsvm interfaceIntroduction============Python (http://www.python.org/) is a programming language suitable forrapid development. This python-to-libsvm interface is developed so users can easily experiment with libsvm using python. The interface is developed with SWIG, 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.4 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 tohave SWIG installed because the generated svmc_wrap.c is included inthis package (It was generated using SWIG 1.3.21). If you prefergenerating the interface with SWIG on your own, you can simply removethe 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 thedirectory windows/python. You need to copy it to this directory. Thedll file depends on different versions of python, so you may have tore-make it by following the instruction of building windows binariesin libsvm README.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 PYTHONPATHpoints 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 trainingprocess. The attributes in svm_parameter include svm_type,kernel_type, degree, gamma, coef0, nu, cache_size, C, eps, p,shrinking, nr_weight, weight_label, and weight. Available svm typesinclude C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, and NU_SVR. Availablekernel types include LINEAR, POLY, RBF, and SIGMOID. The user cansetup the parameters 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 conduct n-fold cross validation; predicted labels in the validationprocess are returned. target = cross_validation(prob, param, n)To predict a new sample with the model: r = m.predict([1, 1, 1])To obtain decision values of predicting a sample: d = m.predict_values([1, 1, 1]) To predict a new sample and obtain probability estimates;return value is a dict that maps labels to probabilities. prd, prb = m.predict_probability([1, 1, 1]) sample of prd : 1.0 sample of prb : {1:0.6, -1:0.4}To obtain sigma of the probability density function for regression;see ../README for the definition of the function. sigma = m.get_svr_probability()To obtain the probability density function for regression; see../README for the definition of the function. pdf = m.get_svr_pdf() probability = pdf(z)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 various kernels on a three-class problem withC-SVM. It also demonstrates how to obtain decision values andprobability estimates.test_cross_validation.py demonstrates loading data from a file anddoes a ten-fold cross validation on the heart_scale dataset. It makesuse of cross_validation.py which calls the C++ cross validationsubroutine.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -