How to use the cornac.Experiment 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 / cvae_example.py View on Github external
item_text_modality = TextModality(corpus=docs, ids=item_ids,
                                tokenizer=BaseTokenizer(stop_words='english'),
                                max_vocab=8000, max_doc_freq=0.5)

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

cvae = cornac.models.CVAE(z_dim=50, vae_layers=[200, 100], act_fn='sigmoid',
                          input_dim=8000, lr=0.001, batch_size=128, n_epochs=100,
                          lambda_u=1e-4, lambda_v=0.001, lambda_r=10, lambda_w=1e-4,
                          seed=123, verbose=True)

rec_300 = cornac.metrics.Recall(k=300)

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[cvae],
                        metrics=[rec_300])
exp.run()
github PreferredAI / cornac / examples / vaecf_citeulike.py View on Github external
import cornac
from cornac.datasets import citeulike
from cornac.eval_methods import RatioSplit

data = citeulike.load_feedback()

ratio_split = RatioSplit(data=data, test_size=0.2, exclude_unknowns=True,
                         verbose=True, seed=123, rating_threshold=0.5)

vaecf = cornac.models.VAECF(k=10, h=20, n_epochs=100, batch_size=100, learning_rate=0.001, beta=1.0, seed=123)

rec_20 = cornac.metrics.Recall(k=20)
ndcg_20 = cornac.metrics.NDCG(k=20)
auc = cornac.metrics.AUC()

cornac.Experiment(eval_method=ratio_split,
                  models=[vaecf],
                  metrics=[rec_20, ndcg_20, auc],
                  user_based=True).run()
github PreferredAI / cornac / examples / cdr_example.py View on Github external
# build text module
item_text_modality = TextModality(corpus=docs, ids=item_ids,
                                tokenizer=BaseTokenizer(stop_words='english'),
                                max_vocab=8000, max_doc_freq=0.5)

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

cdr = cornac.models.CDR(k=50, autoencoder_structure=[200], max_iter=100, batch_size=128,
                        lambda_u=0.01, lambda_v=0.1, lambda_w=0.0001, lambda_n=5,
                        learning_rate=0.001, vocab_size=8000)

rec_300 = cornac.metrics.Recall(k=300)

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[cdr],
                        metrics=[rec_300])
exp.run()
github PreferredAI / cornac / examples / ibpr_example.py View on Github external
# 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 / bpr_netflix.py View on Github external
import cornac
from cornac.data import Reader
from cornac.datasets import netflix
from cornac.eval_methods import RatioSplit

ratio_split = RatioSplit(data=netflix.load_feedback(variant='small', reader=Reader(bin_threshold=1.0)),
                         test_size=0.1, rating_threshold=1.0,
                         exclude_unknowns=True, verbose=True)

most_pop = cornac.models.MostPop()
bpr = cornac.models.BPR(k=10, max_iter=100, learning_rate=0.001, lambda_reg=0.01, verbose=True)

auc = cornac.metrics.AUC()
rec_20 = cornac.metrics.Recall(k=20)

cornac.Experiment(eval_method=ratio_split,
                  models=[most_pop, bpr],
                  metrics=[auc, rec_20],
                  user_based=True).run()
github PreferredAI / cornac / examples / nmf_example.py View on Github external
eval_method = RatioSplit(data=ml_100k, test_size=0.2, rating_threshold=4.0,
                         exclude_unknowns=True, verbose=True, seed=123)

# Instantiate a NMF recommender model.
nmf = cornac.models.NMF(k=15, max_iter=50, learning_rate=.005,
                        lambda_u=.06, lambda_v=.06, lambda_bu=.02, lambda_bi=.02,
                        use_bias=False, verbose=True, seed=123)

# 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=eval_method,
                        models=[nmf],
                        metrics=[mae, rmse, rec_20, pre_20],
                        user_based=True)
exp.run()
github PreferredAI / cornac / examples / wmf_example.py View on Github external
from cornac.data import Reader
from cornac.datasets import citeulike
from cornac.eval_methods import RatioSplit

_, item_ids = citeulike.load_text()

data = citeulike.load_feedback(reader=Reader(item_set=item_ids))

ratio_split = RatioSplit(data=data, test_size=0.2, exclude_unknowns=True,
                         verbose=True, seed=123, rating_threshold=0.5)

cf = cornac.models.WMF(k=50, max_iter=50, learning_rate=0.001, lambda_u=0.01, lambda_v=0.01, verbose=True, seed=123)

rec_300 = cornac.metrics.Recall(k=300)

cornac.Experiment(eval_method=ratio_split,
                  models=[cf],
                  metrics=[rec_300],
                  user_based=True).run()
github PreferredAI / cornac / examples / conv_mf_example.py View on Github external
plots, movie_ids = movielens.load_plot()
ml_1m = movielens.load_feedback(variant='1M', reader=Reader(item_set=movie_ids))

# build text modality
item_text_modality = TextModality(corpus=plots, ids=movie_ids,
                                  tokenizer=BaseTokenizer(sep='\t', stop_words='english'),
                                  max_vocab=8000, 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)

convmf = cornac.models.ConvMF(n_epochs=5, verbose=True, seed=123)

rmse = cornac.metrics.RMSE()

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[convmf],
                        metrics=[rmse],
                        user_based=True)
exp.run()