Skip to main content

No project description provided

Project description

Biased Classifier

Biased Classifier

Current version: 0.3.0

Install

Directly from PyPi servers:

pip install biasedclassifier

Interface

Estimator's constructor:

BiasedClassifier(
    p=[0.0],
    unbiased_estimator=None,
    knn=None
)

where unbiased_estimator is the base estimator to use (and to biased towards critical set). We pass a k-NearestNeighbor object directly via the paramter knn.

Use

Example using Random Forests from scikit-learn.

Assume X, y is a training set with three classes and two heavily inbalanced classes. In this case, we'd like to bias two classifiers into these subsets. We've decided that 0.3 and 0.2 proportions are enough for the minority classes (from smaller up) and k=10 neighbors to collect for critical set. Our unbiased estimator will be a random forest of size 200.

from biasedclassifier import BiasedClassifier
from sklearn.neighbors import NearestNeighbors
from sklearn.ensemble import RandomForestClassifier

clf = BiasedClassifier(
    p=[0.3, 0.2], 
    unbiased_classifier=RandomForestClassifier(n_estimators=200), 
    knn=NearestNeighbors(n_neighbors=10)
)

# Train
clf.fit(X,y)

# Obtain probabilities for each class
prob = clf.predict_proba(X)

# Predicted values
y_pred = clf.predict(X)

# Average accuracy score
score = clf.score(X, y)

It is important to note that BiasedEstimator does not change the state of both objects unbiased_classifier and knn. Instead, it uses clones internally to do its operations.

Compatibility

This model is compatible with all of the capabilities offered by scikit-learn requiring get_params and score methods.

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

BiasedClassifier-0.3.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

BiasedClassifier-0.3.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file BiasedClassifier-0.3.1.tar.gz.

File metadata

  • Download URL: BiasedClassifier-0.3.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.7 Darwin/18.7.0

File hashes

Hashes for BiasedClassifier-0.3.1.tar.gz
Algorithm Hash digest
SHA256 56ba138cce6012f9e310eda4e2bfd67ab9ea8f39b8bdf979154baf6362e7aa43
MD5 43fb934fe3ec73123d03fe26547efbbd
BLAKE2b-256 3da3c5f7086f9096ff5355d7465da62ce7b91f5b130137b262f575ffed9a8bb7

See more details on using hashes here.

File details

Details for the file BiasedClassifier-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for BiasedClassifier-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 271b31de68863be431abb06db664201ed9ab2be87b37ea53d3374faae32d250c
MD5 59ab1b251dd9e04b67b9bc9ad36dce0b
BLAKE2b-256 3ce9f24e948847ddf3f7a664cb5b7092e0d3c006dd686cd9c58b9f4e76d96a58

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