Algorithm-LibLinear
view release on metacpan or search on metacpan
lib/Algorithm/LibLinear/Model.pm view on Meta::CPAN
This class represents a classifier or an estimated function generated as a return value of L<Algorithm::LibLinear>'s C<train> method.
If you have model files generated by LIBLINEAR's C<train> command or this class's C<save> method, you can C<load> them.
=head1 METHOD
Note that the constructor C<new> is B<not> a part of public API. You can get a instance via C<< Algorithm::LibLinaear->train >>. i.e., C<Algorithm::LibLinear> is a factory class.
=head2 load(filename => $path)
Class method. Loads a LIBLINEAR's model file and returns an instance of this class.
=head2 bias([$index])
Returns value of the bias term corresponding to the C<$index>-th class. In case of one-class SVM (i.e., when C<is_oneclass_model> is true,) the C<$index> is ignored.
Recall that a trained model can be represented as a function f(x) = W^t x + b, where W is a F x C matrix, b is a C-sized vector and C and F are the numbers of classes and features, respectively. This method returns b(C<$index>) in this notation.
Note that C<$index> is 1-based, unlike LIBLINEAR's C<get_decfun_bias()> function.
=head2 class_labels
Returns an ArrayRef of class labels, each of them could be returned by C<predict> and C<predict_values>.
=head2 coefficient($feature_index, $label_index)
Returns value of the coefficient of classifier matrix. i.e., W(C<$feature_index>, C<$label_index>) (see C<bias> method description above.)
Be careful that both indices are 1-based just same as C<bias>.
=head2 is_oneclass_model
Returns true if the model is trained for one-class SVM, false otherwise.
=head2 is_probability_model
Returns true if the model is trained for logistic regression, false otherwise.
=head2 is_regression_model
Returns true if the model is trained for support vector regression (SVR), false otherwise.
=head2 num_classes
The number of class labels.
=head2 num_features
The number of features contained in training set.
=head2 predict(feature => $hashref)
In case of classification, returns predicted class label.
In case of regression, returns value of estimated function given feature.
=head2 predict_probabilities(feature => $hashref)
Returns an ArrayRef of probabilities of the feature belonging to corresponding class.
This method will raise an error if the model is not a classifier based on logistic regression (i.e., C<< not $classifier->is_probability_model >>.)
=head2 predict_values(feature => $hashref)
Returns an ArrayRef of decision values of each class (higher is better).
=head2 save(filename => $path)
Writes the model out as a LIBLINEAR model file.
=cut
( run in 0.873 second using v1.01-cache-2.11-cpan-796a6f069b2 )