Since: 7.0

class SVMModel (View source)

The SVMModel is the end result of the training process. It can be used to classify previously unseen data.

Methods

bool
checkProbabilityModel()

Returns true if the model has probability information

__construct(string $filename = '')

Construct a new SVMModel

array
getLabels()

Get the labels the model was trained on

int
getNrClass()

Returns the number of classes the model was trained with

int
getSvmType()

Get the SVM type the model was trained with

float
getSvrProbability()

Get the sigma value for regression types

bool
load(string $filename)

Load a saved SVM Model

float
predict_probability(array $data)

Return class probabilities for previous unseen data

float
predict(array $data)

Predict a value for previously unseen data

bool
save(string $filename)

Save a model to a file, for later use

Details

bool checkProbabilityModel()

Returns true if the model has probability information

Return Value

bool

Return a boolean value

__construct(string $filename = '')

Construct a new SVMModel

Build a new SVMModel. Models will usually be created from the SVM::train function, but then saved models may be restored directly.

Parameters

string $filename

The filename for the saved model file this model should load.

Exceptions

Throws

array getLabels()

Get the labels the model was trained on

Return an array of labels that the model was trained on. For regression and one class models an empty array is returned.

Return Value

array

Return an array of labels

int getNrClass()

Returns the number of classes the model was trained with

Returns the number of classes the model was trained with, will return 2 for one class and regression models.

Return Value

int

Return an integer number of classes

int getSvmType()

Get the SVM type the model was trained with

Returns an integer value representing the type of the SVM model used, e.g SVM::C_SVC.

Return Value

int

Return an integer SVM type

float getSvrProbability()

Get the sigma value for regression types

For regression models, returns a sigma value. If there is no probability information or the model is not SVR, 0 is returned.

Return Value

float

Returns a sigma value

bool load(string $filename)

Load a saved SVM Model

Parameters

string $filename

The filename of the model.

Return Value

bool

Returns true on success.

Exceptions

SVMException

float predict_probability(array $data)

Return class probabilities for previous unseen data

This function accepts an array of data and attempts to predict the class, as with the predict function. Additionally, however, this function returns an array of probabilities, one per class in the model, which represent the estimated chance of the data supplied being a member of that class. Requires that the model to be used has been trained with the probability parameter set to true.

Parameters

array $data

The array to be classified. This should be a series of key => value pairs in increasing key order, but not necessarily continuous.

Return Value

float

the predicted value. This will be a class label in the case of classification, a real value in the case of regression. Throws SVMException on error

Exceptions

SVMException

float predict(array $data)

Predict a value for previously unseen data

This function accepts an array of data and attempts to predict the class or regression value based on the model extracted from previously trained data.

Parameters

array $data

The array to be classified. This should be a series of key => value pairs in increasing key order, but not necessarily continuous.

Return Value

float

the predicted value. This will be a class label in the case of classification, a real value in the case of regression. Throws SVMException on error

Exceptions

SVMException

bool save(string $filename)

Save a model to a file, for later use

Parameters

string $filename

The file to save the model to.

Return Value

bool

Throws SVMException on error. Returns true on success.

Exceptions

SVMException