Skip to main content

Tensorflow Keras implementation of CORAL ordinal regression output layer, loss, activation, and metrics

Project description

Ordinal regression in Tensorflow Keras

Tensorflow Keras implementation of ordinal regression (aka ordinal classification) using consistent rank logits (CORAL) by Cao, Mirjalili, & Raschka (2019).

This package includes:

  • Ordinal output layer: CoralOrdinal()
  • Ordinal loss function: OrdinalCrossEntropy()
  • Ordinal error metric: MeanAbsoluteErrorLabels()
  • Ordinal activation function: ordinal_softmax()

This is a work in progress, so please post any issues to the issue queue.

Acknowledgments: Many thanks to Sebastian Raschka for the help in porting from the PyTorch source repository.

Key pending items:

  • Function docstrings
  • Docs
  • Tests

Installation

Install the stable version via pip:

pip install coral-ordinal

Install the most recent code on GitHub via pip:

pip install git+https://github.com/ck37/coral-ordinal/

Dependencies

This package relies on Python 3.6+, Tensorflow 2.2+, and numpy.

Example

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(32, activation = "relu"))
model.add(coral.CoralOrdinal(num_classes = 5)) # Ordinal variable has 5 labels, 0 through 4.
model.compile(loss = coral.OrdinalCrossEntropy(), metrics = [coral.MeanAbsoluteErrorLabels])

See this colab notebook for extended examples of ordinal regression with MNIST (multilayer perceptron) and Amazon reviews (universal sentence encoder).

Note that the minimum value of the ordinal variable needs to be 0. If your labeled data ranges from 1 to 5, you will need to subtract 1 so that it is scaled to be 0 to 4.

References

Cao, W., Mirjalili, V., & Raschka, S. (2019). Consistent rank logits for ordinal regression with convolutional neural networks. arXiv preprint arXiv:1901.07884, 6.

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

coral-ordinal-0.1.4.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

coral_ordinal-0.1.4-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file coral-ordinal-0.1.4.tar.gz.

File metadata

  • Download URL: coral-ordinal-0.1.4.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for coral-ordinal-0.1.4.tar.gz
Algorithm Hash digest
SHA256 82c2c506f539d726657a58398451f6c63896ff87fbe4a34c9932c72f5c4ae4fc
MD5 d3647e307a4e460d2061b0e7dbe9fa17
BLAKE2b-256 eae29212b9c8cdb0bd77077547f413639a8905f7ab2c110a3d4ddfa4bc8325a5

See more details on using hashes here.

File details

Details for the file coral_ordinal-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: coral_ordinal-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for coral_ordinal-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c8b7588f8ba9d393b4c38424a083727d4fe991cc4372facf82b36f56ddf0b58f
MD5 86b6f02e352bfe89e9e5f877ee54c41f
BLAKE2b-256 1152a803e362851acf1b938ab9790c94038c3105cf26bf0c9f906883efe574fd

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