{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Plot Gain chart\n\nGiven a trained model, show the fraction of events \"gained\" by targetting a percentaige of the total sample.\n\nIn this example, if we select the top 20% of the total sample, we expect to see a gain of about 50%, ie we will have captured 50% of the positive cases.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from sklearn import datasets, model_selection, svm\n\nfrom dfds_ds_toolbox.analysis.plotting import plot_gain_chart\n\nX, y = datasets.make_classification(random_state=0)\nX_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, random_state=0)\nclf = svm.SVC(random_state=0, probability=True)\nclf.fit(X_train, y_train)\n\ny_pred = clf.predict_proba(X_test)[:, 1]  # Select probabilities for class 1\n\nf = plot_gain_chart(\n    y_true=y_test,\n    y_pred=y_pred,\n    n_bins=11,\n)"
      ]
    }
  ],
  "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
}