Net-MachineLearning-Sample
view release on metacpan or search on metacpan
lib/Net/MachineLearning/Sample.pm view on Meta::CPAN
æ¨¡åæ¯æ¬¡éæºè¯»åä¸ä¸ªå¾çï¼å°æ¯ä¸ªåç´ çå¼è¿è¡åæ¢åï¼ä¸å°ç®æ æ°åç¸ä¼¼ç10项æéåå«ç¸ä¹ã
æåå°æ¯ä¸é¡¹ç¸ä¹çç»æå ææ±æ»ï¼å¾å°å¾çä¸ç®æ æ°åçç¸ä¼¼æ¦çï¼æ°åè¶å¤§ç¸ä¼¼åº¦è¶é«ã
æéåæ°æ¯ä¸ä¸ªJSONæä»¶ï¼ä½äºåºæä»¶åä¸ç®å½ä¸çweights.jsonï¼éè¿get_weights.plè¿ä¸ªèæ¬äº§çã
æ£å¸¸æ¥è¯´ï¼æéåæ°æ¯éè¿å¤§éçå¸¦æ æ³¨å¾çï¼è®ç»åºæ¥çï¼è䏿¯æå·¥è°åçç»æã
è¿è¡æ¹æ³ï¼
1. é¦å
éè¿cpanmå®è£
该模åï¼
$ sudo cpanm Net::MachineLearning::Sample
2. ç¶åéè¿å½ä»¤è¡è¿è¡å³å¯ï¼
$ perl -MNet::MachineLearning::Sample -e 'Net::MachineLearning::Sample->new->run'
input numeric image: 8
my best guess: 8
3. æè
å¨perlç¨åºéè°ç¨ï¼
use Net::MachineLearning::Sample;
my $ml = Net::MachineLearning::Sample->new;
$ml->run;
=head1 SUBROUTINES/METHODS
=head2 new
new the object.
=cut
sub new {
my $class = shift;
bless {},$class;
}
=head2 run
run the model.
=cut
sub run {
my $module_dir = $INC{'Net/MachineLearning/Sample.pm'};
$module_dir =~ s/Sample\.pm$//;
my $ix = int rand(10);
my %scores;
open my $fd,"$module_dir/weights.json" or die $!;
my $json = <$fd>;
close $fd;
my $wht = from_json($json);
my $myImage = newFromPng GD::Image("$module_dir/gray-$ix.png",0);
my $pointer = 0;
for my $column (0..9) {
for my $row (0..9) {
my $index = $myImage->getPixel($row,$column);
for my $num (0..9) {
my $weight = $wht->{$num}->[$pointer];
$scores{$num} += $weight * (255 - $index);
}
$pointer ++;
}
}
my $bestValue;
for (sort {$scores{$b} <=> $scores{$a} } keys %scores) {
$bestValue = $_;
last;
}
print "input numeric image: $ix\n";
print "my best guess: $bestValue\n";
}
=head1 AUTHOR
Ken Peng, C<< <yhpeng at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-net-machinelearning-sample at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-MachineLearning-Sample>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::MachineLearning::Sample
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-MachineLearning-Sample>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Net-MachineLearning-Sample>
=item * CPAN Ratings
( run in 1.413 second using v1.01-cache-2.11-cpan-5b529ec07f3 )