Cornac is python recommender system library for easy, effective and efficient experiments. Cornac is simple and handy. It is designed from the ground-up to faithfully reflect the standard steps taken by researchers to implement and evaluate personalized recommendation models.
Website | Documentation | Models | Examples | Preferred.AI
Currently, we are supporting Python 3 (version 3.6 is recommended). There are several ways to install Cornac:
- From PyPI (you may need a C++ compiler):
pip3 install cornac
- From Anaconda:
conda install cornac -c qttruong -c pytorch
- From the GitHub source (for latest updates):
pip3 install Cython
git clone https://github.com/PreferredAI/cornac.git
cd cornac
python3 setup.py install
Note:
Additional dependencies required by models are listed here.
Some of the algorithms use OpenMP
to speed up training with multithreading. For OSX users, in order to run those algorithms efficiently, you might need to install gcc
from Homebrew to have an OpenMP compiler, and install Cornac from the source:
brew install gcc | brew link gcc
If you want to utilize your GPUs, you might consider:
- TensorFlow installation instructions.
- PyTorch installation instructions.
- cuDNN (for Nvidia GPUs).
Flow of an Experiment in Cornac
This example will show you how to run your very first experiment.
- Load the MovieLens 100K dataset (will be automatically downloaded if not cached).
from cornac.datasets import movielens
ml_100k = movielens.load_100k()
- Instantiate an evaluation method. Here we split the data based on ratio.
from cornac.eval_methods import RatioSplit
ratio_split = RatioSplit(data=ml_100k, test_size=0.2, rating_threshold=4.0, exclude_unknowns=False)
- Instantiate models that we want to evaluate. Here we use
Probabilistic Matrix Factorization (PMF)
as an example.
import cornac
pmf = cornac.models.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()
Output:
MAE RMSE Recall@20 Precision@20
PMF 0.760277 0.919413 0.081803 0.0462
For more details, please take a look at our examples.
The recommender models supported by Cornac are listed here. Why don't you join us to lengthen the list?
Your contributions at any level of the library are welcome. If you intend to contribute, please:
- Fork the Cornac repository to your own account.
- Make changes and create pull requests.
You can also post bug reports and feature requests in GitHub issues.