Algorithm-ContextVector
view release on metacpan or search on metacpan
the complete feature set if omitted.
$class->new_from_file( $filename )
Returns the instance of Algorithm::ContextVector stored in $filename.
$self->save_to_file( $filename )
Save the $self to $filename using Storable.
$self->add_instance( label => [ ... ], attributes => { ... } )
$self->train
Keeps the best features (top N) and norms the vectors.
$self->predict( attributes => { ... } )
Returns a hashref with the labels as the keys and the cosines as the
values.
AUTHOR
Antoine Imbert, "<antoine.imbert at gmail.com>"
LICENSE AND COPYRIGHT
This library is free software; you can redistribute it and/or modify it
lib/Algorithm/ContextVector.pm view on Meta::CPAN
my $count = scalar keys %$features;
my $cut = $sum / $count; # hum cut at the avg
for (keys %$features) {
delete $features->{$_} if $features->{$_} < $cut;
}
return $features;
}
=head2 $self->train
Keeps the best features (top N) and norms the vectors.
=cut
sub train {
my $self = shift;
for $_ (keys %{ $self->{labels} }) {
$self->{labels}{$_}{features} = $self->_cut_features( $self->{labels}{$_}{features} );
$self->{labels}{$_}{features} = $self->_norm_features( $self->{labels}{$_}{features} );
}
}
( run in 0.329 second using v1.01-cache-2.11-cpan-4e96b696675 )