Example #1
0
 def test_amazon_office(self):
     random.seed(time.time())
     if random.random() > 0.8:
         ratings = office.load_feedback()
         contexts = office.load_graph()
         self.assertEqual(len(ratings), 53282)
         self.assertEqual(len(contexts), 108466)
Example #2
0
# ============================================================================
"""Fit to and evaluate PCRL [1] on the Office Amazon dataset.
[1] Salah, Aghiles, and Hady W. Lauw. Probabilistic Collaborative Representation Learning\
    for Personalized Item Recommendation. In UAI 2018.
"""

from cornac.data import GraphModality
from cornac.eval_methods import RatioSplit
from cornac.experiment import Experiment
from cornac import metrics
from cornac.models import PCRL
from cornac.datasets import amazon_office as office

# PCRL jointly models user preferences and performs deep item features learning from auxiliary data (e.g., item relations).
# The necessary data can be loaded as follows
ratings = office.load_feedback()
contexts = office.load_graph()

# Instantiate a GraphModality, it make it convenient to work with graph (network) auxiliary information
# For more details, please refer to the tutorial on how to work with auxiliary data
item_graph_modality = GraphModality(data=contexts)

# Define an evaluation method to split feedback into train and test sets
ratio_split = RatioSplit(data=ratings,
                         test_size=0.2,
                         rating_threshold=3.5,
                         exclude_unknowns=True,
                         verbose=True,
                         item_graph=item_graph_modality)

# Instantiate PCRL