Abstract class for different SVM models.
More...
#include <svmmodel.h>
|
SvmParam | param |
|
SyncArray< float_type > | coef |
|
DataSet::node2d | sv |
|
SyncArray< int > | n_sv |
| the number of support vectors for each class
|
|
int | n_total_sv |
| the number of support vectors for all classes
|
|
SyncArray< float_type > | rho |
| the bias term for each binary model
|
|
int | n_classes = 2 |
| the number of classes
|
|
size_t | n_binary_models |
| the number of binary models, equal to \(k(k-1)/2\), where \(k\) is the number of classes
|
|
vector< float_type > | probA |
| be used to predict probability for each binary model
|
|
vector< float_type > | probB |
| be used to predict probability for each binary model
|
|
vector< int > | label |
| only for SVC, maps logical label (0,1,2,...) to real label in dataset (maybe 2,4,5,...)
|
|
Abstract class for different SVM models.
◆ cross_validation()
vector< float_type > SvmModel::cross_validation |
( |
DataSet |
dataset, |
|
|
SvmParam |
param, |
|
|
int |
n_fold |
|
) |
| |
|
virtual |
performing cross-validation. In \(k\)-fold cross_validation, dataset is spilt into \(k\) equal size parts. Then each part is used as testing set, while the remaining \(k-1\) parts are used as training set. The whole dataset will be predicted after \(k\) training and testing.
- Parameters
-
dataset | training dataset |
param | param for cross-validation |
n_fold | the number of fold in cross-validation |
- Returns
- the same structure as predict()
◆ load_from_file()
void SvmModel::load_from_file |
( |
string |
path | ) |
|
|
virtual |
load SvmModel from a file, the file format is the same as LIBSVM. before call this function, one must read the first line of the model file, which contains svm_type. Then construct right SvmModel (SVC, SVR, ...), since SvmModel is an abstract class.
- Parameters
-
path | path and filename of saved model file |
◆ model_setup()
called at the begining of train(), do initialization
- Parameters
-
Reimplemented in SVC.
◆ predict()
vector< float_type > SvmModel::predict |
( |
const DataSet::node2d & |
instances, |
|
|
int |
batch_size |
|
) |
| |
|
virtual |
predict label given instances.
- Parameters
-
instances | instances used |
batch_size | the number of instances to predict parallel, higher value needs more memory |
- Returns
- label (SVC, NuSVC), real number (SVR, NuSVR), {-1,+1} (OneClassSVC)
Reimplemented in SVC, and OneClassSVC.
◆ predict_dec_values()
void SvmModel::predict_dec_values |
( |
const DataSet::node2d & |
instances, |
|
|
SyncArray< float_type > & |
dec_values, |
|
|
int |
batch_size |
|
) |
| const |
predict decision values.
- Parameters
-
[in] | instances | instances used |
[out] | dec_values | decision values predicted, #instances \(times\) n_binary_models array |
[in] | batch_size | the number of instances to predict parallel, higher value needs more memory |
◆ save_to_file()
void SvmModel::save_to_file |
( |
string |
path | ) |
|
|
virtual |
save SvmModel to a file, the file format is the same as LIBSVM
- Parameters
-
path | path and filename of the model file to save |
◆ train()
train model given dataset and param.
- Parameters
-
dataset | training dataset |
param | param for training |
Implemented in SVC, SVR, NuSVR, and OneClassSVC.
◆ coef
coefficients for each support vector, the structure is the same as LIBSVM. The coefficient is equal to \(\alpha_iy_i\) in SVM dual optimization problem. For one-vs-one multi-class decomposition, \(k\) is the number of classes, and \(N_{sv}\) is the number of support vectors. The size of coef is \( (k-1)\times N_{sv}\). Each support vector has at most \(k-1\) coefficients. For each binary classifier \(SVM_{i,j}\), the coefficients locate in: (1) class i, coef[j-1][sv_start[i]...]; (2) class j, coef[i][sv_start[j]...], where sv_start[i] is the start position of support vectors of class i.
◆ sv
DataSet::node2d SvmModel::sv |
|
protected |
support vectors of this model. The support vectors is grouped in classes 0,1,2,.... The sequence of them in each group is as they appear in original dataset. A training instance is saved as a support vector IFF it is a support vector in at least one binary model.
The documentation for this class was generated from the following files:
- include/thundersvm/model/svmmodel.h
- src/thundersvm/model/svmmodel.cpp