DSTools: Data Science Tools Library
Project description
DSTools: Data Science Research Toolkit
Authors
DSTools is a Python library designed to assist data scientists and researchers by providing a collection of helpful functions for various stages of a data science project, from data exploration and preprocessing to model evaluation and synthetic data generation.
This comprehensive library with helper functions to accelerate and simplify various stages of the data science research cycle.
This toolkit is built on top of popular libraries like Pandas, Polars, Scikit-learn, and Matplotlib, providing a higher-level API for common tasks in Exploratory Data Analysis (EDA), feature preprocessing, model evaluation, and synthetic data generation. It is designed for data scientists, analysts, and researchers who want to write cleaner, more efficient, and more reproducible code.
Table of Contents
- Key Features
- Installation
- Usage
- Function Overview
- Example
- Available Tools
- Contributing
- References
- License
Key Features
- Advanced Data Analysis: Get quick and detailed statistics for numerical and categorical columns.
- Powerful Visualizations: Generate insightful correlation matrices and confusion matrices with a single function call.
- Comprehensive Model Evaluation: Calculate a wide range of classification metrics and visualize performance curves effortlessly.
- Synthetic Data Generation: Create datasets with specific statistical properties (mean, median, std, skew, kurtosis) for robust testing and simulation. Create complex numerical distributions matching specific statistical moments (
generate_distribution,generate_distribution_from_metrics). - Efficient Preprocessing: Encode categorical variables, handle outliers, and create features from missing values.
- Utility Functions: A collection of helpers for stationarity testing, data validation, and file I/O operations.
- Data Exploration: Quickly get statistics for numerical and categorical features (
describe_numeric,describe_categorical), check for missing values (check_NINF), and visualize correlations (corr_matrix). - Model Evaluation: Comprehensive classification model evaluation (
evaluate_classification,compute_metrics) with clear visualizations (plot_confusion_matrix). - Data Preprocessing: Encode categorical variables (
labeling), handle outliers (remove_outliers_iqr), and scale features (min_max_scale). - Time Series Analysis: Test for stationarity using the Dickey-Fuller test (
test_stationarity). - Advanced Statistics: Calculate non-parametric correlation (
chatterjee_correlation), entropy, and KL-divergence. - Utilities: Save/load DataFrames to/from ZIP archives, generate random alphanumeric codes, and more.
Installation
Clone the Repository
git clone https://github.com/s-kav/ds_tools.git
or
Install dscience-tools directly from PyPI:
pip install dscience-tools
Navigate to the Project Directory
cd ds_tools
Install Dependencies
Ensure you have Python version 3.8 or higher and install the required packages:
pip install -r requirements.txt
Usage
Here's a simple example of how to use the library to evaluate a classification model.
import numpy as np
from ds_tools import DSTools
# 1. Initialize the toolkit
tools = DSTools()
# 2. Generate some dummy data
y_true = np.array([0, 1, 1, 0, 1, 0, 0, 1])
y_probs = np.array([0.1, 0.8, 0.6, 0.3, 0.9, 0.2, 0.4, 0.7])
# 3. Get a comprehensive evaluation report
# This will print metrics and show plots for ROC and Precision-Recall curves.
results = tools.evaluate_classification(true_labels=y_true, pred_probs=y_probs)
# The results are also returned as a dictionary
print(f"\nROC AUC Score: {results['roc_auc']:.4f}")
Full code base for other function testing you can find here.
Function Overview
The library provides a wide range of functions. To see a full, formatted list of available tools, you can use the function_list method:
from ds_tools import DSTools
tools = DSTools()
tools.function_list()
Example
Generating a Synthetic Distribution: need to create a dataset with specific statistical properties? generate_distribution_from_metrics can do that.
from ds_tools import DSTools, DistributionConfig
tools = DSTools()
# Define the desired metrics
metrics_config = DistributionConfig(
mean=1042,
median=330,
std=1500,
min_val=1,
max_val=120000,
skewness=13.2,
kurtosis=245, # Excess kurtosis
n=10000
)
# Generate the data
generated_data = tools.generate_distribution_from_metrics(n=10000, metrics=metrics_config)
print(f"Generated Mean: {np.mean(generated_data):.2f}")
print(f"Generated Std: {np.std(generated_data):.2f}")
Full code base for other function testing you can find here.
Available Tools
The library includes a wide range of functions. Here is a complete list:
- compute_metrics: Calculate main pre-selected classification metrics.
- corr_matrix: Calculate and visualize a correlation matrix.
- category_stats: Calculate and print categorical statistics.
- sparse_calc: Calculate sparsity level as a coefficient.
- trials_res_df: Aggregate Optuna optimization trials into a DataFrame.
- labeling: Encode categorical variables with optional ordering.
- remove_outliers_iqr: Remove or cap outliers using the IQR method.
- stat_normal_testing: Perform D'Agostino's K² test for normality.
- test_stationarity: Perform the Dickey-Fuller test for time-series stationarity.
- check_NINF: Check for NaN and infinite values in a DataFrame.
- df_stats: Get a quick, comprehensive overview of a DataFrame's structure.
- describe_categorical: Generate a detailed description of categorical columns.
- describe_numeric: Generate a detailed description of numerical columns.
- generate_distribution: Generate a synthetic numerical distribution with specific statistical properties.
- evaluate_classification: A master function to calculate, print, and visualize metrics for a binary classification model.
- grubbs_test: Perform Grubbs' test to identify a single outlier.
- plot_confusion_matrix: Plot a clear and readable confusion matrix.
- add_missing_value_features: Add features based on the count of missing values per row.
- chatterjee_correlation: Calculate Chatterjee's rank correlation coefficient (Xi).
- calculate_entropy & calculate_kl_divergence: Compute information theory metrics.
- min_max_scale: Scale DataFrame columns to the range [0, 1].
- save_dataframes_to_zip & read_dataframes_from_zip: Save and load multiple dataframes from a single ZIP archive.
- generate_alphanum_codes: Generate an array of random alphanumeric codes.
- generate_distribution_from_metrics: A powerful function to generate a synthetic distribution matching a full suite of statistical metrics.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository. If you have ideas for new features or improvements, please open an issue first to discuss what you would like to change.
To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix (git checkout -b feature/AmazingFeature).
- Make your changes.
- Add tests for your new feature. Ensure all tests pass (pytest).
- Format your code (black . and ruff --fix .).
- Commit your changes with clear messages (git commit -m 'Add some AmazingFeature').
- Push to the branch/fork (git push origin feature/AmazingFeature).
- Open a Pull Request.
Please ensure your code adheres to PEP8 standards and includes appropriate docstrings and comments.
References
For citing you should use:
Sergii Kavun. (2025). s-kav/ds_tools: Version 0.9.1 (v0.9.1). Zenodo. https://doi.org/10.5281/zenodo.15864146
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dscience_tools-1.0.6.tar.gz.
File metadata
- Download URL: dscience_tools-1.0.6.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
361819a96f25cbdf6a05afe828c570707b7fba0fc771fda92adc3701773b471c
|
|
| MD5 |
23ac9ffc9e862d807b9fdbecbf023ebf
|
|
| BLAKE2b-256 |
b4fce9e3f3165295ccfb0c142c20de5f1baf5fc1504c782e73d6fbf86ef0d1a1
|
Provenance
The following attestation bundles were made for dscience_tools-1.0.6.tar.gz:
Publisher:
python-publish.yml on s-kav/ds_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dscience_tools-1.0.6.tar.gz -
Subject digest:
361819a96f25cbdf6a05afe828c570707b7fba0fc771fda92adc3701773b471c - Sigstore transparency entry: 274730190
- Sigstore integration time:
-
Permalink:
s-kav/ds_tools@0cae18c83038d57cd498f1754f1dfd0c64e29573 -
Branch / Tag:
refs/tags/v.1.0.6 - Owner: https://github.com/s-kav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0cae18c83038d57cd498f1754f1dfd0c64e29573 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dscience_tools-1.0.6-py3-none-any.whl.
File metadata
- Download URL: dscience_tools-1.0.6-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f077c8f8cf0f298eaae9f1bc69b6c4ad3637870e1e7838f1ed3129154570296
|
|
| MD5 |
c3cd3342a6c4bed8e846fc706e57a88e
|
|
| BLAKE2b-256 |
0b4765e3c63f2900f49ead50bf354589dc14b2edbaeea1b28decf6edd55ff3f9
|
Provenance
The following attestation bundles were made for dscience_tools-1.0.6-py3-none-any.whl:
Publisher:
python-publish.yml on s-kav/ds_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dscience_tools-1.0.6-py3-none-any.whl -
Subject digest:
6f077c8f8cf0f298eaae9f1bc69b6c4ad3637870e1e7838f1ed3129154570296 - Sigstore transparency entry: 274730192
- Sigstore integration time:
-
Permalink:
s-kav/ds_tools@0cae18c83038d57cd498f1754f1dfd0c64e29573 -
Branch / Tag:
refs/tags/v.1.0.6 - Owner: https://github.com/s-kav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0cae18c83038d57cd498f1754f1dfd0c64e29573 -
Trigger Event:
release
-
Statement type: