Skip to content
A Python wrapper for LibFFM
C++ Python Makefile
Branch: master
Clone or download
Pull request Compare This branch is 10 commits ahead, 1 commit behind ycjuan:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ffm Simplify installation by using setuptools.Extension (#13) Jun 16, 2019
.gitignore Simplify installation by using setuptools.Extension (#13) Jun 16, 2019
COPYRIGHT restruct May 28, 2017
Makefile python wrapper started Jun 12, 2017
Makefile.win Windows support Jun 2, 2017
README
README.md
ffm-predict.cpp closing file f_in in ffm-predict.cpp Jun 10, 2017
ffm-train.cpp fix overflow when model size > 2^31 Nov 14, 2017
ffm.cpp get_W function to get model vectors (#11) Dec 19, 2018
ffm.h get_W function to get model vectors (#11) Dec 19, 2018
setup.py Simplify installation by using setuptools.Extension (#13) Jun 16, 2019
timer.cpp restruct May 28, 2017
timer.h restruct May 28, 2017

README.md

Python wrapper for libffm

This is a python wrapped for LibFFM library writen in C++

Installing it:

python setup.py install  # or python setup.py develop

Using it:

import ffm
from sklearn.metrics import roc_auc_score

# prepare the data
# (field, index, value) format

X = [[(1, 2, 1), (2, 3, 1), (3, 5, 1)],
     [(1, 0, 1), (2, 3, 1), (3, 7, 1)],
     [(1, 1, 1), (2, 3, 1), (3, 7, 1), (3, 9, 1)],]

y = [1, 1, 0]

ffm_data = ffm.FFMData(X, y)


# train the model for 10 iterations

n_iter = 10

model = ffm.FFM(eta=0.1, lam=0.0001, k=4)
model.init_model(ffm_data)

for i in range(n_iter):
    print('iteration %d, ' % i, end='')
    model.iteration(ffm_data)

    y_pred = model.predict(ffm_data)
    auc = roc_auc_score(y, y_pred)
    print('train auc %.4f' % auc)


# save the model 
model.save_model('ololo.bin')

# load it to reuse the model
model = ffm.read_model('ololo.bin')
You can’t perform that action at this time.