Documentation

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).

Installation

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

Windows:
#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 http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip3 install https://github.com/PreferredAI/cornac/raw/master/dist/cornac-0.1.0-cp36-cp36m-win_amd64.whl
Linux:      
pip3 install https://github.com/PreferredAI/cornac/archive/master.zip --process-dependency-links
MacOS:   
#PyTorch is required, please follow the instructions at "https://pytorch.org/" to install it on MacOS using conda.
pip install https://github.com/PreferredAI/cornac/archive/master.zip

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 scipy.io 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])
res_pmf.run_()

#Get average results.
res_pmf.res_avg