Solved

Need help on K nearest neighbourhood algorithm with perl

Posted on 2009-05-06
2
307 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python algorithm 20 157
PHP Loan Calculation formula help. 8 82
Ned Perl Snippet to Read Files in Directory 5 74
read an xml file in perl 2 51
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
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…

821 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