Skip to main content

No project description provided

Project description

tf2-fm-zoo

Python package for the factorization machine implementations from tensorflow2_model_zoo.

Acknowledgement

The original implementation for the methods in this repo were done by Ren Zhang who kindly granted permission to use his code for the creation of the package.

Installation

pip install tf2_fm_zoo

Basic Example

import tensorflow as tf
import numpy as np
import pandas as pd

from sklearn.preprocessing import KBinsDiscretizer
from sklearn.datasets import load_boston

from fm_zoo.fm import FactorizationMachine


X, y = load_boston(return_X_y=True)

X = X[:,:3]
y = tf.cast(y, dtype=tf.float32)

kbd = KBinsDiscretizer(n_bins=15, encode="ordinal")

nunique_vals = pd.DataFrame(X).nunique()
X = tf.cast(kbd.fit_transform(X), dtype=tf.int64)

fm = FactorizationMachine(
    feature_cards=tf.cast(nunique_vals, tf.int32), 
    factor_dim=3)

fm.compile(loss=tf.keras.losses.mean_squared_error, optimizer="Adam")
hist = fm.fit(
    X, y, 
    validation_split=0.15, 
    batch_size=16,
    epochs=100,
    callbacks=[
      tf.keras.callbacks.EarlyStopping(patience=10, restore_best_weights=True)
    ])

pd.DataFrame(hist.history).plot(figsize=(15,10))

Supported Models

Model Reference Year
FM Factorization Machines 2010
FFM Field-aware factorization machines for CTR prediction 2016
FNN Deep Learning over Multi-field Categorical Data: A Case Study on User Response Prediction 2016
AFM Attentional Factorization Machines: Learning the Weight of Feature Interactions via Attention Networks 2017
DeepFM DeepFM: A Factorization-Machine based Neural Network for CTR Prediction 2017
NFM Nerual Factorization Machines for Sparse Predictive Analytics 2017
xDeepFM xDeepFM: Combining Explicit and Implicit Feature Interactions for Recommender Systems 2018
AutoInt AutoInt: Automatic Feature Interaction Learning via Self-Attentive Neural Networks 2018
FNFM Field-aware Neural Factorization Machine for Click-Through Rate Prediction 2019

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

tf2_fm_zoo-0.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tf2_fm_zoo-0.1.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file tf2_fm_zoo-0.1.1.tar.gz.

File metadata

  • Download URL: tf2_fm_zoo-0.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for tf2_fm_zoo-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7d0b91380e1f790aa4588e4b1b39f424b6867e0ed6177d9ea7a3e815f6af1292
MD5 7745f28a0cdad5b6c8fc20eb3aff0171
BLAKE2b-256 92b05c732453511046532ac6cb5d6784c54737df79c60361cb516dd1f5f704b6

See more details on using hashes here.

File details

Details for the file tf2_fm_zoo-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tf2_fm_zoo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for tf2_fm_zoo-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 599a616a394e2d4bb5adfa0d533e6c0ace94f2e4761be83ac2c3fb022f8cde3c
MD5 d247d57d3749ed192a9ee7609f246b2d
BLAKE2b-256 da138221526da16f1f0bf403598603727173544b3d834795d0f3a50f48c1107b

See more details on using hashes here.

Supported by

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