{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Evaluate classification by compiling a report\n\nSpecific metrics have been developed to evaluate classifier which has been\ntrained using imbalanced data. :mod:`imblearn` provides a classification report\nsimilar to :mod:`sklearn`, with additional metrics specific to imbalanced\nlearning problem.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Authors: Guillaume Lemaitre <g.lemaitre58@gmail.com>\n# License: MIT\n\n\nfrom sklearn import datasets\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\n\nfrom imblearn import over_sampling as os\nfrom imblearn import pipeline as pl\nfrom imblearn.metrics import classification_report_imbalanced\n\nprint(__doc__)\n\nRANDOM_STATE = 42\n\n# Generate a dataset\nX, y = datasets.make_classification(\n    n_classes=2,\n    class_sep=2,\n    weights=[0.1, 0.9],\n    n_informative=10,\n    n_redundant=1,\n    flip_y=0,\n    n_features=20,\n    n_clusters_per_class=4,\n    n_samples=5000,\n    random_state=RANDOM_STATE,\n)\n\npipeline = pl.make_pipeline(\n    StandardScaler(),\n    os.SMOTE(random_state=RANDOM_STATE),\n    LogisticRegression(max_iter=10_000),\n)\n\n# Split the data\nX_train, X_test, y_train, y_test = train_test_split(X, y, random_state=RANDOM_STATE)\n\n# Train the classifier with balancing\npipeline.fit(X_train, y_train)\n\n# Test the classifier and get the prediction\ny_pred_bal = pipeline.predict(X_test)\n\n# Show the classification report\nprint(classification_report_imbalanced(y_test, y_pred_bal))"
      ]
    }
  ],
  "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
}