{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "toc_visible": true,
      "authorship_tag": "ABX9TyM4gKVPWAxLSMgt8BSGFiZN",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/p82maavd/MIML/blob/main/src/miml/tutorial/classifiers_mimltomi.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install mimllearning\n",
        "\n",
        "from miml.classifier import MIMLtoMIBRClassifier, MIMLtoMILPClassifier\n",
        "from miml.datasets import load_birds_train, load_birds_test\n",
        "\n",
        "dataset_train = load_birds_train()\n",
        "dataset_test = load_birds_test()"
      ],
      "metadata": {
        "id": "QNmyu82hKcVB",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5a021eef-a6c6-4afe-f4e1-85ee2371ef90"
      },
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: mimllearning in /usr/local/lib/python3.10/dist-packages (0.5.1)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Examples of MI Classifiers that can be used in the library from scikit-learn:"
      ],
      "metadata": {
        "id": "KwibNMJV9Gns"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### MIMLtoMI Binary Relevance Classifiers"
      ],
      "metadata": {
        "id": "byKMqi6eeJvD"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "#### APR Classifier [Reference]()"
      ],
      "metadata": {
        "id": "BfO7dgESMX9O"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from miml.classifier import APRClassifier\n",
        "\n",
        "classifier_mi = MIMLtoMIBRClassifier(APRClassifier())\n",
        "classifier_mi.fit(dataset_train)\n",
        "print(\"Predicted Labels: \", classifier_mi.predict_bag(dataset_test.get_bag(\"366\")))\n",
        "print(\"True Labels:      \", dataset_test.get_bag(\"366\").get_labels()[0].astype(int))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ZP8rdL8KKFO-",
        "outputId": "f5347782-260c-4313-8c9d-a057349c4e87"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Predicted Labels:  [0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0]\n",
            "True Labels:       [0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### MIMLtoMI Label Powerset Classifiers"
      ],
      "metadata": {
        "id": "Cl71--v4eVVI"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "#### MIWrapperClassifier [Reference]()"
      ],
      "metadata": {
        "id": "tFiaHceqNhId"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from miml.classifier import MIWrapperClassifier\n",
        "\n",
        "classifier_mi = MIMLtoMILPClassifier(MIWrapperClassifier())\n",
        "classifier_mi.fit(dataset_train)\n",
        "print(\"Predicted Labels: \", classifier_mi.predict_bag(dataset_test.get_bag(\"366\")))\n",
        "print(\"True Labels:       \", dataset_test.get_bag(\"366\").get_labels()[0].astype(int))"
      ],
      "metadata": {
        "id": "lqWQmt4GLXhQ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "1a8af6bf-5a06-4754-b238-e9fad1e3385b"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Predicted Labels:  [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1]\n",
            "True Labels:        [0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0]\n"
          ]
        }
      ]
    }
  ]
}