[][src]Struct ffsvm::ModelFile

pub struct ModelFile<'a> {
    pub header: Header<'a>,
    pub vectors: Vec<SupportVector>,
}

Parsing result of a model file used to instantiate a DenseSVM or SparseSVM.

Obtaining a model

A model file is produced by libSVM. For details how to produce a model see the top-level FFSVM documentation.

Loading a model

Model are generally produced by parsing a &str using the ModelFile::try_from function:

use ffsvm::*;
use std::convert::TryFrom;

let model_result = ModelFile::try_from(SAMPLE_MODEL);

Should anything be wrong with the model format, an Error will be returned. Once you have your model, you can use it to create a SVM, for example by invoking DenseSVM::try_from(model).

Model format

For FFSVM to load a model, it needs to approximately look like below. Note that you cannot reasonably create this model by hand, it needs to come from libSVM.

svm_type c_svc
kernel_type rbf
gamma 1
nr_class 2
total_sv 3012
rho -2.90877
label 0 1
probA -1.55583
probB 0.0976659
nr_sv 1513 1499
SV
256 0:0.5106233 1:0.1584117 2:0.1689098 3:0.1664358 4:0.2327561 5:0 6:0 7:0 8:1 9:0.1989241
256 0:0.5018305 1:0.0945542 2:0.09242307 3:0.09439687 4:0.1398575 5:0 6:0 7:0 8:1 9:1
256 0:0.5020829 1:0 2:0 3:0 4:0.1393665 5:1 6:0 7:0 8:1 9:0
256 0:0.4933203 1:0.1098869 2:0.1048947 3:0.1069601 4:0.2152338 5:0 6:0 7:0 8:1 9:1

Apart from "one-class SVM" (-s 2 in libSVM) and "precomputed kernel" (-t 4) all generated libSVM models should be supported.

However, note that for the DenseSVM to work, all support vectors (past the SV line) must have strictly increasing attribute identifiers starting at 0, without skipping an attribute. In other words, your attributes have to be named 0:, 1:, 2:, ... n: and not, say, 0:, 1:, 4:, ... n:.

Fields

header: Header<'a>vectors: Vec<SupportVector>

Trait Implementations

impl<'a> Default for ModelFile<'a>[src]

impl<'a> Clone for ModelFile<'a>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> Debug for ModelFile<'a>[src]

impl<'a> TryFrom<&'a str> for ModelFile<'a>[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(input: &str) -> Result<ModelFile, Error>[src]

Parses a string into a SVM model

impl<'a, 'b> TryFrom<&'a ModelFile<'b>> for DenseSVM[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a, 'b> TryFrom<&'a ModelFile<'b>> for SparseSVM[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'a> Send for ModelFile<'a>

impl<'a> Sync for ModelFile<'a>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> Cast for T where
    U: FromCast<T>, 
[src]

impl<T> FromCast for T[src]