Implements a class encapsulating the result of a call to the SVM fit function. A model is used to predict the labels of a new data set.
More...
#include <model.hpp>
|
using | real_type = T |
| The type of the data points: either float or double .
|
|
using | label_type = U |
| The type of the labels: any arithmetic type or std::string .
|
|
using | size_type = std::size_t |
| The unsigned size type.
|
|
template<typename T, typename U = int>
class plssvm::model< T, U >
Implements a class encapsulating the result of a call to the SVM fit function. A model is used to predict the labels of a new data set.
- Template Parameters
-
T | the floating point type of the data (must either be float or double ) |
U | the type of the used labels (must be an arithmetic type or std:string ; default: int ) |
- Examples
- csvm_examples.cpp, and model_examples.cpp.
◆ model() [1/2]
template<typename T , typename U >
Read a previously learned model from the LIBSVM model file filename
.
- Parameters
-
[in] | filename | the model file to read |
- Exceptions
-
◆ model() [2/2]
template<typename T , typename U >
Create a new model using the SVM parameter params
and the data
.
Default initializes the weights, i.e., no weights have currently been learned.
- Note
- This constructor may only be used in the befriended base C-SVM class!
- Parameters
-
[in] | params | the SVM parameters used to learn this model |
[in] | data | the data used to learn this model |
◆ save()
template<typename T , typename U >
void plssvm::model< T, U >::save |
( |
const std::string & |
filename | ) |
const |
Save the model to a LIBSVM model file for later usage.
- Parameters
-
[in] | filename | the file to save the model to |
- Examples
- model_examples.cpp.
◆ num_support_vectors()
template<typename T , typename U = int>
The number of support vectors used in this model.
- Returns
- the number of support vectors (
[[nodiscard]]
)
◆ num_features()
template<typename T , typename U = int>
The number of features of the support vectors used in this model.
- Returns
- the number of features (
[[nodiscard]]
)
◆ get_params()
template<typename T , typename U = int>
Return the SVM parameter that were used to learn this model.
- Returns
- the SVM parameter (
[[nodiscard]]
)
◆ support_vectors()
template<typename T , typename U = int>
◆ labels()
template<typename T , typename U = int>
Returns the labels of the support vectors.
If the labels are present, they can be retrieved as std::vector
using: dataset.labels()->get()
.
- Returns
- the labels (
[[nodiscard]]
)
◆ num_different_labels()
template<typename T , typename U = int>
Returns the number of different labels in this data set.
If the data set contains the labels std::vector<int>{ -1, 1, 1, -1, -1, 1 }
, this function returns 2
. It is the same as: model.different_labels().size()
- Returns
- the number of different labels (
[[nodiscard]]
)
◆ different_labels()
template<typename T , typename U = int>
Returns the different labels of the support vectors.
If the support vectors contain the labels std::vector<int>{ -1, 1, 1, -1, -1, 1 }
, this function returns the labels { -1, 1 }
.
- Returns
- all different labels (
[[nodiscard]]
)
◆ weights()
template<typename T , typename U = int>
The learned weights for the support vectors.
It is of size num_support_vectors()
.
- Returns
- the weights (
[[nodiscard]]
)
◆ rho()
template<typename T , typename U = int>
The bias value after learning.
- Returns
- the bias
rho
([[nodiscard]]
)
◆ w_
template<typename T , typename U = int>
A vector used to speedup the prediction in case of the linear kernel function.
Will be reused by subsequent calls to plssvm::csvm::fit
/plssvm::csvm::score
with the same plssvm::model
.
- Note
- Must be initialized to an empty vector instead of a
nullptr
in order to be passable as const reference.
The documentation for this class was generated from the following file: