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 nDgc = metrics.NDCG(k=-1) rec = metrics.Recall(k=20) pre = metrics.Precision(k=20) # Instantiate and run your experiment exp = Experiment(eval_method=ratio_split, models=[pcrl], metrics=[nDgc, rec, pre]) exp.run() """ Output: | NDCG@-1 | Recall@20 | Precision@20 | Train (s) | Test (s) ---- + ------- + --------- + ------------ + --------- + -------- pcrl | 0.1922 | 0.0862 | 0.0148 | 2591.4878 | 4.0957 *Results may change slightly from one run to another due to different random initial parameters """
from cornac.metrics import MAE, RMSE, Precision, Recall, NDCG, AUC, MAP from cornac.eval_methods import PropensityStratifiedEvaluation from cornac.experiment import Experiment # Load the MovieLens 1M dataset ml_dataset = cornac.datasets.movielens.load_feedback(variant="1M") # Instantiate an instance of PropensityStratifiedEvaluation method stra_eval_method = PropensityStratifiedEvaluation( data=ml_dataset, n_strata=2, # number of strata rating_threshold=4.0, verbose=True) # define the examined models models = [ WMF(k=10, seed=123), BPR(k=10, seed=123), ] # define the metrics metrics = [MAE(), RMSE(), Precision(k=10), Recall(k=10), NDCG(), AUC(), MAP()] # run an experiment exp_stra = Experiment(eval_method=stra_eval_method, models=models, metrics=metrics) exp_stra.run()