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

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

πŸ’– AI::Categorizer::Learner::DecisionTree(3pm) πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation collection, and it's about a Decision Tree Learner β€” yes, a whole little machine that learns by asking a billion tiny yes/no questions and building a tree out of your vibes. let's get into it πŸŽ€


✨ NAME ✨

AI::Categorizer::Learner::DecisionTree β€” it's a Decision Tree Learner, that's literally it, that's the whole job description πŸ¦‹


✨ SYNOPSIS ✨

here's the whole flow, bestie, copy it exactly because code is sacred πŸ’…

use AI::Categorizer::Learner::DecisionTree;

# Here $k is an AI::Categorizer::KnowledgeSet object

my $l = new AI::Categorizer::Learner::DecisionTree(...parameters...);
$l->train(knowledge_set => $k);
$l->save_state('filename');

... time passes ...

$l = AI::Categorizer::Learner->restore_state('filename');
while (my $document = ... ) {  # An AI::Categorizer::Document object
  my $hypothesis = $l->categorize($document);
  print "Best assigned category: ", $hypothesis->best_category, "\n";
}

okay notice the little "... time passes ..." in there? that's not me being cute, that's canonically in the source. the author KNEW. we save our state, we go live our life, we come back, we restore. it's giving main character arc 🌸


✨ DESCRIPTION ✨

so this class implements a Decision Tree machine learner, and it does that by handing off the actual internal work to AI::DecisionTree. she doesn't do the heavy lifting herself, she delegates β€” which is honestly iconic behavior πŸ‘‘


✨ METHODS ✨

this class inherits from the AI::Categorizer::Learner class, so all of its methods are available unless they're explicitly mentioned here. so if you don't see something listed below, bestie, go check the parent class, it's probably there 🫢

✨ new() ✨

Creates a new DecisionTree Learner and returns it. that's it. no cap. she's born ✨

✨ train(knowledge_set => $k) ✨

Trains the categorizer. this is the glow-up phase β€” it prepares her for later use in categorizing documents πŸ’ͺ

the knowledge_set parameter must provide an object of the class AI::Categorizer::KnowledgeSet (or a subclass thereof), and it has to be populated with lots of documents and categories. like, a LOT. don't skimp, she needs the material fr fr.

if you wanna know the details of how to actually build one of those objects, go read AI::Categorizer::KnowledgeSet. this page isn't gonna hold your hand through that part πŸ“

✨ categorize($document) ✨

Returns an AI::Categorizer::Hypothesis object that represents the categorizer's "best guess" about which categories the given document should be assigned to. it's literally her guessing her best guess and honestly? valid.

See AI::Categorizer::Hypothesis for more details on how to use this object β€” because this object has lore of its own 😭

✨ save_state($path) ✨

Saves the categorizer for later use. and surprise, this method is inherited from AI::Categorizer::Storable, so she's not even doing it herself. queen of delegation, again πŸ’…


✨ AUTHOR ✨

Ken Williams, ken@mathforum.org β€” thank you for your service king πŸ«‘πŸ’–


Copyright 2000-2003 Ken Williams. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, open source rights 🌈


✨ SEE ALSO ✨


okay that's the whole page bestie, you ate that. and just so you know where this lore came from: it's perl v5.42.0, dated 2025-07-25, straight from the AI::Categorizer::Learner::DecisionTree(3pm) manual page. go forth and categorize, no cap πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from