update
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func cosine(x, y []int) float64 {
|
||||
var dotProduct, normX, normY float64
|
||||
for i := 1; i < len(x); i++ {
|
||||
dotProduct += float64(x[i] * y[i])
|
||||
normX += float64(x[i] * x[i])
|
||||
normY += float64(y[i] * y[i])
|
||||
}
|
||||
return dotProduct / (math.Sqrt(normX) * math.Sqrt(normY))
|
||||
}
|
||||
|
||||
func main() {
|
||||
history := [][]int{
|
||||
{1, 0, 1, 0},
|
||||
{0, 1, 0, 1},
|
||||
{1, 0, 1, 1},
|
||||
}
|
||||
|
||||
productCategory := [][]int{
|
||||
{1, 1, 0, 0},
|
||||
{0, 0, 0, 1},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 1, 1},
|
||||
{0, 1, 0, 0},
|
||||
|
||||
{0, 1, 1, 1},
|
||||
{1, 1, 1, 0},
|
||||
{0, 0, 0, 1},
|
||||
{1, 1, 1, 1},
|
||||
}
|
||||
|
||||
// Calculate similarity between first search and each product
|
||||
for i, product := range productCategory {
|
||||
sim := cosine(history[0], product)
|
||||
fmt.Printf("Similarity with product %d: %f\n", i, sim)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ const pool = mysql.createPool({
|
||||
host: "localhost",
|
||||
user: "root",
|
||||
database: "marketplace",
|
||||
password: "12345678",
|
||||
});
|
||||
|
||||
//Export a promise for promise-based query
|
||||
|
||||
Reference in New Issue
Block a user