1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::;
/// Implemented by [`DenseSVM`](crate::DenseSVM) and [`SparseSVM`](crate::SparseSVM) to predict a [`FeatureVector`].
///
/// # Predicting a label
///
/// To predict a label, first make sure the [`FeatureVector`](crate::FeatureVector) has all features set. Then calling
/// ```
/// use ffsvm::{DenseFeatures, DenseSVM, Predict};
///
/// fn set_features(svm: &DenseSVM, problem: &mut DenseFeatures) {
/// // Predicts the value.
/// svm.predict_value(problem);
/// }
/// ```
/// will update the [`FeatureVector::label`] to correspond to the class label with the highest likelihood.
///
/// # Predicting a label and obtaining probability estimates.
///
/// If the libSVM model was trained with probability estimates FFSVM can not only predict the
/// label, but it can also give information about the likelihood distribution of all classes.
/// This can be helpful if you want to consider alternatives.
///
/// Probabilities are estimated like this:
///
/// ```
/// use ffsvm::{DenseFeatures, DenseSVM, Predict};
///
/// fn set_features(svm: &DenseSVM, features: &mut DenseFeatures) {
/// // Predicts the value.
/// svm.predict_probability(features);
/// }
/// ```
///
/// Predicting probabilities automatically predicts the best label. In addition, [`FeatureVector::probabilities`]
/// will be updated accordingly. The class labels for each probablity entry can be obtained
/// by the SVM's `class_label_for_index` and `class_index_for_label` methods.