Example #1
0
 def test_amazon_office(self):
     random.seed(time.time())
     if random.random() > 0.8:
         ratings = office.load_rating()
         contexts = office.load_context()
         self.assertEqual(len(ratings), 53282)
         self.assertEqual(len(contexts), 108466)
Example #2
0
# limitations under the License.
# ============================================================================
"""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 GraphModule
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

# Load office ratings and item contexts
ratings = office.load_rating()
contexts = office.load_context()

item_graph_module = GraphModule(data=contexts)

ratio_split = RatioSplit(data=ratings,
                         test_size=0.2,
                         rating_threshold=3.5,
                         shuffle=True,
                         exclude_unknowns=True,
                         verbose=True,
                         item_graph=item_graph_module)

pcrl = PCRL(k=100, z_dims=[300], max_iter=300, learning_rate=0.001)

# Evaluation metrics