Calculate the Jaccard Similarity Coefficient.
Set::Jaccard::SimilarityCoefficient - Calculate the Jaccard Similarity Coefficient of 2 sets
# VERSION
$res = Set::Jaccard::SimilarityCoefficient::calc(\@set_a, \@set_b);
OR
my $a = Set::Scalar->new(@set_a); my $b = Set::Scalar->new(@set_b); $res = Set::Jaccard::SimilarityCoefficient::calc($a, $b);
Set::Jaccard::SimilarityCoefficient lets you calculate the Jaccard Similarity Coefficient for either arrayrefs or Set::Scalar objects.
Briefly, the Jaccard Similarity Coefficient is a simple measure of how similar 2 sets are. The calculation is (in pseudo-code):
count(difference(SET-A, SET-B)) / count(union(SET-A, SET-B))
There is a Jaccard Similarity Coefficient routine already in CPAN, but it is specialized for use by Text::NSP. I wanted a generic routine that could be used by anyone so Set::Jaccard::SimilarityCoefficient was born.
calc(A, B) calculates the Jaccard Similarity Coefficient for the arguments A and B. A and B can be either array references or Set::Scalar objects.
new() will complain if A or B is empty, not either a reference to an array, or not a Set::Scalar object.
calc() could theoretically throw DivideByZeroException when the union of the two sets has 0 members. However, that would require set A or set B to have 0 members, which was previously prohibited by the prohibition on empty sets.
This module should work wherever Perl works.
Set::Scalar
None that I know of.
There are no bugs that I know of. Given that this is non-trivial code, there will be bugs.
The types of arguments are limited to either array references or Set::Scalar objects.
Mark Leighton Fisher, <markleightonfisher@gmail.com>
Set::JaccardSimilarityCoefficient is licensed under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Unknown directive: =function
To install Set::Jaccard::SimilarityCoefficient, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Set::Jaccard::SimilarityCoefficient
CPAN shell
perl -MCPAN -e shell install Set::Jaccard::SimilarityCoefficient
For more information on module installation, please visit the detailed CPAN module installation guide.