myFM - Bayesian Factorization Machines in Python/C++

myFM is an unofficial implementation of Bayesian Factorization Machines in Python/C++. Notable features include:

  • Implementation of all corresponding functionalities in libFM MCMC engine (including grouping & relation block)

  • A simpler and faster implementation using Pybind11 and Eigen

  • Gibbs sampling for ordinal regression with probit link function. See the tutorial for its usage.

  • Support variational inference, which converges faster and requires lower memory (but usually less accurate than the Gibbs sampling).

In most cases, you can install the library from PyPI:

pip install myfm

It has an interface similar to sklearn, and you can use them for wide variety of prediction tasks. For example,

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn import metrics

from myfm import MyFMClassifier

dataset = load_breast_cancer()
X = StandardScaler().fit_transform(dataset['data'])
y = dataset['target']

X_train, X_test, y_train, y_test = train_test_split(
   X, y, random_state=42
)
fm = MyFMClassifier(rank=2).fit(X_train, y_train)

print(metrics.roc_auc_score(y_test, fm.predict_proba(X_test)))
# 0.9954

Try out the following examples to see how Bayesian approaches to explicit collaborative filtering are still very competitive (almost unbeaten)!

Details

Indices and tables