Skip to main content
        _________  _.
.__    |__ |__ | \/ |
|__\__/|   |   |    |
|   /       

A python implementation of Factorization Machines / Field-aware Factorization Machines with a simple interface.

(FFM fully functioning/tested, FM still not fully tested)

Supports classification and regression.

Project Structure

pyffm
 ├── engine
 │   ├── model
 │   │   ├── __init__.py
 │   │   ├── base_model.py
 │   │   ├── ffm_model.py
 │   │   └── fm_model.py
 │   ├── __init__.py
 │   ├── base_engine.py
 │   ├── ffm_engine.py
 │   └── fm_engine.py
 ├── test
 │   ├── data
 │   │   ├── __init__.py
 │   │   ├── bigdata.te.txt
 │   │   ├── bigdata.tr.txt
 │   │   └── small_sample_train.csv
 │   ├── __init__.py
 │   ├── test_ctrengine.py
 │   ├── test_pyffm.py
 │   └── test_utils.py
 ├── __init__.py
 ├── pyffm.py
 └── util.py
LICENSE
README.md
setup.py

Installation:

pip install pyffm

Basic example:

import pandas as pd
from pyffm import PyFFM

training_params = {'epochs': 2, 'reg_lambda': 0.002}
pyffm = PyFFM(model='ffm', training_params=training_params)

from pyffm.test.data import sample_df  # Small training data sample 

# Make sure your file has a label column, default name is 'click' but you can either rename it or pass in label=label_column_name

# Balance the dataset so we get some non-zero predictions (very small training sample)
balanced_df = sample_df[sample_df['click'] == 1].append(sample_df[sample_df['click'] == 0].sample(n=1000)).sample(frac=1)

train_data = balanced_df.sample(frac=0.9)
predict_data = balanced_df.drop(train_data.index)

pyffm.train(train_data)
preds = pyffm.predict(predict_data.drop(columns='click'))

Sample data from:
https://github.com/ycjuan/libffm
and:
https://www.kaggle.com/c/criteo-display-ad-challenge

Created using the algorithm described in the original paper:
https://www.csie.ntu.edu.tw/~cjlin/libffm/

Metadata

Release files for pyFFM 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyFFM 0.0.7
File Size Uploaded
pyFFM-0.0.7.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyFFM 0.0.7
File Interpreter ABI Platform
pyFFM-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 30.4 kB

Release files / pyFFM-0.0.7.tar.gz

Download URL pyFFM-0.0.7.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
53debb6a72c7977f9b29ed2bb9b053d48e08fd023cf99038d5afc32dcfb4f3ed
BLAKE2b-256 checksum
How to use checksums
b01c132ef9f1212b768b5ece043334d8286d8c82e8a8ea3ca63aefd9bf5be201
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

Release files / pyFFM-0.0.7-py3-none-any.whl

Download URL pyFFM-0.0.7-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a352158ef6b15aa6cd4cec232d1503720e4f5ce8a213193890419bdddeca971
BLAKE2b-256 checksum
How to use checksums
34cf9e2a528b5c95b2288565b4ec939bff13f91c2b127c50de002ebf155f8dad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page