Support Vector Machine Classifier (SVM)¶
Support Vector Machine (SVM) classification and regression are among popular algorithms. It belongs to a family of generalized linear classification problems.
Operation |
Computational methods |
Programming Interface |
|||
Mathematical formulation¶
Refer to Developer Guide: Support Vector Machine Classifier.
Programming Interface¶
All types and functions in this section are declared in the
oneapi::dal::svm namespace and are available via inclusion of the
oneapi/dal/algo/svm.hpp header file.
Descriptor¶
-
template<typename
Float= float, typenameMethod= method::by_default, typenameTask= task::by_default, typenameKernel= linear_kernel::descriptor<Float>>
classdescriptor¶ - Template Parameters
Float – The floating-point type that the algorithm uses for intermediate computations. Can be
floatordouble.Method – Tag-type that specifies an implementation of algorithm. Can be
method::thunderormethod::smo.Task – Tag-type that specifies the type of the problem to solve. Can be
task::classification,task::nu_classification,task::regression, ortask::nu_regression.
Constructors
-
descriptor(const Kernel &kernel = kernel_t{})¶ Creates a new instance of the class with the given descriptor of the kernel function.
Properties
-
std::int64_t
class_count¶ The number of classes. Used with
task::classificationandtask::nu_classification. Default value: 2.- Getter & Setter
template <typename T = Task, typename None = detail::enable_if_classification_t<T>> std::int64_t get_class_count() consttemplate <typename T = Task, typename None = detail::enable_if_classification_t<T>> auto & set_class_count(std::int64_t value)- Invariants
class_count >= 2
-
double
accuracy_threshold¶ The threshold \(\varepsilon\) for the stop condition. Default value: 0.0.
- Getter & Setter
double get_accuracy_threshold() constauto & set_accuracy_threshold(double value)- Invariants
accuracy_threshold >= 0.0
-
double
c¶ The upper bound \(C\) in constraints of the quadratic optimization problem. Used with
task::classification,task::regression, andtask::nu_regression. Default value: 1.0.- Getter & Setter
template <typename T = Task, typename None = detail::enable_if_c_available_t<T>> double get_c() consttemplate <typename T = Task, typename None = detail::enable_if_c_available_t<T>> auto & set_c(double value)- Invariants
c > 0
-
const Kernel &
kernel¶ The descriptor of kernel function \(K(x, y)\). Can be
linear_kernel::descriptororpolynomial_kernel::descriptororrbf_kernel::descriptororsigmoid_kernel::descriptor.- Getter & Setter
const Kernel & get_kernel() constauto & set_kernel(const Kernel &kernel)
-
double
epsilon¶ The epsilon. Used with
task::regressiononly. Default value: 0.1.- Getter & Setter
template <typename T = Task, typename None = detail::enable_if_epsilon_available_t<T>> double get_epsilon() consttemplate <typename T = Task, typename None = detail::enable_if_epsilon_available_t<T>> auto & set_epsilon(double value)- Invariants
epsilon >= 0
-
double
tau¶ The threshold parameter \(\tau\) for computing the quadratic coefficient. Default value: 1e-6.
- Getter & Setter
double get_tau() constauto & set_tau(double value)- Invariants
tau > 0.0
-
std::int64_t
max_iteration_count¶ The maximum number of iterations \(T\). Default value: 100000.
- Getter & Setter
std::int64_t get_max_iteration_count() constauto & set_max_iteration_count(std::int64_t value)- Invariants
max_iteration_count >= 0
-
double
nu¶ The nu. Used with
task::nu_classificationandtask::nu_regression. Default value: 0.5.- Getter & Setter
template <typename T = Task, typename None = detail::enable_if_nu_task_t<T>> double get_nu() consttemplate <typename T = Task, typename None = detail::enable_if_nu_task_t<T>> auto & set_nu(double value)- Invariants
0 < nu <= 1
-
double
cache_size¶ The size of cache (in megabytes) for storing the values of the kernel matrix. Default value: 200.0.
- Getter & Setter
double get_cache_size() constauto & set_cache_size(double value)- Invariants
cache_size >= 0.0
Method tags¶
Task tags¶
-
struct
classification¶ Tag-type that parameterizes entities that are used for solving classification problem.
-
struct
nu_classification¶ Tag-type that parameterizes entities that are used for solving nu-classification problem.
-
struct
nu_regression¶ Tag-type that parameterizes entities used for solving nu-regression problem.
-
struct
regression¶ Tag-type that parameterizes entities used for solving regression problem.
-
using
by_default= classification¶ Alias tag-type for classification task.
Model¶
-
template<typename
Task= task::by_default>
classmodel¶ - Template Parameters
Task – Tag-type that specifies the type of the problem to solve. Can be
task::classification,task::nu_classification,task::regression, ortask::nu_regression.
Constructors
-
model()¶ Creates a new instance of the class with the default property values.
Public Methods
-
std::int64_t
get_support_vector_count() const¶ The number of support vectors.
Properties
-
const table &
biases¶ A \(class_count*(class_count-1)/2 \times 1\) table for
task::classificationandtask::nu_classificationand a \(1 \times 1\) table fortask::regressionandtask::nu_regressioncontaining constants in decision function.- Getter & Setter
const table & get_biases() constauto & set_biases(const table &value)
-
const table &
coeffs¶ A \(nsv \times class_count - 1\) table for
task::classificationandtask::nu_classificationand a \(nsv \times 1\) table fortask::regressionandtask::nu_regressioncontaining coefficients of Lagrange multiplier. Default value: table{}.- Getter & Setter
const table & get_coeffs() constauto & set_coeffs(const table &value)
-
std::int64_t
second_class_label¶ The second unique value in class labels. Used with
task::classificationandtask::nu_classification.- Getter & Setter
std::int64_t get_second_class_label() consttemplate <typename T = Task, typename None = detail::enable_if_classification_t<T>> auto & set_second_class_label(std::int64_t value)
-
std::int64_t
second_class_response¶ The second unique value in class responses. Used with
task::classificationandtask::nu_classification.- Getter & Setter
std::int64_t get_second_class_response() consttemplate <typename T = Task, typename None = detail::enable_if_classification_t<T>> auto & set_second_class_response(std::int64_t value)
-
std::int64_t
first_class_response¶ The first unique value in class responses. Used with
task::classificationandtask::nu_classification.- Getter & Setter
std::int64_t get_first_class_response() consttemplate <typename T = Task, typename None = detail::enable_if_classification_t<T>> auto & set_first_class_response(std::int64_t value)
-
double
bias¶ The bias. Default value: 0.0.
- Getter & Setter
double get_bias() constauto & set_bias(double value)
-
std::int64_t
first_class_label¶ The first unique value in class labels. Used with
task::classificationandtask::nu_classification.- Getter & Setter
std::int64_t get_first_class_label() consttemplate <typename T = Task, typename None = detail::enable_if_classification_t<T>> auto & set_first_class_label(std::int64_t value)
Training train(...)¶
Input¶
-
template<typename
Task= task::by_default>
classtrain_input¶ - Template Parameters
Task – Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification,oneapi::dal::svm::task::nu_classification,oneapi::dal::svm::task::regression, oroneapi::dal::svm::task::nu_regression.
Constructors
-
train_input(const table &data, const table &responses, const table &weights = table{})¶ Creates a new instance of the class with the given
data,responsesandweights.
Properties
-
const table &
labels¶ The vector of labels \(y\) for the training set \(X\). Default value: table{}.
- Getter & Setter
const table & get_labels() constauto & set_labels(const table &value)
-
const table &
weights¶ The vector of weights \(w\) for the training set \(X\). Default value: table{}.
- Getter & Setter
const table & get_weights() constauto & set_weights(const table &value)
Result¶
-
template<typename
Task= task::by_default>
classtrain_result¶ - Template Parameters
Task – Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification,oneapi::dal::svm::task::nu_classification,oneapi::dal::svm::task::regression, oroneapi::dal::svm::task::nu_regression.
Constructors
-
train_result()¶ Creates a new instance of the class with the default property values.
Public Methods
-
std::int64_t
get_support_vector_count() const¶ The number of support vectors.
Properties
-
const table &
biases¶ A \(class_count*(class_count-1)/2 \times 1\) table for
task::classificationandtask::classificationand \(1 \times 1\) table fortask::regressionandtask::nu_regressioncontaining constants in decision function.- Getter & Setter
const table & get_biases() constauto & set_biases(const table &value)
-
const table &
coeffs¶ A \(nsv \times class_count - 1\) table for
task::classificationandtask::classificationand \(nsv \times 1\) table fortask::regressionandtask::nu_regressioncontaining coefficients of Lagrange multiplier. Default value: table{}.- Getter & Setter
const table & get_coeffs() constauto & set_coeffs(const table &value)
-
const table &
support_indices¶ A \(nsv \times 1\) table containing support indices. Default value: table{}.
- Getter & Setter
const table & get_support_indices() constauto & set_support_indices(const table &value)
-
double
bias¶ The bias. Default value: 0.0.
- Getter & Setter
double get_bias() constauto & set_bias(double value)
Operation¶
-
template<typename
Descriptor>
svm::train_resulttrain(const Descriptor &desc, const svm::train_input &input)¶ - Parameters
desc – SVM algorithm descriptor
svm::descriptor.input – Input data for the training operation
- Preconditions
Inference infer(...)¶
Input¶
-
template<typename
Task= task::by_default>
classinfer_input¶ - Template Parameters
Task – Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification,oneapi::dal::svm::task::nu_classification,oneapi::dal::svm::task::regression, oroneapi::dal::svm::task::nu_regression.
Constructors
-
infer_input(const model<Task> &trained_model, const table &data)¶ Creates a new instance of the class with the given
modelanddataproperty values.
Properties
Result¶
-
template<typename
Task= task::by_default>
classinfer_result¶ - Template Parameters
Task – Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification,oneapi::dal::svm::task::nu_classification,oneapi::dal::svm::task::regression, oroneapi::dal::svm::task::nu_regression.
Constructors
-
infer_result()¶ Creates a new instance of the class with the default property values.
Properties
-
const table &
labels¶ The \(n \times 1\) table with the predicted labels. Default value: table{}.
- Getter & Setter
const table & get_labels() constauto & set_labels(const table &value)
-
const table &
responses¶ The \(n \times 1\) table with the predicted responses. Default value: table{}.
- Getter & Setter
const table & get_responses() constauto & set_responses(const table &value)
-
const table &
decision_function¶ The \(n \times 1\) table with the predicted class. Used with
oneapi::dal::svm::task::classificationandoneapi::dal::svm::task::nu_classification. decision function for each observation. Default value: table{}.- Getter & Setter
const table & get_decision_function() consttemplate <typename T = Task, typename None = detail::enable_if_classification_t<T>> auto & set_decision_function(const table &value)
Operation¶
-
template<typename
Descriptor>
svm::infer_resultinfer(const Descriptor &desc, const svm::infer_input &input)¶ - Parameters
desc – SVM algorithm descriptor
svm::descriptor.input – Input data for the inference operation
- Preconditions
input.data.is_empty == false
Examples¶
Batch Processing:
Batch Processing:
Batch Processing: