forked from llSourcell/AI_In_Marketing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensorrec_example.py
More file actions
26 lines (21 loc) · 846 Bytes
/
tensorrec_example.py
File metadata and controls
26 lines (21 loc) · 846 Bytes
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
import numpy as np
import tensorrec
# Build the model with default parameters
model = tensorrec.TensorRec()
# Generate some dummy data
interactions, user_features, item_features = tensorrec.util.generate_dummy_data(
num_users=100,
num_items=150,
interaction_density=.05
)
# Fit the model for 5 epochs
model.fit(interactions, user_features, item_features, epochs=5, verbose=True)
# Predict scores for all users and all items
predictions = model.predict(user_features=user_features,
item_features=item_features)
# Calculate and print the recall at 10
r_at_k = tensorrec.eval.recall_at_k(model, interactions,
k=10,
user_features=user_features,
item_features=item_features)
print(np.mean(r_at_k))