How to use the cornac.metrics function in cornac

To help you get started, we’ve selected a few cornac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PreferredAI / cornac / examples / pmf_ratio.py View on Github external
from cornac.models import PMF

# Load the MovieLens 100K dataset
ml_100k = movielens.load_feedback()

# Instantiate an evaluation method.
ratio_split = RatioSplit(data=ml_100k, test_size=0.2, rating_threshold=4.0, exclude_unknowns=False)

# Instantiate a PMF recommender model.
pmf = PMF(k=10, max_iter=100, learning_rate=0.001, lamda=0.001)

# Instantiate evaluation metrics.
mae = cornac.metrics.MAE()
rmse = cornac.metrics.RMSE()
rec_20 = cornac.metrics.Recall(k=20)
pre_20 = cornac.metrics.Precision(k=20)

# Instantiate and then run an experiment.
exp = cornac.Experiment(eval_method=ratio_split,
                        models=[pmf],
                        metrics=[mae, rmse, rec_20, pre_20],
                        user_based=True)
exp.run()
github PreferredAI / cornac / examples / hft_example.py View on Github external
from cornac.data.text import BaseTokenizer

plots, movie_ids = movielens.load_plot()
ml_1m = movielens.load_feedback(variant='1M', reader=Reader(item_set=movie_ids))

# build text module
item_text_modality = TextModality(corpus=plots, ids=movie_ids,
                                  tokenizer=BaseTokenizer(sep='\t', stop_words='english'),
                                  max_vocab=5000, max_doc_freq=0.5)

ratio_split = RatioSplit(data=ml_1m, test_size=0.2, exclude_unknowns=True,
                         item_text=item_text_modality, verbose=True, seed=123)

hft = cornac.models.HFT(k=10, max_iter=40, grad_iter=5, l2_reg=0.001, lambda_text=0.01, vocab_size=5000, seed=123)

mse = cornac.metrics.MSE()

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[hft],
                        metrics=[mse],
                        user_based=False)
exp.run()
github PreferredAI / cornac / examples / c2pf_example.py View on Github external
# Load office ratings and item contexts, see C2PF paper for details
ratings = office.load_feedback()
contexts = office.load_graph()

item_graph_modality = GraphModality(data=contexts)

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

c2pf = C2PF(k=100, max_iter=80, variant='c2pf')

# Evaluation metrics
nDgc = metrics.NDCG(k=-1)
mrr = metrics.MRR()
rec = metrics.Recall(k=20)
pre = metrics.Precision(k=20)

# Instantiate and run your experiment
exp = Experiment(eval_method=ratio_split,
                 models=[c2pf],
                 metrics=[nDgc, mrr, rec, pre])
exp.run()
github PreferredAI / cornac / examples / c2pf_example.py View on Github external
# Load office ratings and item contexts, see C2PF paper for details
ratings = office.load_feedback()
contexts = office.load_graph()

item_graph_modality = GraphModality(data=contexts)

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

c2pf = C2PF(k=100, max_iter=80, variant='c2pf')

# Evaluation metrics
nDgc = metrics.NDCG(k=-1)
mrr = metrics.MRR()
rec = metrics.Recall(k=20)
pre = metrics.Precision(k=20)

# Instantiate and run your experiment
exp = Experiment(eval_method=ratio_split,
                 models=[c2pf],
                 metrics=[nDgc, mrr, rec, pre])
exp.run()
github PreferredAI / cornac / examples / ibpr_example.py View on Github external
from cornac.datasets import movielens
from cornac.eval_methods import RatioSplit
from cornac.models import IBPR

# Load the MovieLens 1M dataset
ml_1m = movielens.load_feedback(variant='1M')

# Instantiate an evaluation method.
ratio_split = RatioSplit(data=ml_1m, test_size=0.2, rating_threshold=1.0,
                         exclude_unknowns=True, verbose=True)

# Instantiate a IBPR recommender model.
ibpr = IBPR(k=10, init_params={'U': None, 'V': None}, verbose=True)

# Instantiate evaluation metrics.
rec_20 = cornac.metrics.Recall(k=20)
pre_20 = cornac.metrics.Precision(k=20)

# Instantiate and then run an experiment.
exp = cornac.Experiment(eval_method=ratio_split,
                        models=[ibpr],
                        metrics=[rec_20, pre_20],
                        user_based=True)
exp.run()
github PreferredAI / cornac / examples / vbpr_tradesy.py View on Github external
from cornac.datasets import tradesy
from cornac.data import ImageModality
from cornac.eval_methods import RatioSplit

features, item_ids = tradesy.load_feature()  # BIG file
item_image_modality = ImageModality(features=features, ids=item_ids, normalized=True)

ratio_split = RatioSplit(data=tradesy.load_feedback(),
                         test_size=0.1, rating_threshold=0.5,
                         exclude_unknowns=True, verbose=True,
                         item_image=item_image_modality)

vbpr = cornac.models.VBPR(k=10, k2=20, n_epochs=50, batch_size=100, learning_rate=0.005,
                          lambda_w=1, lambda_b=0.01, lambda_e=0.0, use_gpu=True)

auc = cornac.metrics.AUC()
rec_50 = cornac.metrics.Recall(k=50)

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[vbpr],
                        metrics=[auc, rec_50])
exp.run()
github PreferredAI / cornac / examples / vbpr_tradesy.py View on Github external
from cornac.data import ImageModality
from cornac.eval_methods import RatioSplit

features, item_ids = tradesy.load_feature()  # BIG file
item_image_modality = ImageModality(features=features, ids=item_ids, normalized=True)

ratio_split = RatioSplit(data=tradesy.load_feedback(),
                         test_size=0.1, rating_threshold=0.5,
                         exclude_unknowns=True, verbose=True,
                         item_image=item_image_modality)

vbpr = cornac.models.VBPR(k=10, k2=20, n_epochs=50, batch_size=100, learning_rate=0.005,
                          lambda_w=1, lambda_b=0.01, lambda_e=0.0, use_gpu=True)

auc = cornac.metrics.AUC()
rec_50 = cornac.metrics.Recall(k=50)

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[vbpr],
                        metrics=[auc, rec_50])
exp.run()