Solved

Need help on K nearest neighbourhood algorithm with perl

Posted on 2009-05-06
2
298 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
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24323888
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now