Skip to content

kabychow/go-cosinesimilarity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Cosine similarity calculation for Golang

GoLang implementation of sklearn.metrics.pairwise.cosine_similarity. It Computes cosine similarity between samples in X and Y. Cosine similarity, or the cosine kernel, computes similarity as the normalized dot product of X and Y:

K(X, Y) = <X, Y> / (||X||*||Y||)

Installation

go get github.com/khaibin/go-cosinesimilarity

Usage

package main

import (
    "fmt"
    "github.com/khaibin/go-cosinesimilarity"
)

func main() {
    x := [][]float64{{1, 2, 3}, {3, 2, 1}}
    y := [][]float64{{1, 3, 4}}
    result := cosinesimilarity.Compute(x, y)
    fmt.Println(result) // [[0.9958705948858224] [0.6813851438692469]]
}

License

MIT

About

Cosine similarity calculation for Golang

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages