{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyPHBLcx6x97ebPE6LXXGnFd",
      "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/train_test_experiment_miml.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "#Installation and requirements of library\n"
      ],
      "metadata": {
        "id": "UwOvUSvR-8Sm"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install mimllearning"
      ],
      "metadata": {
        "id": "jZMmibMJcRf2"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Loading of datasets"
      ],
      "metadata": {
        "id": "AYTbl78HBtuZ"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "L-_qkpnOxj_V"
      },
      "outputs": [],
      "source": [
        "import pkg_resources\n",
        "from miml.datasets import load_dataset, load_birds\n",
        "\n",
        "# dataset = load_dataset(\"miml_birds.csv\"))\n",
        "# dataset = load_dataset(\"C:\\Users\\Damián\\Downloads\\miml_birds.arff\")\n",
        "# dataset = load_dataset(pkg_resources.resource_filename('miml', 'datasets/miml_birds'))\n",
        "dataset = load_birds()\n",
        "\n",
        "dataset_train, dataset_test = dataset.split_dataset(0.8)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# MIMLtoMI Classifier\n"
      ],
      "metadata": {
        "id": "KCupyHfc9c0F"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from miml.classifier import MIMLtoMIBRClassifier, APRClassifier\n",
        "\n",
        "classifier_mi = MIMLtoMIBRClassifier(APRClassifier())\n",
        "classifier_mi.fit(dataset_train)\n",
        "results_mi = classifier_mi.evaluate(dataset_test)\n",
        "probs_mi = classifier_mi.predict_proba(dataset_test)"
      ],
      "metadata": {
        "id": "J7CxjYzK9jdX"
      },
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Report MI"
      ],
      "metadata": {
        "id": "5VmZnFleZUMZ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from miml.report import Report\n",
        "\n",
        "report = Report(results_mi, probs_mi, dataset_test)\n",
        "report.to_string()\n",
        "print(\"\")\n",
        "report.to_csv()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_blawc4pZWuH",
        "outputId": "e02d579c-479d-4297-e76e-43a8dd9eeaf8"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "precision-score-macro :  0.16599026450285032\n",
            "precision-score-micro :  0.208955223880597\n",
            "average-precision-score-macro :  0.13233912181953641\n",
            "average-precision-score-micro :  0.13673291608692004\n",
            "recall-score-macro :  0.15933416428772468\n",
            "recall-score-micro :  0.25925925925925924\n",
            "f1-score-macro :  0.14296150593201268\n",
            "f1-score-micro :  0.23140495867768596\n",
            "fbeta-score-macro :  0.14634518676605035\n",
            "fbeta-score-micro :  0.2173913043478261\n",
            "subset-accuracy-score :  0.0196078431372549\n",
            "hamming-loss :  0.19195046439628483\n",
            "jaccard-score-macro :  0.08445809323477566\n",
            "jaccard-score-micro :  0.1308411214953271\n",
            "log-loss :  23.432988277126885\n",
            "precision-score-BRCR :  0.0\n",
            "precision-score-PAWR :  0.3333333333333333\n",
            "precision-score-PSFL :  0.23076923076923078\n",
            "precision-score-RBNU :  0.0\n",
            "precision-score-DEJU :  0.0\n",
            "precision-score-OSFL :  1.0\n",
            "precision-score-HETH :  0.2857142857142857\n",
            "precision-score-CBCH :  0.0\n",
            "precision-score-VATH :  0.07692307692307693\n",
            "precision-score-HEWA :  0.3\n",
            "precision-score-SWTH :  0.30434782608695654\n",
            "precision-score-HAFL :  0.0\n",
            "precision-score-WETA :  0.2727272727272727\n",
            "precision-score-BHGB :  0.0\n",
            "precision-score-GCKI :  0.1\n",
            "precision-score-WAVI :  0.0\n",
            "precision-score-MGWA :  0.0\n",
            "precision-score-STJA :  0.0\n",
            "precision-score-CONI :  0.25\n",
            "recall-score-BRCR :  0.0\n",
            "recall-score-PAWR :  0.5\n",
            "recall-score-PSFL :  0.42857142857142855\n",
            "recall-score-RBNU :  0.0\n",
            "recall-score-DEJU :  0.0\n",
            "recall-score-OSFL :  0.2\n",
            "recall-score-HETH :  0.16666666666666666\n",
            "recall-score-CBCH :  0.0\n",
            "recall-score-VATH :  0.14285714285714285\n",
            "recall-score-HEWA :  0.2727272727272727\n",
            "recall-score-SWTH :  0.4117647058823529\n",
            "recall-score-HAFL :  0.0\n",
            "recall-score-WETA :  0.42857142857142855\n",
            "recall-score-BHGB :  0.0\n",
            "recall-score-GCKI :  0.14285714285714285\n",
            "recall-score-WAVI :  0.0\n",
            "recall-score-MGWA :  0.0\n",
            "recall-score-STJA :  0.0\n",
            "recall-score-CONI :  0.3333333333333333\n",
            "f1-score-BRCR :  0.0\n",
            "f1-score-PAWR :  0.4\n",
            "f1-score-PSFL :  0.3\n",
            "f1-score-RBNU :  0.0\n",
            "f1-score-DEJU :  0.0\n",
            "f1-score-OSFL :  0.33333333333333337\n",
            "f1-score-HETH :  0.2105263157894737\n",
            "f1-score-CBCH :  0.0\n",
            "f1-score-VATH :  0.1\n",
            "f1-score-HEWA :  0.28571428571428564\n",
            "f1-score-SWTH :  0.35\n",
            "f1-score-HAFL :  0.0\n",
            "f1-score-WETA :  0.33333333333333326\n",
            "f1-score-BHGB :  0.0\n",
            "f1-score-GCKI :  0.11764705882352941\n",
            "f1-score-WAVI :  0.0\n",
            "f1-score-MGWA :  0.0\n",
            "f1-score-STJA :  0.0\n",
            "f1-score-CONI :  0.28571428571428575\n",
            "fbeta-score-BRCR :  0.0\n",
            "fbeta-score-PAWR :  0.3571428571428571\n",
            "fbeta-score-PSFL :  0.2542372881355932\n",
            "fbeta-score-RBNU :  0.0\n",
            "fbeta-score-DEJU :  0.0\n",
            "fbeta-score-OSFL :  0.5555555555555556\n",
            "fbeta-score-HETH :  0.24999999999999997\n",
            "fbeta-score-CBCH :  0.0\n",
            "fbeta-score-VATH :  0.08474576271186442\n",
            "fbeta-score-HEWA :  0.29411764705882354\n",
            "fbeta-score-SWTH :  0.3211009174311927\n",
            "fbeta-score-HAFL :  0.0\n",
            "fbeta-score-WETA :  0.29411764705882354\n",
            "fbeta-score-BHGB :  0.0\n",
            "fbeta-score-GCKI :  0.10638297872340426\n",
            "fbeta-score-WAVI :  0.0\n",
            "fbeta-score-MGWA :  0.0\n",
            "fbeta-score-STJA :  0.0\n",
            "fbeta-score-CONI :  0.2631578947368421\n",
            "jaccard-score-BRCR :  0.0\n",
            "jaccard-score-PAWR :  0.25\n",
            "jaccard-score-PSFL :  0.17647058823529413\n",
            "jaccard-score-RBNU :  0.0\n",
            "jaccard-score-DEJU :  0.0\n",
            "jaccard-score-OSFL :  0.2\n",
            "jaccard-score-HETH :  0.11764705882352941\n",
            "jaccard-score-CBCH :  0.0\n",
            "jaccard-score-VATH :  0.05263157894736842\n",
            "jaccard-score-HEWA :  0.16666666666666666\n",
            "jaccard-score-SWTH :  0.21212121212121213\n",
            "jaccard-score-HAFL :  0.0\n",
            "jaccard-score-WETA :  0.2\n",
            "jaccard-score-BHGB :  0.0\n",
            "jaccard-score-GCKI :  0.0625\n",
            "jaccard-score-WAVI :  0.0\n",
            "jaccard-score-MGWA :  0.0\n",
            "jaccard-score-STJA :  0.0\n",
            "jaccard-score-CONI :  0.16666666666666666\n",
            "\n",
            "precision-score-macro,precision-score-micro,average-precision-score-macro,average-precision-score-micro,recall-score-macro,recall-score-micro,f1-score-macro,f1-score-micro,fbeta-score-macro,fbeta-score-micro,subset-accuracy-score,hamming-loss,jaccard-score-macro,jaccard-score-micro,log-loss,precision-score-BRCR,precision-score-PAWR,precision-score-PSFL,precision-score-RBNU,precision-score-DEJU,precision-score-OSFL,precision-score-HETH,precision-score-CBCH,precision-score-VATH,precision-score-HEWA,precision-score-SWTH,precision-score-HAFL,precision-score-WETA,precision-score-BHGB,precision-score-GCKI,precision-score-WAVI,precision-score-MGWA,precision-score-STJA,precision-score-CONI,recall-score-BRCR,recall-score-PAWR,recall-score-PSFL,recall-score-RBNU,recall-score-DEJU,recall-score-OSFL,recall-score-HETH,recall-score-CBCH,recall-score-VATH,recall-score-HEWA,recall-score-SWTH,recall-score-HAFL,recall-score-WETA,recall-score-BHGB,recall-score-GCKI,recall-score-WAVI,recall-score-MGWA,recall-score-STJA,recall-score-CONI,f1-score-BRCR,f1-score-PAWR,f1-score-PSFL,f1-score-RBNU,f1-score-DEJU,f1-score-OSFL,f1-score-HETH,f1-score-CBCH,f1-score-VATH,f1-score-HEWA,f1-score-SWTH,f1-score-HAFL,f1-score-WETA,f1-score-BHGB,f1-score-GCKI,f1-score-WAVI,f1-score-MGWA,f1-score-STJA,f1-score-CONI,fbeta-score-BRCR,fbeta-score-PAWR,fbeta-score-PSFL,fbeta-score-RBNU,fbeta-score-DEJU,fbeta-score-OSFL,fbeta-score-HETH,fbeta-score-CBCH,fbeta-score-VATH,fbeta-score-HEWA,fbeta-score-SWTH,fbeta-score-HAFL,fbeta-score-WETA,fbeta-score-BHGB,fbeta-score-GCKI,fbeta-score-WAVI,fbeta-score-MGWA,fbeta-score-STJA,fbeta-score-CONI,jaccard-score-BRCR,jaccard-score-PAWR,jaccard-score-PSFL,jaccard-score-RBNU,jaccard-score-DEJU,jaccard-score-OSFL,jaccard-score-HETH,jaccard-score-CBCH,jaccard-score-VATH,jaccard-score-HEWA,jaccard-score-SWTH,jaccard-score-HAFL,jaccard-score-WETA,jaccard-score-BHGB,jaccard-score-GCKI,jaccard-score-WAVI,jaccard-score-MGWA,jaccard-score-STJA,jaccard-score-CONI\n",
            "0.16599026450285032,0.208955223880597,0.13233912181953641,0.13673291608692004,0.15933416428772468,0.25925925925925924,0.14296150593201268,0.23140495867768596,0.14634518676605035,0.2173913043478261,0.0196078431372549,0.19195046439628483,0.08445809323477566,0.1308411214953271,23.432988277126885,0.0,0.3333333333333333,0.23076923076923078,0.0,0.0,1.0,0.2857142857142857,0.0,0.07692307692307693,0.3,0.30434782608695654,0.0,0.2727272727272727,0.0,0.1,0.0,0.0,0.0,0.25,0.0,0.5,0.42857142857142855,0.0,0.0,0.2,0.16666666666666666,0.0,0.14285714285714285,0.2727272727272727,0.4117647058823529,0.0,0.42857142857142855,0.0,0.14285714285714285,0.0,0.0,0.0,0.3333333333333333,0.0,0.4,0.3,0.0,0.0,0.33333333333333337,0.2105263157894737,0.0,0.1,0.28571428571428564,0.35,0.0,0.33333333333333326,0.0,0.11764705882352941,0.0,0.0,0.0,0.28571428571428575,0.0,0.3571428571428571,0.2542372881355932,0.0,0.0,0.5555555555555556,0.24999999999999997,0.0,0.08474576271186442,0.29411764705882354,0.3211009174311927,0.0,0.29411764705882354,0.0,0.10638297872340426,0.0,0.0,0.0,0.2631578947368421,0.0,0.25,0.17647058823529413,0.0,0.0,0.2,0.11764705882352941,0.0,0.05263157894736842,0.16666666666666666,0.21212121212121213,0.0,0.2,0.0,0.0625,0.0,0.0,0.0,0.16666666666666666\n"
          ]
        }
      ]
    }
  ]
}