AI-ML
view release on metacpan or search on metacpan
lib/AI/ML/Expr.pm view on Meta::CPAN
=cut
sub mini_batch {
my ($self, $start, $size, $axis) = @_;
$axis = 0 unless defined $axis; #default
return _bless _mini_batch($self->matrix_id, $start, $size, $axis);
}
=head2 prediction
=cut
sub prediction {
my ($self, %opts) = @_;
my $t = exists $opts{threshold} ? $opts{threshold} : 0.50;
return _bless _predict_binary_classification($self->matrix_id, $t);
}
=head2 precision
=cut
sub precision {
my ($y, $yatt) = @_;
return _precision($y->matrix_id, $yatt->matrix_id);
}
=head2 accuracy
=cut
sub accuracy {
my ($y, $yatt) = @_;
return _accuracy($y->matrix_id, $yatt->matrix_id);
}
=head2 recall
=cut
sub recall {
my ($y, $yatt) = @_;
return _recall($y->matrix_id, $yatt->matrix_id);
}
=head2 f1
=cut
sub f1 {
my ($y, $yatt) = @_;
return _f1($y->matrix_id, $yatt->matrix_id);
}
=head2 plot
=cut
sub plot {
my ($x, $y, $theta, $file) = @_;
my @xdata = $x->vector_to_list();
my @ydata = $y->vector_to_list();
my @thetas = $theta->vector_to_list();
my $f = $thetas[0] . "+" . $thetas[1] . "*x";
#print STDERR "$_\n" for(@xdata);
#rint STDERR "$_\n" for(@ydata);
#print STDERR "$f\n";
#print STDERR "\n\nFILE == $file\n\n";
my $chart = Chart::Gnuplot->new(
output => $file,
title => "Nice one",
xlabel => "x",
ylabel => "y"
);
my $points = Chart::Gnuplot::DataSet->new(
xdata => \@xdata,
ydata => \@ydata,
style => "points"
);
my $func = Chart::Gnuplot::DataSet->new(
func => $f
);
$chart->plot2d($points, $func);
}
=head2 plot_cost
=cut
sub plot_cost{
my ($file, @costs) = @_;
my @iters = (1 .. scalar(@costs));
my $chart = Chart::Gnuplot->new(
output => $file,
title => "Cost",
xlabel => "Iter",
ylabel => "Cost"
);
$chart->png;
my $data = Chart::Gnuplot::DataSet->new(
xdata => \@iters,
ydata => \@costs,
style => "linespoints"
);
$chart->plot2d($data);
}
1;
( run in 0.902 second using v1.01-cache-2.11-cpan-39bf76dae61 )