pip install classifier-toolkit
Classifier Toolkit
Table of Content
Installation
This library is published in the PyPI directory. To install, users can run pip install 'classifier_toolkit' command.
Usage
This library automates binary and multiclass classification workflows. It is independent of the modelled problem: the class of interest is configured through pos_label (the positive class for binary targets, the class of interest for multiclass ones). It includes several packages designed to address the main steps in any machine learning/data science task:
- EDA: accessible via
EDAToolkit. Provides EDA and feature engineering functionality with all necessary visualizations. - Feature Reduction: filter-style pre-selection pipeline (expert rules, low variance, drift, predictive power, counter-intuitive direction, high correlation).
- Feature Selection: wrapper and embedded methods (RFE, Boruta, Sequential, Bayesian, ElasticNet, MetaSelector).
- Model Training: accessible via
Tuner. Hyperparameter optimization (grid search, Bayesian via Optuna) for LightGBM and CatBoost with train/val/test evaluation, including multiclass objectives and class weights. - Risk Class:
RiskClassBuilderDP/RiskClassBuilderturn model scores into risk classes with statistically validated, ordered event rates. - Model Validation:
Evaluatorcomputes metrics, calibration and stability checks for any model exposingpredict_proba. - Calibration:
OVRHistogramCalibratorandplot_reliability_curvesfor One-vs-Rest probability calibration. - Explainability: SHAP-based explanations, interactions and misclassification diagnostics.
- Data Partition: temporal-aware train/test splitting, preprocessing and dtype optimization.
For detailed usage, refer to the documentation.
Note: that this library does not contain data wrangling steps (although it contains feature engineering), it's an intermediate step between EDA and feature engineering where users should fix any data quality related issues. Therefore, conducting the EDA is crucial to mitigate any issues before moving onto the feature engineering and the subsequent steps.
Modules Overview
-
EDA Toolkit: This module includes classes and methods for performing comprehensive exploratory data analysis. It provides automated warnings for data quality issues, univariate and bivariate analysis, and various data visualizations to help understand the dataset.
-
Univariate Analysis: This class focuses on the analysis of individual variables. It includes methods for calculating statistical measures, visualizing distributions, and assessing relationships between variables and a target through techniques like Cramer's V and Information Value. This helps in understanding the significance and distribution of each feature independently.
-
Bivariate Analysis: This class deals with the analysis of two variables to understand their relationship. It includes functionalities for generating correlation heatmaps, performing ANOVA tests between numerical and categorical variables, and computing pairwise Cramer's V for categorical features. This aids in identifying patterns and correlations between pairs of variables, which is crucial for feature selection and engineering.
-
Feature Engineering: This module assists in transforming features, handling missing values, encoding categorical variables, and more. It aims to enhance the dataset's quality for better model performance.
-
Visualizations: This module offers a wide range of plotting capabilities to visually analyze data distributions, relationships, and other crucial aspects of the dataset.
-
Automated Warnings: A utility to automatically check the dataset for common issues such as missing or duplicate values, outliers, and more, providing warnings to guide data cleaning efforts.
-
Feature Reduction: Filter-style pipeline that reduces the feature set before model-based selection. Six sequential steps, each independently configurable:
- Expert Rules — drop features by hand-coded list.
- Low Variance — drop near-constant numerical and categorical features.
- Drift — drop features whose distribution has shifted (PSI, KS, JS and more).
- Predictive Power — drop features with weak univariate Gini / PR-AUC.
- Counter-Intuitive Direction — drop features violating a business prior.
- High Correlation — drop pairwise-redundant features (Pearson/Spearman/Kendall; Cramér's V).
The
FeatureReducerorchestrates all six steps in one sklearn-compatiblefit/transformcall.from classifier_toolkit.feature_reduction import FeatureReducer reducer = FeatureReducer(gini_threshold=0.01, numeric_correlation_threshold=0.85) reducer.fit(X_train, y=y_train, X_val=X_val) X_filtered = reducer.transform(X_train) reducer.summary() # print pipeline summary reducer.export_summary("summary.xlsx", format="excel")
Standalone helpers are also available for ad-hoc analysis outside the pipeline:
from classifier_toolkit.feature_reduction import ( calculate_feature_predictive_metrics, # Gini + PR-AUC for every feature CorrelationAnalyser, # inspect all correlated pairs DriftAnalyser, # inspect drift stats per feature )
Logs are silent by default. To enable them:
import logging logging.basicConfig(level=logging.INFO) logging.getLogger("classifier_toolkit.feature_reduction").setLevel(logging.INFO)
-
Feature Selection: This module provides various feature selection techniques:
- Embedded Methods: Includes ElasticNet for regularization-based feature selection.
- Wrapper Methods:
- Recursive Feature Elimination (RFE) with support for various ensemble methods (Random Forest, XGBoost, LightGBM, CatBoost).
- Sequential Feature Selection (forward, backward, floating, and bidirectional).
- Recursive Feature Eliminator: Adaptive two-phase elimination (batch drop + one-by-one) with overfitting-aware strategies, early stopping with rollback, temporal cross-validation, and sample weights.
- Feature Combination Searcher: Exhaustive combinatorial search over all subsets of a candidate pool, scoring each combination on train/val/test splits.
- Meta Selector: Combines multiple feature selection methods to provide a robust selection.
- Utility Functions: Includes scoring functions and plotting utilities for feature importance visualization.
-
Model Training: Hyperparameter optimization for LightGBM and CatBoost, with support for grid search and Bayesian optimization (via Optuna).
from classifier_toolkit.model_training.hyper_parameter_tuning.tuner import Tuner tuner = Tuner( X=X_train, y=y_train, model_name="lightgbm", X_val=X_val, y_val=y_val, X_test=X_test, y_test=y_test, search_method="bayesian", n_trials=50, optimization_metric="prauc", ) result = tuner.tune() best_model = result["best_model"] result["trials_results"] # full trial results (DataFrame)
Reported metrics are
auc,prauc,ks,log_lossandbrier(ks/brierare binary-only). Custom parameter search spaces can be defined viaModelParamsandParamRange. -
Risk Class: Builds risk classes from model scores.
RiskClassBuilderDPsearches bin edges with dynamic programming so that each class' observed event rate falls in a target band (target_ranges, required), then checks that adjacent classes are statistically distinguishable;RiskClassBuilderdiscovers classes with KMeans.from classifier_toolkit.risk_class import RiskClassBuilderDP builder = RiskClassBuilderDP( target_col="target", target_ranges=[(0.00, 0.02), (0.02, 0.05), (0.05, 0.10)], min_obs_per_bin=200, ) result = builder.build(train_proba, y_train) print(result.bins, result.n_classes)
-
Model Validation:
Evaluatorevaluates any model withpredict_proba(metrics, ROC/PR/calibration/threshold plots),score_distribution_psiandcompare_score_distributionscompare a reference score distribution with a current one, andevaluate_risk_classes_dpchecks calibration within each risk class. -
Calibration:
OVRHistogramCalibratorcalibrates multiclass (or binary) probabilities One-vs-Rest with histogram binning;plot_reliability_curvesshows raw vs calibrated reliability per class. -
Explainability:
TreeSHAPExplainer,ExplainabilityToolkit, SHAP plots, pairwise interaction analysis and aMisclassificationAnalyzerthat explains confusion-matrix quadrants (per-class SHAP for multiclass models). -
Data Partition: Temporal-aware train/test splitting, preprocessing helpers and dtype optimization.
Development & CI/CD
This project uses modern tooling for fast and efficient development workflows:
Dependency Management
- UV: Lightning-fast Python package installer and resolver (replacing Poetry)
- Install UV:
curl -LsSf https://astral.sh/uv/install.sh | sh - Install dependencies:
uv sync --group dev --group lint --group test
CI/CD Pipeline
Our CI/CD pipeline is optimized for speed and efficiency:
- Parallel Test Execution: One test job per directory under
tests/(discovered automatically, so new test groups are picked up without editing the workflow), all running simultaneously - Shared Caching: The parallel jobs share the same dependency cache, avoiding duplicate downloads
- Smart Test Reruns: Failed tests run first (
pytest --lf --ff) for faster feedback on fixes - Master Protection: Build tests only run on
masterbranch and PRs targetingmaster, saving CI resources on feature branches - Automatic Linting: Code quality checks (Ruff, SQLFluff) run on every push
Pipeline Jobs:
dependencies- Installs and caches project dependencieslint- Runs code quality checks (Ruff, SQLFluff)test- Executes tests in parallel with shared cachebuild_test- Builds and validates package (master/PRs only)
Local Development:
# Run linting
uv run make lint
# Run tests
uv run make test
# Build package
uv build
Future Work
The next planned improvements and additions to the library include:
- Extending the evaluation and reporting tools in
model_validation(more checks and report formats). - Expanding documentation to include architecture diagrams and detailed usage examples.
Metadata
Release files for classifier-toolkit 0.5.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 |
|---|---|---|---|---|
| classifier_toolkit-0.5.0.tar.gz | 367.4 kB | Without provenance | Details for classifier_toolkit-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| classifier_toolkit-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for classifier_toolkit-0.5.0-py3-none-any.whl |
Total release size: 653.0 kB
Release files / classifier_toolkit-0.5.0.tar.gz
| Download URL | classifier_toolkit-0.5.0.tar.gz |
|---|---|
| Size | 367.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be34bbd98ca5127ad74ff3039ca54980fb3b8a8457f11dc8601e4cdec2f2229b
|
|
BLAKE2b-256 checksum How to use checksums |
26ece66f18a8ce632dea4f563e35d4720e767c62337c820523a9d97627c76bb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / classifier_toolkit-0.5.0-py3-none-any.whl
| Download URL | classifier_toolkit-0.5.0-py3-none-any.whl |
|---|---|
| Size | 285.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a38f741328e26c3af68fa926ee76e859d9f3a549bcedbf185c54a7ae22af91a8
|
|
BLAKE2b-256 checksum How to use checksums |
c2c1bcdfdd76eada4f4daab2644e8ac6a95289003bbcd813d3b20561c4fe2b10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for classifier-toolkit 0.5.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.