# 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 ...

###### Who is Participating?

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
``````
0

Commented:
cosine distance?
0

Commented:
0

FounderAuthor Commented:
I need to find Cosine  Similarity between 2 Strings (Keywords)
0

Commented:
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

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

Commented:
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

FounderAuthor Commented:
Is it possible in form of VB code .. in the meantime I m trying  to  write the code ...
0

FounderAuthor 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.