A small toolbox for mlops
Project description
TinyShift
TinyShift is a lightweight, sklearn-compatible Python library designed for data drift detection, outlier identification, and MLOps monitoring in production machine learning systems. The library provides modular, easy-to-use tools for detecting when data distributions or model performance change over time, with comprehensive visualization capabilities.
For enterprise-grade solutions, consider Nannyml.
Features
- Data Drift Detection: Categorical and continuous data drift monitoring with multiple distance metrics
- Outlier Detection: HBOS, PCA-based and SPAD outlier detection algorithms
- Time Series Analysis: Seasonality decomposition, trend analysis, and forecasting diagnostics
Technologies Used
- Python 3.10+
- Scikit-learn 1.3.0+
- Pandas 2.3.0+
- NumPy
- SciPy
- Statsmodels 0.14.5+
- Plotly 5.22.0+ (optional, for plotting)
๐ฆ Installation
Install TinyShift using pip:
pip install tinyshift
Development Installation
Clone and install from source:
git clone https://github.com/HeyLucasLeao/tinyshift.git
cd tinyshift
pip install -e .
๐ Quick Start
1. Categorical Data Drift Detection
TinyShift provides sklearn-compatible drift detectors that follow the familiar fit() and score() pattern:
import pandas as pd
from tinyshift.drift import CatDrift
# Load your data
df = pd.read_csv("data.csv")
reference_data = df[df["date"] < '2024-07-01']
analysis_data = df[df["date"] >= '2024-07-01']
# Initialize and fit the drift detector
detector = CatDrift(
freq="D", # Daily frequency
func="chebyshev", # Distance metric
drift_limit="auto", # Automatic threshold detection
method="expanding" # Comparison method
)
# Fit on reference data
detector.fit(reference_data)
# Score new data for drift
drift_scores = detector.predict(analysis_data)
print(drift_scores)
Available distance metrics for categorical data:
"chebyshev": Maximum absolute difference between distributions"jensenshannon": Jensen-Shannon divergence"psi": Population Stability Index
2. Continuous Data Drift Detection
For numerical features, use the continuous drift detector:
from tinyshift.drift import ConDrift
# Initialize continuous drift detector
detector = ConDrift(
freq="W", # Weekly frequency
func="ws", # Wasserstein distance
drift_limit="auto",
method="expanding"
)
# Fit and score
detector.fit(reference_data)
drift_scores = detector.score(analysis_data)
3. Outlier Detection
TinyShift includes sklearn-compatible outlier detection algorithms:
from tinyshift.outlier import SPAD, HBOS, PCAReconstructionError
# SPAD (Simple Probabilistic Anomaly Detector)
spad = SPAD(plus=True)
spad.fit(X_train)
outlier_scores = spad.decision_function(X_test)
outlier_labels = spad.predict(X_test)
# HBOS (Histogram-Based Outlier Score)
hbos = HBOS(dynamic_bins=True)
hbos.fit(X_train, nbins="fd")
scores = hbos.decision_function(X_test)
# PCA-based outlier detection
pca_detector = PCAReconstructionError()
pca_detector.fit(X_train)
pca_scores = pca_detector.decision_function(X_test)
4. Time Series Analysis and Diagnostics
TinyShift provides time series analysis capabilities:
from tinyshift.plot import seasonal_decompose
from tinyshift.series import trend_significance, permutation_auto_mutual_information
# Seasonal decomposition with multiple periods
seasonal_decompose(
time_series,
periods=[7, 365], # Weekly and yearly patterns
width=1200,
height=800
)
# Test for significant trends
trend_result = trend_significance(time_series, alpha=0.05)
print(f"Significant trend: {trend_result}")
# Stationary Analysis
fig = stationarity_analysis(time_series)
5. Advanced Modeling Tools
from tinyshift.modelling import filter_features_by_vif
from tinyshift.stats import bootstrap_bca_interval
# Detect multicollinearity
mask = filter_features_by_vif(X, trehshold=5, verbose=True)
X.columns[mask]
# Bootstrap confidence intervals
confidence_interval = bootstrap_bca_interval(
data,
statistic=np.mean,
alpha=0.05,
n_bootstrap=1000
)
๐ Project Structure
tinyshift/
โโโ association_mining/ # Market basket analysis tools
โ โโโ analyzer.py # Transaction pattern analysis
โ โโโ encoder.py # Data encoder
โโโ drift/ # Data drift detection
โ โโโ base.py # Base drift detection classes
โ โโโ categorical.py # CatDrift for categorical features
โ โโโ continuous.py # ConDrift for numerical features
โโโ examples/ # Jupyter notebook examples
โ โโโ drift.ipynb # Drift detection examples
โ โโโ outlier.ipynb # Outlier detection demos
โ โโโ series.ipynb # Time series analysis
โ โโโ transaction_analyzer.ipynb
โโโ modelling/ # ML modeling utilities
โ โโโ multicollinearity.py # VIF-based multicollinearity detection
โ โโโ residualizer.py # Residualizer Feature
โ โโโ scaler.py # Custom scaling transformations
โโโ outlier/ # Outlier detection algorithms
โ โโโ base.py # Base outlier detection classes
โ โโโ hbos.py # Histogram-Based Outlier Score
โ โโโ pca.py # PCA-based outlier detection
โ โโโ spad.py # Simple Probabilistic Anomaly Detector
โโโ plot/ # Visualization capabilities
โ โโโ correlation.py # Correlation analysis plots
โ โโโ diagnostic.py # Time series diagnostics plots
โโโ series/ # Time series analysis tools
โ โโโ forecastability.py # Forecast quality metrics
โ โโโ outlier.py # Time series outlier detection
โ โโโ stats.py # Statistical analysis functions
โโโ stats/ # Statistical utilities
โโโ bootstrap_bca.py # Bootstrap confidence intervals
โโโ statistical_interval.py # Statistical interval estimation
โโโ utils.py # General statistical utilities
tinyshift
โโโ LICENSE
โโโ README.md
โโโ poetry.lock
โโโ pyproject.toml
โโโ tinyshift
โย ย โโโ association_mining
โย ย โย ย โโโ README.md
โย ย โย ย โโโ __init__.py
โย ย โย ย โโโ analyzer.py
โย ย โย ย โโโ encoder.py
โย ย โโโ examples
โย ย โย ย โโโ outlier.ipynb
โย ย โย ย โโโ tracker.ipynb
โย ย โย ย โโโ transaction_analyzer.ipynb
โย ย โโโ modelling
โย ย โย ย โโโ __init__.py
โย ย โย ย โโโ multicollinearity.py
โย ย โย ย โโโ residualizer.py
โย ย โย ย โโโ scaler.py
โย ย โโโ outlier
โย ย โย ย โโโ README.md
โย ย โย ย โโโ __init__.py
โย ย โย ย โโโ base.py
โย ย โย ย โโโ hbos.py
โย ย โย ย โโโ pca.py
โย ย โย ย โโโ spad.py
โย ย โโโ plot
โย ย โย ย โโโ __init__.py
โย ย โย ย โโโ correlation.py
โย ย โย ย โโโ plot.py
โย ย โโโ series
โย ย โย ย โโโ README.md
โย ย โย ย โโโ __init__.py
โย ย โย ย โโโ forecastability.py
โย ย โย ย โโโ outlier.py
โย ย โย ย โโโ stats.py
โย ย โโโ stats
โย ย โย ย โโโ __init__.py
โย ย โย ย โโโ bootstrap_bca.py
โย ย โย ย โโโ series.py
โย ย โย ย โโโ statistical_interval.py
โย ย โย ย โโโ utils.py
โย ย โโโ tests
โย ย โย ย โโโ test.pca.py
โย ย โย ย โโโ test_hbos.py
โย ย โย ย โโโ test_spad.py
โย ย โโโ tracker
โย ย โโโ __init__.py
โย ย โโโ anomaly.py
โย ย โโโ base.py
โย ย โโโ categorical.py
โย ย โโโ continuous.py
โย ย โโโ performance.py
Development Setup
git clone https://github.com/HeyLucasLeao/tinyshift.git
cd tinyshift
pip install -e ".[all]"
๐ Requirements
- Python: 3.10+
- Core Dependencies:
- pandas (>2.3.0)
- scikit-learn (>1.3.0)
- statsmodels (>=0.14.5)
- Optional Dependencies:
- plotly (>5.22.0) - for visualization
- kaleido (<=0.2.1) - for static plot export
- nbformat (>=5.10.4) - for notebook support
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by Nannyml
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 tinyshift-1.0.0.tar.gz.
File metadata
- Download URL: tinyshift-1.0.0.tar.gz
- Upload date:
- Size: 46.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60dc0c029d61aee672a5bbe29246bcc65938e2bfa5f4a29d324513fee515d43f
|
|
| MD5 |
427b7dcb81ac01ce638d65b4c86aff16
|
|
| BLAKE2b-256 |
f78753417a4f0c509fa9c449024af4163dcc50bba7812923cc50cd489afb46f6
|
File details
Details for the file tinyshift-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tinyshift-1.0.0-py3-none-any.whl
- Upload date:
- Size: 60.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd3ff25b75ed8ddc4b537e43d4946081d3f31fe2ba545f8e3716ad8c9c6ec927
|
|
| MD5 |
a7eaaf5188d0c0c6b3eec627be6a3ab9
|
|
| BLAKE2b-256 |
c4a2c6b95108b606038c33837da74f7794ea484cab7b5ac7a92b1c2b5d540f59
|