Skip to main content

A small toolbox for mlops

Project description

TinyShift

TinyShift is a small experimental Python library designed to detect data drifts and performance drops in machine learning models over time. The main goal of the project is to provide quick and tiny monitoring tools to help identify when data or model performance unexpectedly change. For more robust solutions, I highly recommend Nannyml.

Technologies Used

  • Python 3.x
  • Scikit-learn
  • Pandas
  • NumPy
  • Plotly
  • Scipy

Installation

To install TinyShift in your development environment, use pip:

pip install tinyshift

If you prefer to clone the repository and install manually:

git clone https://github.com/HeyLucasLeao/tinyshift.git
cd tinyshift    
pip install .

Note: If you want to enable plotting capabilities, you need to install the extras using Poetry:

poetry install --all-extras

Usage

Below are basic examples of how to use TinyShift's features.

1. Data Drift Detection

To detect data drift, simply score in a new dataset to compare with the reference data. The DataDriftDetector will calculate metrics to identify significant differences.

from tinyshift.detector import CategoricalDriftDetector

df = pd.DataFrame("examples.csv")
df_reference = df[(df["datetime"] < '2024-07-01')].copy()
df_analysis = df[(df["datetime"] >= '2024-07-01')].copy()

detector = CategoricalDriftDetector(df_reference, 'discrete_1', "datetime", "W", drift_limit='mad')

analysis_score = detector.score(df_analysis, "discrete_1", "datetime")

print(analysis_score)

2. Performance Tracker

To track model performance over time, use the PerformanceMonitor, which will compare model accuracy on both old and new data.

from tinyshift.tracker import PerformanceTracker

df_reference = pd.read_csv('refence.csv')
df_analysis = pd.read_csv('analysis.csv')
model = load_model('model.pkl') 
df_analysis['prediction'] = model.predict(df_analysis["feature_0"])

tracker = PerformanceTracker(df_reference, 'target', 'prediction', 'datetime', "W")

analysis_score = tracker.score(df_analysis, 'target', 'prediction', 'datetime')

print(analysis_score)

3. Visualization

TinyShift also provides graphs to visualize the magnitude of drift and performance changes over time.

tracker.plot.scatterplot_over_time(analysis_score, fig_type="png")

tracker.plot.diverging_bar_over_time(analysis_score, fig_type="png")

Project Structure

The basic structure of the project is as follows:

tinyshift
├── LICENSE
├── README.md
├── example.ipynb
├── pyproject.toml
└── tinyshift
    ├── base
    │   ├── __init__.py
    │   └── model.py
    ├── detector
    │   ├── __init__.py
    │   ├── categorical.py
    │   └── continuous.py
    ├── plot
    │   ├── __init__.py
    │   └── plot.py
    └── tracker
        ├── __init__.py
        └── performance.py          

License

This project is licensed under the MIT License - see the LICENSE file for more details.

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

tinyshift-0.0.4.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinyshift-0.0.4-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file tinyshift-0.0.4.tar.gz.

File metadata

  • Download URL: tinyshift-0.0.4.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for tinyshift-0.0.4.tar.gz
Algorithm Hash digest
SHA256 5c5b0ffdae164cd2c4ebd460aa37829f1dcfc9a44891c461a734ab675b301bd6
MD5 cc40c0b067fe0f4961faca6e091033f1
BLAKE2b-256 e28c959db1e70c4280de4efbc0c3168b381b18dc7ae3a026fda1483cd10bd8fa

See more details on using hashes here.

File details

Details for the file tinyshift-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tinyshift-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for tinyshift-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1168804e8bb055e40f90c53e0177ccf0d6405e5bf77cdaad37f2882fa0007fe8
MD5 da8560c2a7b4ecf0297fa0ff09938d28
BLAKE2b-256 71482b19a2ee25c2826faa0e2f89025ddc6b440dcddaaab05e412628a4bbad42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page