-
Notifications
You must be signed in to change notification settings - Fork 16
/
youtube_test.go
77 lines (70 loc) · 1.87 KB
/
youtube_test.go
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 movielens
import (
"context"
"fmt"
"math/rand"
"testing"
rcmd "github.com/auxten/go-ctr/recommend"
"github.com/auxten/go-ctr/utils"
. "github.com/smartystreets/goconvey/convey"
)
func TestYoutubeDnnOnMovielens(t *testing.T) {
rand.Seed(42)
rcmd.DebugUserId = 429
//rcmd.DebugItemId = 588
var (
movielens = &MovielensRec{
DataPath: "movielens.db",
SampleCnt: 79948,
//SampleCnt: 10000,
}
model rcmd.Predictor
err error
)
Convey("Train youtube Dnn model", t, func() {
yDnnImpl := &YoutubeDnnImpl{
predBatchSize: 100,
batchSize: 200,
epochs: 200,
earlyStop: 20,
}
trainCtx := context.Background()
model, err = rcmd.Train(trainCtx, movielens, yDnnImpl)
So(err, ShouldBeNil)
So(model, ShouldNotBeNil)
})
Convey("Predict youtube Dnn model", t, func() {
testCount := 20600
rows, err := db.Query(
"SELECT userId, movieId, rating, timestamp FROM ratings_test ORDER BY timestamp, userId ASC LIMIT ?", testCount)
So(err, ShouldBeNil)
var (
userId int
itemId int
rating float32
timestamp int64
yTrue []float32
sampleKeys = make([]rcmd.Sample, 0, testCount)
)
for i := 0; rows.Next(); i++ {
err = rows.Scan(&userId, &itemId, &rating, ×tamp)
if err != nil {
t.Errorf("scan error: %v", err)
}
//yTrue.Set(i, 0, BinarizeLabel(rating))
yTrue = append(yTrue, BinarizeLabel32(rating))
sampleKeys = append(sampleKeys, rcmd.Sample{userId, itemId, 0, timestamp})
}
batchPredictCtx := context.Background()
yDnnPred := &dnnPredictor{
PreRanker: movielens,
Predictor: model,
UserBehavior: movielens,
}
yPred, err := rcmd.BatchPredict(batchPredictCtx, yDnnPred, sampleKeys)
So(err, ShouldBeNil)
rocAuc := utils.RocAuc32(yPred.Data().([]float32), yTrue)
rowCount := len(yTrue)
fmt.Printf("rocAuc on test set %d: %f\n", rowCount, rocAuc)
})
}