Algorithm-Kmeanspp

 view release on metacpan or  search on metacpan

inc/Module/Install.pm  view on Meta::CPAN

		open( FH, "< $_[0]"  ) or die "open($_[0]): $!";
	}
	my $string = do { local $/; <FH> };
	close FH or die "close($_[0]): $!";
	return $string;
}

sub _readperl {
	my $string = Module::Install::_read($_[0]);
	$string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
	$string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s;
	$string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg;
	return $string;
}

sub _readpod {
	my $string = Module::Install::_read($_[0]);
	$string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
	return $string if $_[0] =~ /\.pod\z/;
	$string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg;
	$string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg;

sample/sample_kmeanspp.pl  view on Meta::CPAN


use strict;
use warnings;
use FindBin::libs;
use Algorithm::Kmeanspp;

my $kmp = Algorithm::Kmeanspp->new;

# read input documents
# format: id \t key1 \t val1 \t key2 \t val2 \t ...\n
while (my $line = <DATA>) {
    chomp $line;
    my @arr = split /\t/, $line;
    my $id = shift @arr;
    my %vector = @arr;
    $kmp->add_document($id, \%vector);
}

my $num_cluster = 3;
my $num_iter    = 20;
$kmp->do_clustering($num_cluster, $num_iter);

sample/sample_kmeanspp.pl  view on Meta::CPAN


print "\n";
print "Cluster centroids:\n";
foreach my $centroids (@{ $kmp->centroids }) {
    print join "\t", map {
        sprintf "%s:%.4f", $_, $centroids->{$_}
    } keys %{ $centroids };
    print "\n";
}

__DATA__
Alex	Pop	10	R&B	6	Rock	4
Bob	Jazz	8	Reggae	9
Dave	Classic	4	World	4
Ted	Jazz	9	Metal	2	Reggae	6
Fred	Pop	4	Rock	3	Hip-hop	3
Sam	Classic	8	Rock	1

xt/01_podspell.t  view on Meta::CPAN

my $spell_cmd;
foreach my $path (split(/:/, $ENV{PATH})) {
    -x "$path/spell"  and $spell_cmd="spell", last;
    -x "$path/ispell" and $spell_cmd="ispell -l", last;
    -x "$path/aspell" and $spell_cmd="aspell list", last;
}
$ENV{SPELL_CMD} and $spell_cmd = $ENV{SPELL_CMD};
$spell_cmd or plan skip_all => "no spell/ispell/aspell";

$ENV{LANG} = 'C';
add_stopwords(map { split /[\s\:\-]/ } <DATA>);
set_spell_cmd($spell_cmd);
all_pod_files_spelling_ok('lib');

__DATA__
Mizuki Fujisawa
fujisawa@bayon.cc
Algorithm::Kmeanspp
Wikipedia



( run in 0.954 second using v1.01-cache-2.11-cpan-140bd7fdf52 )