Algorithm-LibLinear
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Algorithm/LibLinear/Model.pm view on Meta::CPAN
package Algorithm::LibLinear::Model;
use 5.014;
use Algorithm::LibLinear; # For Algorithm::LibLinear::Model::Raw
use Algorithm::LibLinear::Types qw/Feature/;
use Carp qw//;
use Smart::Args::TypeTiny;
use Types::Standard qw/ClassName InstanceOf Int Str/;
my $InstanceOfPackage = InstanceOf[__PACKAGE__];
sub new {
args
my $class => ClassName,
my $raw_model => InstanceOf['Algorithm::LibLinear::Model::Raw'];
bless +{ raw_model => $raw_model, } => $class;
}
sub load {
args
my $class => ClassName,
my $filename => Str;
my $raw_model = Algorithm::LibLinear::Model::Raw->load($filename);
$class->new(raw_model => $raw_model);
}
sub bias {
args_pos
my $self => $InstanceOfPackage,
my $label => +{ isa => Int, optional => 1, };
return $self->raw_model->rho if $self->is_oneclass_model;
# Non one-class SVM model requires label index.
Carp::croak('Missing mandatory label index.') unless defined $label;
$self->raw_model->bias($label - 1);
}
sub class_labels { $_[0]->raw_model->class_labels }
sub coefficient {
args_pos
my $self => $InstanceOfPackage,
my $feature => Int,
my $label => Int;
$self->raw_model->coefficient($feature, $label - 1);
}
sub is_oneclass_model { $_[0]->raw_model->is_oneclass_model }
sub is_probability_model { $_[0]->raw_model->is_probability_model }
sub is_regression_model { $_[0]->raw_model->is_regression_model }
sub num_classes { $_[0]->raw_model->num_classes }
sub num_features { $_[0]->raw_model->num_features }
sub predict {
args
my $self => $InstanceOfPackage,
my $feature => Feature;
$self->raw_model->predict($feature);
}
sub predict_probability {
args
my $self => $InstanceOfPackage,
my $feature => Feature;
unless ($self->is_probability_model) {
Carp::carp(
'This method only makes sense when the model is configured for'
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.128 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )