Solved

Need help on K nearest neighbourhood algorithm with perl

Posted on 2009-05-06
2
312 Views
Last Modified: 2012-06-27
Can anyone explain each line of the code below and what does it do.
And from the code below i'm hoping to modify it so that it can determine which email is spam or which is not. If i m not mistaken it uses the K nearest neighbourhood algorithm to determine the difference. thx,

p.s. I have attached a sample of spam and non spam email text file to show their difference.
use Search::VectorSpace;
 
# These are just some simple sample documents
my @docs = (
	"The cat in the hat",
	"A cat is a fine pet.",
	"Dogs and cats make good pets.");
 
# Build our search engine, with a suitable threshold	
my $engine = Search::VectorSpace->new( docs => \@docs, threshold=>'0.1');
 
# Index the documents
$engine->build_index();
 
# Answer queries
print "Next query?\n";
while ( my $query = <> ) {
    my %results = $engine->search( $query );
    foreach my $result ( sort { $results{$b} <=> $results{$a} } keys %results ) {
        print "Relevance: ", $results{$result}, "\n";
        print $result, "\n\n";
    }
    print "Next query?\n";
}

Open in new window

spam.txt
0
Comment
Question by:ychet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24323888
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Six Sigma Control Plans
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question