-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
77 lines (61 loc) · 2.58 KB
/
Copy pathmain.go
File metadata and controls
77 lines (61 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/kobeld/recommendation/datasource"
"github.com/kobeld/recommendation/filters"
)
func main() {
var (
score float64
person1 = "Lisa"
person2 = "Michael"
)
fmt.Printf("1. Getting score for %s and %s:\n", person1, person2)
score = filters.GetScore(datasource.BoughtItems, person1, person2, filters.EuclideanDistance)
fmt.Printf("Euclidean distance score is: %+v \n", score)
score = filters.GetScore(datasource.BoughtItems, person1, person2, filters.PearsonCorrelation)
fmt.Printf("Pearson Correlation score is: %+v \n", score)
var (
targetPerson = "Toby"
targetMovie = "Superman Returns"
)
fmt.Printf("\n2. Ranking the Critics for %s\n", targetPerson)
personSocres := filters.TopMatches(datasource.BoughtItems, targetPerson, filters.PearsonCorrelation)
for i, ps := range personSocres {
fmt.Printf(" %d) %s: %+v\n", i+1, ps.Name, ps.Score)
}
fmt.Printf("\n3. Getting recommendations for %s\n", targetPerson)
itemScores := filters.GetRecommendations(datasource.BoughtItems, targetPerson, filters.PearsonCorrelation)
for i, ps := range itemScores {
fmt.Printf(" %d) %s: %+v\n", i+1, ps.Name, ps.Score)
}
fmt.Printf("\n4. Matching products for \"%s\"\n", targetMovie)
moviePrefs := filters.TransformPrefs(datasource.BoughtItems)
productScores := filters.TopMatches(moviePrefs, targetMovie, filters.PearsonCorrelation)
for i, ps := range productScores {
fmt.Printf(" %d) %s: %+v\n", i+1, ps.Name, ps.Score)
}
// targetMovie = "Just My Luck"
fmt.Printf("\n5. Getting recommended critics for \"%s\"\n", targetMovie)
itemScores = filters.GetRecommendations(moviePrefs, targetMovie, filters.PearsonCorrelation)
for i, ps := range itemScores {
fmt.Printf(" %d) %s: %+v\n", i+1, ps.Name, ps.Score)
}
fmt.Printf("\n6. Item-based filtering, getting item mapping")
itemMatch := filters.CalculateSimilarItems(moviePrefs, filters.EuclideanDistance)
for key1, value1 := range itemMatch {
fmt.Printf("\n%s: \n", key1)
for key2, value2 := range value1 {
fmt.Printf(" %s: %+v \n", key2, value2)
}
}
userRates := datasource.BoughtItems[targetPerson]
itemScores = filters.GetRecommendationItems(itemMatch, userRates)
fmt.Printf("\n7. Item-based filtering, Getting recommendations for %s\n", targetPerson)
for i, ps := range itemScores {
fmt.Printf(" %d) %s: %+v\n", i+1, ps.Name, ps.Score)
}
bookPrefs := filters.TransformPrefs(datasource.BoughtBooks)
scoreBookAB := filters.PhiCorrelation(bookPrefs["Book A"], bookPrefs["Book B"])
fmt.Printf("\n8. Phi Correlation for ‘%s’ and '%s' is %+v\n", "Book A", "Book B", scoreBookAB)
}