⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 experiment.pm

📁 AI::Categorizer is a framework for automatic text categorization. It consists of a collection of Per
💻 PM
字号:
package AI::Categorizer::Experiment;use strict;use Class::Container;use AI::Categorizer::Storable;use Statistics::Contingency;use base qw(Class::Container AI::Categorizer::Storable Statistics::Contingency);use Params::Validate qw(:types);__PACKAGE__->valid_params  (   categories => { type => ARRAYREF|HASHREF },   sig_figs   => { type => SCALAR, default => 4 },  );sub new {  my $package = shift;  my $self = $package->Class::Container::new(@_);    $self->{$_} = 0 foreach qw(a b c d);  my $c = delete $self->{categories};  $self->{categories} = { map {($_ => {a=>0, b=>0, c=>0, d=>0})} 			  UNIVERSAL::isa($c, 'HASH') ? keys(%$c) : @$c			};  return $self;}sub add_hypothesis {  my ($self, $h, $correct, $name) = @_;  die "No hypothesis given to add_hypothesis()" unless $h;  $name = $h->document_name unless defined $name;    $self->add_result([$h->categories], $correct, $name);}sub stats_table {  my $self = shift;  $self->SUPER::stats_table($self->{sig_figs});}1;__END__=head1 NAMEAI::Categorizer::Experiment - Coordinate experimental results=head1 SYNOPSIS use AI::Categorizer::Experiment; my $e = new AI::Categorizer::Experiment(categories => \%categories); my $l = AI::Categorizer::Learner->restore_state(...path...);  while (my $d = ... get document ...) {   my $h = $l->categorize($d); # A Hypothesis   $e->add_hypothesis($h, [map $_->name, $d->categories]); }  print "Micro F1: ", $e->micro_F1, "\n"; # Access a single statistic print $e->stats_table; # Show several stats in table form=head1 DESCRIPTIONThe C<AI::Categorizer::Experiment> class helps you organize theresults of categorization experiments.  As you get lots ofcategorization results (Hypotheses) back from the Learner, you canfeed these results to the Experiment class, along with the correctanswers.  When all results have been collected, you can get a reporton accuracy, precision, recall, F1, and so on, with bothmacro-averaging and micro-averaging over categories.=head1 METHODSThe general execution flow when using this class is to create anExperiment object, add a bunch of Hypotheses to it, and then report onthe results.Internally, C<AI::Categorizer::Experiment> inherits from theC<Statistics::Contingency>.  Please see the documentation ofC<Statistics::Contingency> for a description of its interface.  All ofits methods are available here, with the following additions:=over 4=item new( categories => \%categories )=item new( categories => \@categories, verbose => 1, sig_figs => 2 )Returns a new Experiment object.  A required C<categories> parameterspecifies the names of all categories in the data set.  The categorynames may be specified either the keys in a reference to a hash, or asthe entries in a reference to an array.The C<new()> method accepts a C<verbose> parameter whichwill cause some status/debugging information to be printed toC<STDOUT> when C<verbose> is set to a true value.A C<sig_figs> indicates the number of significant figures that shouldbe used when showing the results in the C<results_table()> method.  Itdoes not affect the other methods like C<micro_precision()>.=item add_result($assigned, $correct, $name)Adds a new result to the experiment.  Please see theC<Statistics::Contingency> documentation for a description of thismethod.=item add_hypothesis($hypothesis, $correct_categories)Adds a new result to the experiment.  The first argument is aC<AI::Categorizer::Hypothesis> object such as one generated by aLearner's C<categorize()> method.  The list of correct categories canbe given as an array of category names (strings), as a hash whose keysare the category names and whose values are anything logically true,or as a single string if there is only one category.  For example, allof the following are legal: $e->add_hypothesis($h, "sports"); $e->add_hypothesis($h, ["sports", "finance"]); $e->add_hypothesis($h, {sports => 1, finance => 1});=back=head1 AUTHORKen Williams <ken@mathforum.org>=head1 COPYRIGHTThis distribution is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.  These terms apply toevery file in the distribution - if you have questions, please contactthe author.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -