Skip to main content

Python implementation of Factorization Machines (+ Field Aware)

Project description

        _________  _.
.__    |__ |__ | \/ |
|__\__/|   |   |    |
|   /       

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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyFFM-0.0.7.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

pyFFM-0.0.7-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file pyFFM-0.0.7.tar.gz.

File metadata

  • Download URL: pyFFM-0.0.7.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pyFFM-0.0.7.tar.gz
Algorithm Hash digest
SHA256 53debb6a72c7977f9b29ed2bb9b053d48e08fd023cf99038d5afc32dcfb4f3ed
MD5 21fac6781d27b0efe9ee74eb8c02b039
BLAKE2b-256 b01c132ef9f1212b768b5ece043334d8286d8c82e8a8ea3ca63aefd9bf5be201

See more details on using hashes here.

File details

Details for the file pyFFM-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: pyFFM-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pyFFM-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1a352158ef6b15aa6cd4cec232d1503720e4f5ce8a213193890419bdddeca971
MD5 2f4cd2743c502974dcff27d576b133c2
BLAKE2b-256 34cf9e2a528b5c95b2288565b4ec939bff13f91c2b127c50de002ebf155f8dad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page