How to Find Cosine Distance in VB.NET

I m trying to find similar web services using Cosine Distance Classifier


Kindly help me find a code script in VB to do so ...


Puneet AroraFounderAsked:
Who is Participating?
 
TommySzalapskiConnect With a Mentor Commented:
Well, if you want code, you'll need to give some more detail. Do you have the vectors already? How are you choosing what keywords to use? Is it a static list?
The code for the formula would look something like this:
Function CosineSimilarity(v1, v2)

Dim numer As Integer
Dim denom1 As Double, denom2 As Double
'v1 and v2 are the vectors of the counts of keywords

numer = 0
denom1 = 0
denom2 = 0

For i = 1 To N 'N is the size of the vector
  numer = numer + v1[i]*v2[i]
  denom1 = denom1 + v1[i]*v1[i]
  denom2 = denom2 + v2[i]*v2[i]
Next

CosineSimilarity = 1 - number/(sqrt(denom1)*sqrt(denom2))
End Function

Open in new window

0
 
NiyasCommented:
cosine distance?
are you asking about polar coordinates?
0
 
NiyasCommented:
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Puneet AroraFounderAuthor Commented:
I need to find Cosine  Similarity between 2 Strings (Keywords)  
0
 
TommySzalapskiCommented:
It depends on what you are concerned with. Generally you need to map your strings to a vector of some kind. Then run them through the formula above (except do it as a loop).

Since you said 'keyword' I assume you want to get the vector by counting how many times each word or keyword appears in the page. Since you are dealing with whole numbers only, you won't need the abs
So get the dot product of the two vectors and divide it by the root sum of squares as you see above.
0
 
TommySzalapskiConnect With a Mentor Commented:
Niyas, you should cite sources when you copy information off the internet (and also make sure you are not violating any licensing).
http://reference.wolfram.com/mathematica/ref/CosineDistance.html
0
 
TommySzalapskiCommented:
Note: cosine distance is kind of a misnomer. Cosine similarity is (I think) a better term since a low number means not similar at all and 1 means identical.
0
 
Puneet AroraFounderAuthor Commented:
Is it possible in form of VB code .. in the meantime I m trying  to  write the code ...
0
 
Puneet AroraFounderAuthor Commented:
Yes I have vectors ready also.. and I have implemented the solution , real thanks for the solution in VB code : Which I wanted ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.