KSFeatureSelector
KSFeatureSelector is a scikit-learn compatible feature selector that ranks features by how well they separate the classes of a binary or multi-class target, using the two-sample Kolmogorov-Smirnov (K-S) test. It subclasses scikit-learn’s SelectorMixin, passes check_estimator, and plugs directly into Pipeline and GridSearchCV.
Features
Ranks features by their K-S test p-value (lower p-value is more discriminative).
Handles binary and multi-class targets (2 to 10 classes).
Two class-comparison strategies for multi-class targets:
pairwise: K-S test between every pair of classes.
one-vs-rest: each class against the rest.
Three p-value aggregation methods: fisher (default), min, max.
Select features by a count (top_n) or a p-value threshold (top_p).
Full scikit-learn API: fit, transform, get_support, get_feature_names_out, inverse_transform.
A select_ks_features convenience function for quick one-off selection.
Installation
pip install ksfeatureselector
Usage
import numpy as np
from ksfeatureselector import KSFeatureSelector
rng = np.random.RandomState(0)
X = rng.normal(size=(200, 5))
y = (X[:, 0] + X[:, 1] > 0).astype(int)
selector = KSFeatureSelector(top_n=2).fit(X, y)
X_reduced = selector.transform(X)
print(selector.get_support())
print(selector.get_feature_p_values())
In a scikit-learn pipeline:
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
pipe = Pipeline([
("ks", KSFeatureSelector(top_p=0.05)),
("clf", LogisticRegression()),
])
pipe.fit(X, y)
Convenience function for DataFrames:
from ksfeatureselector import select_ks_features
selected = select_ks_features(
df, x_cols=["f1", "f2", "f3"], y_var="target",
top_p=0.01,
aggregation_method="one-vs-rest",
p_value_aggregation_method="min",
)
Parameters
top_n (int, optional): keep this many top-ranked features.
top_p (float in [0, 1], optional): keep features whose aggregated p-value is at most this value.
aggregation_method ({"pairwise", "one-vs-rest"}): class comparison strategy for multi-class targets.
p_value_aggregation_method ({"fisher", "min", "max"}): per-feature p-value aggregation method.
top_n and top_p are mutually exclusive. If neither is set, all features are kept (ranked by p-value).
License
BSD 3-Clause License.
Metadata
Release files for ksfeatureselector 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ksfeatureselector-0.3.0.tar.gz | 9.6 kB | Without provenance | Details for ksfeatureselector-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ksfeatureselector-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ksfeatureselector-0.3.0-py3-none-any.whl |
Total release size: 18.4 kB
Release files / ksfeatureselector-0.3.0.tar.gz
| Download URL | ksfeatureselector-0.3.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28fdb468dfcd7eef4f0d69e911a8d3ef0c9b6ef4b3402ab7945657339cc713d5
|
|
BLAKE2b-256 checksum How to use checksums |
46fd07284bc605cc3efe52e2120e98b742607c69086ad5a7d3f9fda1f73eeb0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / ksfeatureselector-0.3.0-py3-none-any.whl
| Download URL | ksfeatureselector-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7802ebf9cb5c3f1ab0de514f89617f166564f83cad676dc766263a56cd5ca403
|
|
BLAKE2b-256 checksum How to use checksums |
605e27dfc17f9c2ada4b9c36968826c4102514ebc2be6e90d33c7cd76dfa86b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for ksfeatureselector 0.3.0
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.