Algorithm-LibLinear
view release on metacpan or search on metacpan
lib/Algorithm/LibLinear/DataSet.pm view on Meta::CPAN
my $data_set = Algorithm::LibLinear::DataSet->new(data_set => [
+{ feature => +{ 1 => 0.708333, 2 => 1, 3 => 1, ... }, label => 1, },
+{ feature => +{ 1 => 0.583333, 2 => -1, 3 => 0.333333, ... }, label => -1, },
+{ feature => +{ 1 => 0.166667, 2 => 1, 3 => -0.333333, ... }, label => 1, },
...
]);
my $data_set = Algorithm::LibLinear::DataSet->load(fh => \*DATA);
my $data_set = Algorithm::LibLinear::DataSet->load(filename => 'liblinear_file');
my $data_set = Algorithm::LibLinear::DataSet->load(string => "+1 1:0.70833 ...");
say $data_set->size;
say $data_set->as_string; # '+1 1:0.70833 2:1 3:1 ...'
__DATA__
+1 1:0.708333 2:1 3:1 4:-0.320755 5:-0.105023 6:-1 7:1 8:-0.419847 9:-1 10:-0.225806 12:1 13:-1
-1 1:0.583333 2:-1 3:0.333333 4:-0.603774 5:1 6:-1 7:1 8:0.358779 9:-1 10:-0.483871 12:-1 13:1
+1 1:0.166667 2:1 3:-0.333333 4:-0.433962 5:-0.383562 6:-1 7:-1 8:0.0687023 9:-1 10:-0.903226 11:-1 12:-1 13:1
...
=head1 DESCRIPTION
This class represents set of labeled feature vectors used for learning.
lib/Algorithm/LibLinear/FeatureScaling.pm view on Meta::CPAN
);
my $scaled_feature = $scale->scale(feature => +{ 1 => 30, 2 => - 25, ... });
my $scaled_labeled_data = $scale->scale(
labeled_data => +{ feature => +{ 1 => 30, ... }, label => 1 },
);
my $scaled_data_set = $scale->scale(
data_set => Algorithm::LibLinear::DataSet->new(...),
);
say $scale->as_string;
$scale->save(filename => '/path/to/another/file');
=head1 DESCRIPTION
Support vector classification is actually just a calculation of inner product of feature vector and normal vector of separation hyperplane. If some elements in feature vectors have greater dynamic range than others, they can have stronger influence o...
For example, consider a normal vector to be C<{ 1 1 1 }> and feature vectors to be classified are C<{ -2 10 5 }>, C<{ 5 -50 0 }> and C<{ 10 100 10 }>. Inner products of these normal vector and feature vectors are 13, -45 and 120 respectively. Obvious...
To avoid such a problem, normalizing range of elements of feature vectors is very important. This module provides such vector scaling functionality. You can see this is a library version of LIBLINEAR's C<svm-scale> command.
lib/Algorithm/LibLinear/Model.pm view on Meta::CPAN
use Algorithm::LibLinear;
my $data_set = Algorithm::LibLinear::DataSet->load(fh => \*DATA);
my $classifier = Algorithm::LibLinear->new->train(data_set => $data_set);
my $classifier = Algorithm::LibLinear::Model->load(filename => 'trained.model');
my @labels = $classifier->class_labels;
if ($classifier->is_oneclass_model) { ... }
if ($classifier->is_probability_model) { ... }
if ($classifier->is_regression_model) { ... }
say $classifier->num_classes; # == @labels
say $classifier->num_features; # == $data_set->size
for my $label (1 .. $classifier->num_classes) {
print 'Coeffs: ';
print join(' ', map {
$classifier->coefficient($_, $label);
} 1 .. $classifier->num_features);
print "\t";
print 'Bias: ', $classifier->bias($label);
print "\n";
}
( run in 0.436 second using v1.01-cache-2.11-cpan-483215c6ad5 )