Developer Guide and Reference

  • 2021.2
  • 03/26/2021
  • Public Content
Contents

Support Vector Machine Classifier (SVM)

Support Vector Machine (SVM) classification is among popular classification algorithms. It belongs to a family of generalized linear classification problems.

Mathematical formulation

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, typename
Method
= method::by_default, typename
Task
= task::by_default, typename
Kernel
= linear_kernel::descriptor<Float>>
class
descriptor
Template Parameters
  • Float
    – The floating-point type that the algorithm uses for intermediate computations. Can be
    float
    or
    double
    .
  • Method
    – Tag-type that specifies an implementation of algorithm. Can be
    method::thunder
    or
    method::smo
    .
  • Task
    – Tag-type that specifies the type of the problem to solve. Can be or
    task::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
max_iteration_count
The maximum number of iterations LaTex Math image..
Default value
: 100000.
Getter & Setter


std::int64_t get_max_iteration_count() const
auto & set_max_iteration_count(std::int64_t value)

Invariants


max_iteration_count >= 0

std::int64_t
class_count
The number of classes. Used with only.
Default value
: 2.
Getter & Setter


template > std::int64_t get_class_count() const
template > auto & set_class_count(std::int64_t value)

Invariants


class_count >= 2

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() const
auto & set_cache_size(double value)

Invariants


cache_size >= 0.0

double
tau
The parameter of the WSS scheme LaTex Math image..
Default value
: 1e-6.
Getter & Setter


double get_tau() const
auto & set_tau(double value)

Invariants


tau > 0.0

bool
shrinking
A flag that enables the use of a shrinking optimization technique. Used with
method::smo
split-finding method only.
Default value
: true.
Getter & Setter


bool get_shrinking() const
auto & set_shrinking(bool value)

double
epsilon
The epsilon. Used with
task::regression
only.
Default value
: 0.1.
Getter & Setter


template > double get_epsilon() const
template > auto & set_epsilon(double value)

Invariants


epsilon >= 0

double
accuracy_threshold
The threshold LaTex Math image. for the stop condition.
Default value
: 0.0.
Getter & Setter


double get_accuracy_threshold() const
auto & set_accuracy_threshold(double value)

Invariants


accuracy_threshold >= 0.0

const
Kernel &
kernel
The descriptor of kernel function LaTex Math image.. Can be
linear_kernel::descriptor
or or
rbf_kernel::descriptor
.
Getter & Setter


const Kernel & get_kernel() const
auto & set_kernel(const Kernel &kernel)

double
c
The upper bound LaTex Math image. in constraints of the quadratic optimization problem.
Default value
: 1.0.
Getter & Setter


double get_c() const
auto & set_c(double value)

Invariants


c > 0

Method tags
struct
smo
Tag-type that denotes SMO computational method.
struct
thunder
Tag-type that denotes Thunder computational method.
using
by_default
= thunder
Alias tag-type for Thunder computational method.
Task tags
struct
classification
Tag-type that parameterizes entities that are used for solving classification problem.
using
by_default
= classification
Alias tag-type for classification task.
Model
template<typename
Task
= task::by_default>
class
model
Template Parameters
Task
– Tag-type that specifies the type of the problem to solve. Can be or
task::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 &
coeffs
A LaTex Math image. table containing coefficients of Lagrange multiplier.
Default value
: table{}.
Getter & Setter


const table & get_coeffs() const
auto & set_coeffs(const table &value)

const
table &
support_vectors
A LaTex Math image. table containing support vectors. Where LaTex Math image. - number of support vectors.
Default value
: table{}.
Getter & Setter


const table & get_support_vectors() const
auto & set_support_vectors(const table &value)

std::int64_t
first_class_label
The first unique value in class labels. Used with only.
Getter & Setter


std::int64_t get_first_class_label() const
auto & set_first_class_label(std::int64_t value)

double
bias
The bias.
Default value
: 0.0.
Getter & Setter


double get_bias() const
auto & set_bias(double value)

std::int64_t
second_class_label
The second unique value in class labels. Used with only.
Getter & Setter


std::int64_t get_second_class_label() const
auto & set_second_class_label(std::int64_t value)

Training
train(...)
Input
template<typename
Task
= task::by_default>
class
train_input
Template Parameters
Task
– Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification
or
oneapi::dal::svm::task::regression
.
Constructors
train_input
(
const
table &
data
,
const
table &
labels
,
const
table &
weights
= table{})
Creates a new instance of the class with the given
data
,
labels
and
weights
.
Properties
const
table &
labels
The vector of labels LaTex Math image. for the training set LaTex Math image..
Default value
: table{}.
Getter & Setter


const table & get_labels() const
auto & set_labels(const table &value)

const
table &
weights
The vector of weights LaTex Math image. for the training set LaTex Math image..
Default value
: table{}.
Getter & Setter


const table & get_weights() const
auto & set_weights(const table &value)

const
table &
data
The training set LaTex Math image..
Default value
: table{}.
Getter & Setter


const table & get_data() const
auto & set_data(const table &value)

Result
template<typename
Task
= task::by_default>
class
train_result
Template Parameters
Task
– Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification
or
oneapi::dal::svm::task::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 &
coeffs
A LaTex Math image. table containing coefficients of Lagrange multiplier.
Default value
: table{}.
Getter & Setter


const table & get_coeffs() const
auto & set_coeffs(const table &value)

const
table &
support_vectors
A LaTex Math image. table containing support vectors, where LaTex Math image. is the number of support vectors.
Default value
: table{}.
Getter & Setter


const table & get_support_vectors() const
auto & set_support_vectors(const table &value)

double
bias
The bias.
Default value
: 0.0.
Getter & Setter


double get_bias() const
auto & set_bias(double value)

const
table &
support_indices
A LaTex Math image. table containing support indices.
Default value
: table{}.
Getter & Setter


const table & get_support_indices() const
auto & set_support_indices(const table &value)

const
model<Task> &
model
The trained SVM model.
Default value
: model<Task>{}.
Getter & Setter


const model< Task > & get_model() const
auto & set_model(const model< Task > &value)

Operation
template<typename
Descriptor
> svm::train_result
train
(
const
Descriptor &
desc
,
const
svm::train_input &
input
)
Parameters
  • desc
    – SVM algorithm descriptor .
  • input
    – Input data for the training operation
Preconditions


input.data.is_empty == false
input.labels.is_empty == false
input.labels.column_count == 1
input.data.row_count == input.labels.row_count

Inference
infer(...)
Input
template<typename
Task
= task::by_default>
class
infer_input
Template Parameters
Task
– Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification
or
oneapi::dal::svm::task::regression
.
Constructors
infer_input
(
const
model<Task> &
trained_model
,
const
table &
data
)
Creates a new instance of the class with the given
model
and
data
property values.
Properties
const
model<Task> &
model
The trained SVM model.
Default value
: model<Task>{}.
Getter & Setter


const model< Task > & get_model() const
auto & set_model(const model< Task > &value)

const
table &
data
The dataset for inference LaTex Math image..
Default value
: table{}.
Getter & Setter


const table & get_data() const
auto & set_data(const table &value)

Result
template<typename
Task
= task::by_default>
class
infer_result
Template Parameters
Task
– Tag-type that specifies the type of the problem to solve. Can be
oneapi::dal::svm::task::classification
or
oneapi::dal::svm::task::regression
.
Constructors
infer_result
()
Creates a new instance of the class with the default property values.
Properties
const
table &
labels
The LaTex Math image. table with the predicted labels.
Default value
: table{}.
Getter & Setter


const table & get_labels() const
auto & set_labels(const table &value)

const
table &
decision_function
The LaTex Math image. table with the predicted class. Used with
oneapi::dal::svm::task::classification
only. decision function for each observation.
Default value
: table{}.
Getter & Setter


const table & get_decision_function() const
auto & set_decision_function(const table &value)

Operation
template<typename
Descriptor
> svm::infer_result
infer
(
const
Descriptor &
desc
,
const
svm::infer_input &
input
)
Parameters
  • desc
    – SVM algorithm descriptor .
  • input
    – Input data for the inference operation
Preconditions


input.data.is_empty == false

Examples

oneAPI DPC++
Python* with DPC++ support
Batch Processing:

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.