Skip to main content

Bcselector

https://raw.githubusercontent.com/Kaketo/bcselector/master/docs/img/logo_small.png https://img.shields.io/badge/python-3.7-blue.svg https://badge.fury.io/py/bcselector.svg https://travis-ci.com/Kaketo/bcselector.svg?branch=master https://codecov.io/gh/Kaketo/bcselector/branch/master/graph/badge.svg https://img.shields.io/badge/License-MIT-yellow.svg

What is it?

Feature selection is a crucial problem in many machine learning tasks. Usually the considered variables are cheap to collect and store but in some situations the acquisition of feature values can be problematic. For example, when predicting the occurrence of the disease we may consider the results of some diagnostic tests which can be very expensive. The existing feature selection methods usually ignore costs associated with the considered features. The goal of cost- sensitive feature selection is to select a subset of features which allow to predict the target variable (e.g. occurrence of the diseases) successfully within the assumed budget.

The main purpose of this package is to provide filter methods of feature selection based on information theory and to propose new variants of these methods considering feature costs.

Installation

bcselector can be installed from [PyPI] (https://pypi.org/project/bcselector):

pip install bcselector

Quickstart

First of all we must have a dataset with classification target variable and a cost assigned to each feature. Good sample data could be hepatitis from UCI repository [1].

Lets say that that we have dataset loaded to Python, we need to create Selector class and call fit method with proper arguments on it:

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score

from bcselector.variable_selection import FractionVariableSelector
from bcselector.datasets import load_sample

# Arguments for feature selection
# r - cost scaling parameter,
# beta - kwarg for j_criterion_func,
# model - model that is fitted on data.
r = 1
beta = 0.5
model = LogisticRegression(max_iter=1000)

# Data
X,y,costs = load_sample()

# Feature selection
fvs = FractionVariableSelector()
fvs.fit(data=X, target_variable=y, costs=costs, r=r, j_criterion_func='cife', beta=beta)

Now we can obtain feature selection results by calling simple getter:

fvs.get_cost_results()

Or we can score and plot our results with any sklearn model and classification metric:

fvs.score(model=model, scoring_function=roc_auc_score)
fvs.plot_scores(compare_no_cost_method=True, model=model, annotate=True)

Which results in BC-plot:

https://raw.githubusercontent.com/Kaketo/bcselector/master/docs/img/bc_plot.png

On OX axis we have accumulated cost and on OY axis we see test set score of currently selected set of features:

  • Blue line is cost-sensitive method selected features order.

  • Red line is NO-cost method selected features order.

  • Blue vertical line is maximum budget avaliable (user parameter)

Small numbers above or below the curve are indexes of selected features. Therefore we can see that first variable selected by cost-sensitive method is on 14th column in dataset X.

Bibliography

  • [1] Dua, D. and Graff, C. (2019). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.

Citations

TBD

Metadata

Release files for bcselector 0.0.42

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

Source distribution (sdist)

Source distribution for bcselector 0.0.42
File Size Uploaded Provenance Actions
bcselector-0.0.42.tar.gz 11.2 MB Without provenance Details for bcselector-0.0.42.tar.gz

Built distribution (wheel)

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

Total release size: 22.8 MB

Release files / bcselector-0.0.42.tar.gz

Download URL bcselector-0.0.42.tar.gz
Size 11.2 MB
Tags Source
SHA-256 checksum
How to use checksums
a6d1397a937a11a755ef5eaea032f8a30278fd36ec8ec5e44ba8dc295e878e12
BLAKE2b-256 checksum
How to use checksums
fc5ac3b9b56732db1eae3709a6234a5ecd5b0fd46424ba1b7ee79da8a3cd64a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.12

Release files / bcselector-0.0.42-py3-none-any.whl

Download URL bcselector-0.0.42-py3-none-any.whl
Size 11.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f3e0fe775ab8d38f61eb499f687b13226baabbfd76c117298037fdc1e0f25c4d
BLAKE2b-256 checksum
How to use checksums
87f1eef28384de663d70ac7be8ca8fd4ccc4b3ba99033297d44bd9bb3f648a88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.12

Security for bcselector 0.0.42

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.

Release history Release notifications | RSS feed

This release

0.0.42 This release

2 release files No provenance

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