Skip to main content

Neigbhorhood Component Feature Selection

This is a Python implementation of Neighborhood Component Feature Selection, originally introduced in Yang et al. 2012. NCFS is an embedded feature selection method that learns feature weights by maximizing prediction accuracy in a leave-one-out KNN classifier.

Installation

The package can be with pip using the following command:

pip install ncfs

Example

from NCFS import NCFS

X, y = NCFS.toy_dataset()
feature_select = NCFS.NCFS()
feature_select.fit(X, y)
print(sum(feature_select.coef_ > 1))

Tests

To compare results to the original paper run the following command python tests/generate_results.py

To perform unit tests ensuring accurate distance calculations, run: python tests/test_distances.py

Comparison with Original Results

Distance metric

The original paper uses the Manhattan distance when calculating distances between samples/features. While this implementation defaults to using this distance, weights comparable with published results were only found using the euclidean distance. However, while exact weights differed between distance metrics, the selected features did not. Unfortunately, the original paper did not link to the code used, and I've been unable to find a public implementation of the aglorithm.

Numerical stability

NCFS uses the original kernel function when calculating probabilities; however, with a large number of features, distance values can easily approach a large enough value such that the negative exponent rounds to zero. This leads to division by zero issues, and fitting fails. To get around this, small pseudocounts are added to distances when a division by zero would otherwise occur. To keep distances small, features should be scaled between 0 and 1 (enforced by NCFS).

Metadata

Release files for ncfs 0.1.2

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

Source distribution (sdist)

Source distribution for ncfs 0.1.2
File Size Uploaded Provenance Actions
ncfs-0.1.2.tar.gz 12.4 kB Without provenance Details for ncfs-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 25.2 kB

Release files / ncfs-0.1.2.tar.gz

Download URL ncfs-0.1.2.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e9e228f5d1691644d419a5a8c84eb8861e930b817a324a959eb095cd051b13c0
BLAKE2b-256 checksum
How to use checksums
0531bd7ff1eff6486f0e35a6e8a2f75c3b444fa262702c8137f0faefc09be582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.8

Release files / ncfs-0.1.2-py3-none-any.whl

Download URL ncfs-0.1.2-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa4beb7b69766444cae68883e682f20bb7e094451201b8d53f6afabaee0e6fb5
BLAKE2b-256 checksum
How to use checksums
2703540739b3703740318a1934ec5a5d08d57ae7d53c6bdde037117e9a310066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.8

Security for ncfs 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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