Cornac is a Python Recommender Library

A collection of recommendation algorithms and comparisons
for Easy, Effective and Efficient experiments.

by Preferred.AI

Get Started

Get Started with Cornac

Getting started with Cornac is simple, and you just need to install it first. Please make sure that you have the latest version of pip, and you are using Python 3 (we recommend version >=3.6).


Please run the appropriate Cornac install command according to your platform.

#The wheel (.whl) files are for Python 3.6, please make sure you are on the same Python version.
#Installing PyTorch is required as this dependency is not handled automatically.
pip3 install
pip3 install
pip3 install --process-dependency-links
#PyTorch is required, please follow the instructions at "" to install it on MacOS using conda.
pip install

Your first example

Training and evaluating the Probabilistic Matrix Factorization (PMF) recommender model with Cornac.

#Importing required modules from Cornac.
from cornac.models import Pmf
from cornac.experiment import Experiment
from cornac.evaluation_strategies import Split
from cornac import metrics 

#Importing some additional useful modules.
from import loadmat

#Loading and preparing the Amazon office data (Available in the GitHub repository, inside folder 'data/'). 
office= loadmat("path to office.mat")
mat_office = office['mat']

#Instantiate a pfm recommender model.
#Please refer to the documentation for details on parameter settings.
rec_pmf = Pmf(k=10, max_iter=10, learning_rate=0.001, lamda=0.001, init_params={'U':None,'V':None})

#Instantiate an evaluation strategy.
es_split = Split(data = mat_office, prop_test=0.2, prop_validation=0.0, good_rating=4)

#Instantiate evaluation metrics.
rec = metrics.Recall(m=20)
pre = metrics.Precision(m=20)

#Instantiate and then run an experiment.
res_pmf = Experiment(es_split, [rec_pmf], metrics=[pre,rec])

#Get average results.