But,I have already do the stem and stop word in advance so I think the code you wrote:sub invert_string { my ($string, $weight, $hash) = @_; $hash->{$_} += $weight for grep { !$StopWords{$_} } @{words(lc($string))}; }
has the same function, is there any difference?my $sentence1 = { wordA => 2, wordB => 1, };
2. If I have hundreds of sentence to make prediction, how can I invert all the sentence into hash variable?
3.I can not quite get the function of the code:
is that true because I do not need to separate the weight of title and contend, so I can ignore this step?sub invert_item { my $item = shift; my %hash; invert_string($item->{title}, 2, \%hash); invert_string($item->{description}, 1, \%hash); return \%hash; }
4.here is the code in the book to train analyzer:
I don't understand the function of:#!/usr/bin/perl use XML::RSS; use Algorithm::NaiveBayes; use Lingua::EN::Splitter qw(words); use Lingua::EN::StopWords qw(%StopWords); my $nb = Algorithm::NaiveBayes->new( ); for my $category (qw(interesting boring)) { my $rss = new XML::RSS; $rss->parsefile("$category.rdf"); $nb->add_instance(attributes => invert_item($_), label => $category) for @{$rss->{'items +'}}; } $nb->train; # Work out all the probabilities
If I have ignore the invert_item step, what should I write to take place of "@{$rss->{'items'}}"my $rss = new XML::RSS; $rss->parsefile("$category.rdf"); $nb->add_instance(attributes => invert_item($_), label => $category) for @{$rss->{'items +'}}; }
5. all the codes you wrote above should be written in one perl document or their have to be written separately and quote each other by name?
Your reply will be surely helpful. Thank you so much!!In reply to Re^2: how to use Algorithm::NaiveBayes module
by agnes
in thread how to use Algorithm::NaiveBayes module
by agnes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |