{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Histogram of predicted probabilities\n\nWhen doing a classification, we want to see how much overlap there is in\nthe predicted probabilities.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from sklearn.datasets import make_classification\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split\n\nfrom dfds_ds_toolbox.analysis.plotting import plot_classification_proba_histogram\n\n# Create a dataset to classify\nX, y = make_classification(\n    n_samples=500,\n    n_features=5,\n    n_redundant=2,\n    n_informative=3,\n    random_state=1,\n    n_clusters_per_class=1,\n)\n# Train a model\nmodel = LogisticRegression()\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=42)\nmodel.fit(X_train, y_train)\n# Get predictions\npredictions = model.predict_proba(X_test)\nproba_class_1 = predictions[:, 1]\n\n# Compare predictions to ground truth\nplot_classification_proba_histogram(y_true=y_test, y_pred=proba_class_1)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}