[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need help on K nearest neighbourhood algorithm with perl

Posted on 2009-05-06
2
Medium Priority
?
321 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 2000 total points
ID: 24323888
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
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…
Six Sigma Control Plans

649 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