| 1 | package Algorithm::LibLinear::Model; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use 5.014; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use Algorithm::LibLinear; # For Algorithm::LibLinear::Model::Raw | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use Algorithm::LibLinear::Types qw/Feature/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Carp qw//; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use Smart::Args::TypeTiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Types::Standard qw/ClassName InstanceOf Int Str/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | my $InstanceOfPackage = InstanceOf[__PACKAGE__]; | |||||||||
| 11 | |||||||||||
| 12 | 5 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 13 | 5 | args | |||||||||
| 14 | my $class => ClassName, | ||||||||||
| 15 | my $raw_model => InstanceOf['Algorithm::LibLinear::Model::Raw']; | ||||||||||
| 16 | |||||||||||
| 17 | 5 | bless +{ raw_model => $raw_model, } => $class; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 3 | ▶ | sub load { | ||||||||
|
Subroutine
load: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 3 | args | |||||||||
| 22 | my $class => ClassName, | ||||||||||
| 23 | my $filename => Str; | ||||||||||
| 24 | |||||||||||
| 25 | 3 | my $raw_model = Algorithm::LibLinear::Model::Raw->load($filename); | |||||||||
| 26 | 2 | $class->new(raw_model => $raw_model); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 3 | ▶ | sub bias { | ||||||||
|
Subroutine
bias: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 30 | 3 | args_pos | |||||||||
| 31 | my $self => $InstanceOfPackage, | ||||||||||
| 32 | my $label => +{ isa => Int, optional => 1, }; | ||||||||||
| 33 | |||||||||||
| 34 | 3 | ▶ | return $self->raw_model->rho if $self->is_oneclass_model; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | # Non one-class SVM model requires label index. | ||||||||||
| 36 | 3 | ▶ | Carp::croak('Missing mandatory label index.') unless defined $label; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 3 | $self->raw_model->bias($label - 1); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 4 | ▶ | sub class_labels { $_[0]->raw_model->class_labels } | ||||||||
|
Subroutine
class_labels: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | |||||||||||
| 43 | 12 | ▶ | sub coefficient { | ||||||||
|
Subroutine
coefficient: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 12 | args_pos | |||||||||
| 45 | my $self => $InstanceOfPackage, | ||||||||||
| 46 | my $feature => Int, | ||||||||||
| 47 | my $label => Int; | ||||||||||
| 48 | |||||||||||
| 49 | 12 | $self->raw_model->coefficient($feature, $label - 1); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 4 | ▶ | sub is_oneclass_model { $_[0]->raw_model->is_oneclass_model } | ||||||||
|
Subroutine
is_oneclass_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 53 | |||||||||||
| 54 | 2 | ▶ | sub is_probability_model { $_[0]->raw_model->is_probability_model } | ||||||||
|
Subroutine
is_probability_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | sub is_regression_model { $_[0]->raw_model->is_regression_model } | ||||||||
|
Subroutine
is_regression_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | 7 | ▶ | sub num_classes { $_[0]->raw_model->num_classes } | ||||||||
|
Subroutine
num_classes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 59 | |||||||||||
| 60 | 3 | ▶ | sub num_features { $_[0]->raw_model->num_features } | ||||||||
|
Subroutine
num_features: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 61 | |||||||||||
| 62 | 1 | ▶ | sub predict { | ||||||||
|
Subroutine
predict: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | 1 | args | |||||||||
| 64 | my $self => $InstanceOfPackage, | ||||||||||
| 65 | my $feature => Feature; | ||||||||||
| 66 | |||||||||||
| 67 | 1 | $self->raw_model->predict($feature); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub predict_probability { | ||||||||
|
Subroutine
predict_probability: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 71 | 0 | args | |||||||||
| 72 | my $self => $InstanceOfPackage, | ||||||||||
| 73 | my $feature => Feature; | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | unless ($self->is_probability_model) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | Carp::carp( | |||||||||
| 77 | 'This method only makes sense when the model is configured for' | ||||||||||
| 78 | . ' classification based on logistic regression.' | ||||||||||
| 79 | ); | ||||||||||
| 80 | } | ||||||||||
| 81 | 0 | $self->raw_model->predict_probability($feature); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 0 | ▶ | sub predict_values { | ||||||||
|
Subroutine
predict_values: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 85 | 0 | args | |||||||||
| 86 | my $self => $InstanceOfPackage, | ||||||||||
| 87 | my $feature => Feature; | ||||||||||
| 88 | |||||||||||
| 89 | 0 | $self->raw_model->predict_values($feature); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 38 | ▶ | sub raw_model { $_[0]->{raw_model} } | ||||||||
|
Subroutine
raw_model: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 93 | |||||||||||
| 94 | 1 | ▶ | sub save { | ||||||||
|
Subroutine
save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 95 | 1 | args | |||||||||
| 96 | my $self => $InstanceOfPackage, | ||||||||||
| 97 | my $filename => Str; | ||||||||||
| 98 | |||||||||||
| 99 | 1 | $self->raw_model->save($filename); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 4 | 1; | |||||||||
| 103 | |||||||||||
| 104 | __DATA__ | ||||||||||