Data::CosineSimilarity - Compute the Cosine Similarity
$cs = Data::CosineSimilarity->new; $cs->add( label1 => { feature1 => 3, feature2 => 1, feature3 => 10 } ); $cs->add( label2 => ... ); $cs->add( label3 => ... ); # computes the cosine similarity my $r = $cs->similarity( 'label1', 'label2' ); # the result object my $cosine = $r->cosine; my $radian = $r->radian; my $degree = $r->degree; my ($label1, $label2) = $r->labels; # computes all the cosine similarity between 'label1' and the others. my @all = $cs->all_for_label('label1'); # computes all, and returns the best my ($best_label, $r) = $cs->best_for_label('label2'); # computes all, and returns the worst my ($worst_label, $r) = $cs->worst_for_label('label2');
Compute the cosine similarities between a set of vectors.
If all the feature vectors are normed then the computation of the cosine becomes just the dot product of the vectors. In this case, specify the option normed => 1, the performance will be greatly improved.
Antoine Imbert, <antoine.imbert at gmail.com>
<antoine.imbert at gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::CosineSimilarity, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::CosineSimilarity
CPAN shell
perl -MCPAN -e shell install Data::CosineSimilarity
For more information on module installation, please visit the detailed CPAN module installation guide.