https://github.com/golang-infrastructure/go-cosine-similarity
余弦相似度
https://github.com/golang-infrastructure/go-cosine-similarity
similarity
Last synced: about 2 months ago
JSON representation
余弦相似度
- Host: GitHub
- URL: https://github.com/golang-infrastructure/go-cosine-similarity
- Owner: golang-infrastructure
- License: mit
- Created: 2022-12-04T14:38:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-05T15:55:01.000Z (almost 3 years ago)
- Last Synced: 2025-01-18T16:11:01.332Z (9 months ago)
- Topics: similarity
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 余弦相似度
# 一、安装
```bash
go get -u github.com/golang-infrastructure/go-cosine-similarity
```# 二、示例代码
```go
package mainimport (
"fmt"
cosine_similarity "github.com/golang-infrastructure/go-cosine-similarity"
)func main() {
sliceA := []int{1, 1, 2, 1, 1, 1, 0, 0, 0}
sliceB := []int{1, 1, 1, 0, 1, 1, 1, 1, 1}
r, err := cosine_similarity.NumberSliceCosineSimilarityE(sliceA, sliceB)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(r)
// Output:
// 0.7071067811865475
}
```