AI::Ca...eriment(3pm)

πŸ“¦
version 0.09 Β· 2 versions
, in fedora 43

πŸ’– NAME πŸ’–

AI::Categorizer::Experiment β€” the lil class that coordinates experimental results, aka your categorizer's report card bestie πŸŽ€

This one lives in the perl manual, section 3pm (that's the "user contributed perl documentation" crew, iykyk).


✨ SYNOPSIS ✨

Okay so here's the whole vibe in code:

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

Like, you make an experiment, you feed it hypotheses, and then it literally hands you the receipts πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

So the AI::Categorizer::Experiment class is here to help you organize the results of categorization experiments. It's giving personal assistant energy fr fr.

As you get lots of categorization results (Hypotheses) back from the Learner, you can feed these results to the Experiment class, along with the correct answers. And then β€” when all results have been collected β€” you can get a report on accuracy, precision, recall, F1, and so on, with both macro-averaging and micro-averaging over categories. The way that it just… does all of that for you? Iconic. Periodt. πŸ‘‘


πŸ’… METHODS πŸ’…

The general execution flow when using this class is to create an Experiment object, add a bunch of Hypotheses to it, and then report on the results. That's it, that's the whole storyline πŸ“

Internally, AI::Categorizer::Experiment inherits from Statistics::Contingency. Please see the documentation of Statistics::Contingency for a description of its interface. All of its methods are available here, with the following additions:

  • new( categories => \%categories )
  • new( categories => \@categories, verbose => 1, sig_figs => 2 ) β€” Returns a new Experiment object. A required categories parameter specifies the names of all categories in the data set. The category names may be specified either the keys in a reference to a hash, or as the entries in a reference to an array.

The new() method accepts a verbose parameter which will cause some status/debugging information to be printed to STDOUT when verbose is set to a true value.

A sig_figs indicates the number of significant figures that should be used when showing the results in the results_table() method. It does not affect the other methods like micro_precision().

  • add_result($assigned, $correct, $name) β€” Adds a new result to the experiment. Please see the Statistics::Contingency documentation for a description of this method.
  • add_hypothesis($hypothesis, $correct_categories) β€” Adds a new result to the experiment. The first argument is a AI::Categorizer::Hypothesis object such as one generated by a Learner's categorize() method. The list of correct categories can be given as an array of category names (strings), as a hash whose keys are the category names and whose values are anything logically true, or as a single string if there is only one category. For example, all of the following are legal:
$e->add_hypothesis($h, "sports");
$e->add_hypothesis($h, ["sports", "finance"]);
$e->add_hypothesis($h, {sports => 1, finance => 1});
ngl the flexibility on that last one is so satisfying β€” string, arrayref, hashref, pick your fighter πŸ’€

πŸ‘‘ AUTHOR πŸ‘‘

Ken Williams <ken@mathforum.org>


This distribution is free software; you can redistribute it and/or modify it under the same terms as Perl itself. These terms apply to every file in the distribution β€” if you have questions, please contact the author. 🫢


Okay bye bestie, that's the whole page! πŸ’œ This lil writeup came from the perl v5.42.0 docs, dated 2025-07-25, and it's the AI::Ca...eriment(3pm) page β€” go forth and experiment, you got this ✨🧚

πŸ“¦ where this page comes from