PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
csvm_examples.cpp

A few examples regarding the plssvm::csvm class.

#include "plssvm/core.hpp"
#include <string>
#include <vector>
int main() {
// create a train data set from a file with int labels
const plssvm::data_set<double> train_data_with_label{ "path/to/train/file.libsvm" };
// create a test data set from a file without labels
const plssvm::data_set<double> test_data{ "path/to/test/file.libsvm" };
// create a support vector machine
auto svm = plssvm::make_csvm();
// optional: update a parameter; can also be directly passed to the plssvm::make_csvm function!
svm->set_params(plssvm::kernel_type = plssvm::kernel_function_type::rbf, plssvm::gamma = 0.001);
// fit the support vector machine
const plssvm::model model = svm->fit(train_data_with_label);
// score the learned model
const double model_score = svm->score(model);
// score a new, unseen data set
const double score = svm->score(model, test_data);
//
// Note: the model is NOT bound to a specific support vector machine
//
// explicitly make an OpenCL support vector machine
const plssvm::opencl::csvm opencl_svm{};
// predict labels
const std::vector<int> predicted_labels = opencl_svm.predict(model, test_data);
return 0;
}
std::vector< label_type > predict(const model< real_type, label_type > &model, const data_set< real_type, label_type > &data) const
Predict the labels for the data set using the model.
Definition: csvm.hpp:326
Encapsulate all necessary data that is needed for training or predicting using an SVM.
Definition: data_set.hpp:69
Implements a class encapsulating the result of a call to the SVM fit function. A model is used to pre...
Definition: model.hpp:50
A C-SVM implementation using OpenCL as backend.
Definition: csvm.hpp:42
Core header including all other necessary headers.
std::unique_ptr< csvm > make_csvm(const backend_type backend, Args &&...args)
Create a new C-SVM using the backend type and additional parameter args.
Definition: csvm_factory.hpp:158