Skip to main content

A package with code from my ML projects that has a potential of being reusable

Project description


PyPI version

A package with code from my ML projects that has a potential of being reusable.


The package installation is simple, since the repo is available on PyPi:

pip install ddplt

Confusion matrix

Draw a confusion matrix for classification results:

import numpy as np
from ddplt.heatmaps import draw_confusion_heatmap

# generate some data 
y_test = np.array([0, 0, 1, 1, 2, 0])
y_pred = np.array([0, 1, 1, 2, 2, 0])
class_names = np.array(['hip', 'hop', 'pop'])
ax, cm = draw_confusion_heatmap(y_test, y_pred, class_names)


Cross-validated receiver operating characteristic and precision-recall curves

Draw receiver operating characteristic (ROC) and precision-recall (PR) curves using k-fold cross-validation:

from ddplt.classification import draw_roc_prc_cv

from sklearn.datasets import make_moons
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import KFold

X, y = make_moons(500, noise=.2, random_state=123)
estimator = LogisticRegression()
cv = KFold(n_splits=5, shuffle=True, random_state=123)

draw_roc_prc_cv(estimator, X, y, cv)


The function draw_roc_prc_cv accepts the following parameters:

  • estimator - Scikit-learn's estimator with set hyperparameters. The estimator does not have to be fitted.
  • X - array-like with shape (n_instances,n_features)
  • y - array-like with shape (n_instances,) with instance labels
  • cv - cross-validation generator responsible for creating k-fold splitting of X and y

see the docs for info regarding the optional parameters

In each CV iteration, the estimator is fitted on training fold and class probabilities are predicted for instances within the test fold. Then, ROC and PR curves are generated from the probabilities.

The figure consists of:

  • individual ROC/PR curves
  • mean ROC/PR curve
  • shaded region denoting +-1 std. dev.

Areas under ROC and PR curves are reported in the legend.

Note: Use the functions draw_roc_cv or draw_prc_cv to draw ROC or PR curves only

Learning curve

TODO - not yet implemented

Create plot showing performance evaluation for different sizes of training data. The method should accept:

  • existing Axes
  • performance measure (e.g. accuracy, MSE, precision, recall, etc.)
  • ...

Correlation heatmap

TODO - not yet implemented

Grid where each square has a color denoting strength of a correlation between predictors. You can choose between Pearson and Spearman correlation coefficient, the result is shown inside the square.

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

ddplt-0.0.2.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distributions

ddplt-0.0.2-py3.6.egg (8.8 kB view hashes)

Uploaded Source

ddplt-0.0.2-py3-none-any.whl (21.3 kB view hashes)

Uploaded Python 3

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