Skip to main content

Kernel FDA implementation described in https://arxiv.org/abs/1906.09436

Project description

Kernel FDA

PyPI version

This repository implements Kernel Fisher Discriminant Analysis (Kernel FDA) as described in https://arxiv.org/abs/1906.09436. FDA, equivalent to Linear Discriminant Analysis (LDA), is a classification method that projects vectors onto a smaller subspace. This subspace is optimized to maximize between-class scatter and minimize within class scatter, making it an effective classification method. Kernel FDA improves on regular FDA by enabling nonlinear subspaces using the kernel trick.

FDA and Kernel FDA classify vectors by comparing their projection in the fisher subspace to class centroids, adding a new class is just a matter of adding a new centroid. Thus, this model is implemented here with the hope of using Kernel FDA as a oneshot learning algorithm.

Usage

Kfda uses scikit-learn's interface.

  • Initializing: cls = Kfda(n_components=2, kernel='linear') for a classifier that a linear kernel with 2 components. For kernel of degree 2, use Kfda(n_components=2, kernel='poly', degree=2) for a polynomial kernel of degree 2. See https://scikit-learn.org/stable/modules/metrics.html#polynomial-kernel for a list of kernels and their parameters, or the source code docstrings for a complete description of the parameters.

  • Fitting: cls.fit(X, y)

  • Prediction: cls.predict(X)

  • Scoring: cls.score(X, y)

Examples

See examples for examples on MNIST, faces, and oneshot learning.

After running them, you can plug corresponding pairs of generated *embeddings.tsv and *labels.tsv into Tensorflow's Embedding Projector to visualize the embeddings. For example, running mnist.py and then loading mnist_test_embeddings.tsv and mnist_test_labels.tsv shows the following using the UMAP visualizer:

MNIST Kernel FDA embeddings

Notebook

Another place to see example usage is the Colab Notebook.

Caveats

Similar to SVM, the most glaring constraint of KFDA is the memory limit in training. Training a Kernel FDA classifier requires creating matrices that are n_samples by n_samples large, meaning the memory requirement grows with respect to O(n_samples^2).

The accuracy, while high (0.97 on MNIST), seems to be limited by the training set size. With a training size of 10000 and a testing size of 60000, performance on MNIST averages around 0.97 accuracy using 9 fisher directions and the RBF kernel:

cls = Kfda(kernel='rbf', n_components=9)

This may be due to the constrained training size. Accuracy can be improved without increasing training size by implementing invariant kernels that would implicitly handle scale and rotation without requiring an extended dataset.

Oneshot Learning

Oneshot learning means that an algorithm can learn a new class with as little as one sample. This is possible for Kernel FDA because it finds a subspace that purposefully spreads out distinct classes. Introducing a new label involves simply adding another centroid for use in prediction. See the Colab Notebook. or the example for examples.

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

kfda-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

kfda-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kfda-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.2

File hashes

Hashes for kfda-0.1.1.tar.gz
Algorithm Hash digest
SHA256 122224712f8e9f06e96cc9129d4832871d4a855b13c0b7e4a20b6271740d2ee0
MD5 82a0f43355599bb6b60b9a1d99c81ce7
BLAKE2b-256 8fe5a4b327665038c3aa0f4966d3ab60fe5bcb59eaa63d832858b976d07d2db8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kfda-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.2

File hashes

Hashes for kfda-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ddcab446b25dc0ac0770979aca7473f10db0e16951dafaa7e90d51297683ae9
MD5 9a2dc7965308087c536e7483f5835799
BLAKE2b-256 586a74ff6846b076c1181aae42c6965241621cda616d9228d8b88ae8f4917741

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