AI-Perceptron-Simple

 view release on metacpan or  search on metacpan

lib/AI/Perceptron/Simple.pm  view on Meta::CPAN

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
sub train {
    my $self = shift;
    my( $stimuli_train_csv, $expected_output_header, $save_nerve_to_file, $display_stats, $identifier ) = @_;
     
    $display_stats = 0 if not defined $display_stats;
    if ( $display_stats and not defined $identifier ) {
        croak "Please specifiy a string for \$identifier if you are trying to display stats";
    }
     
    # CSV processing is all according to the documentation of Text::CSV
    open my $data_fh, "<:encoding(UTF-8)", $stimuli_train_csv
        or croak "Can't open $stimuli_train_csv: $!";
     
    my $csv = Text::CSV->new( {auto_diag => 1, binary => 1} );
     
    my $attrib = $csv->getline($data_fh);
    $csv->column_names( $attrib );
 
    # individual row
    ROW: while ( my $row = $csv->getline_hr($data_fh) ) {
        # print $row->{book_name}, " -> ";

lib/AI/Perceptron/Simple.pm  view on Meta::CPAN

745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
This is where the filling in of the predicted values takes place. Take note that the parameters naming are the same as the ones used in the C<validate> and C<test> method.
 
This subroutine should be called in the procedural way.
 
=cut
 
sub _fill_predicted_values {
    my ( $self, $stimuli_validate, $predicted_index, $aoa ) = @_;
 
    # CSV processing is all according to the documentation of Text::CSV
    open my $data_fh, "<:encoding(UTF-8)", $stimuli_validate
        or croak "Can't open $stimuli_validate: $!";
     
    my $csv = Text::CSV->new( {auto_diag => 1, binary => 1} );
     
    my $attrib = $csv->getline($data_fh);
     
    $csv->column_names( $attrib );
 
    # individual row
    my $row = 0;

lib/AI/Perceptron/Simple.pm  view on Meta::CPAN

858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
my $actual_header = $info->{ actual_output_header };
my $predicted_header = $info->{ predicted_output_header };
my $more_stats = defined ( $info->{ more_stats } ) ? 1 : 0;
 
my %c_matrix = (
    true_positive => 0, true_negative => 0, false_positive => 0, false_negative => 0,
    accuracy => 0, sensitivity => 0
);
 
# CSV processing is all according to the documentation of Text::CSV
open my $data_fh, "<:encoding(UTF-8)", $file
    or croak "Can't open $file: $!";
 
my $csv = Text::CSV->new( {auto_diag => 1, binary => 1} );
 
my $attrib = $csv->getline($data_fh); # get the row of headers, can't specify any column
# shouldn't be a problem, since we're reading line by line :)
 
$csv->column_names( $attrib );
 
# individual row



( run in 0.384 second using v1.01-cache-2.11-cpan-95122f20152 )