{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 필요한 모듈 import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.pipeline import FeatureUnion\n",
    "from imblearn.pipeline import make_pipeline, Pipeline\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.model_selection import StratifiedKFold, GridSearchCV, RandomizedSearchCV, train_test_split\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.discriminant_analysis import LinearDiscriminantAnalysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.feature_selection import VarianceThreshold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "APCFP = pd.read_csv('finalfingerprint_sub_apc.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target_name_bin</th>\n",
       "      <th>target_name_ter</th>\n",
       "      <th>target_name_quater</th>\n",
       "      <th>smiles</th>\n",
       "      <th>APC2D1_C_C</th>\n",
       "      <th>APC2D1_C_N</th>\n",
       "      <th>APC2D1_C_O</th>\n",
       "      <th>APC2D1_C_S</th>\n",
       "      <th>APC2D1_C_P</th>\n",
       "      <th>APC2D1_C_F</th>\n",
       "      <th>...</th>\n",
       "      <th>SubFPC303</th>\n",
       "      <th>SubFPC304</th>\n",
       "      <th>SubFPC305</th>\n",
       "      <th>SubFPC306</th>\n",
       "      <th>SubFPC307</th>\n",
       "      <th>bond:C=S_carbonyl_thio_generic</th>\n",
       "      <th>bond:CN_amine_pri-NH2_aromatic</th>\n",
       "      <th>bond:CS_sulfide</th>\n",
       "      <th>bond:S=O_sulfonyl_generic</th>\n",
       "      <th>ring:hetero_[6_6]_O_benzopyrone_(1_4-)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "      <td>A1</td>\n",
       "      <td>Nc1ccccc1</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "      <td>A1</td>\n",
       "      <td>COc1ccc(N)cc1</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "      <td>A1</td>\n",
       "      <td>COP(=S)(OC)SCn1nnc2ccccc2c1=O</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "      <td>A1</td>\n",
       "      <td>CC(C)(c1ccc(O)cc1)c1ccc(O)cc1</td>\n",
       "      <td>16</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>A</td>\n",
       "      <td>A</td>\n",
       "      <td>A1</td>\n",
       "      <td>CC(C)(C)c1cc(O)ccc1O</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>582</td>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>CSCCCCN=C=S</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>583</td>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>CCCN=C=S</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>584</td>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>CS(=O)CCCCC#N</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>585</td>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>CSCCCCC#N</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>586</td>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>C</td>\n",
       "      <td>C=CCSC#N</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>587 rows × 1096 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    target_name_bin target_name_ter target_name_quater  \\\n",
       "0                 A               A                 A1   \n",
       "1                 A               A                 A1   \n",
       "2                 A               A                 A1   \n",
       "3                 A               A                 A1   \n",
       "4                 A               A                 A1   \n",
       "..              ...             ...                ...   \n",
       "582               B               C                  C   \n",
       "583               B               C                  C   \n",
       "584               B               C                  C   \n",
       "585               B               C                  C   \n",
       "586               B               C                  C   \n",
       "\n",
       "                            smiles  APC2D1_C_C  APC2D1_C_N  APC2D1_C_O  \\\n",
       "0                        Nc1ccccc1           6           1           0   \n",
       "1                    COc1ccc(N)cc1           6           1           2   \n",
       "2    COP(=S)(OC)SCn1nnc2ccccc2c1=O           7           3           3   \n",
       "3    CC(C)(c1ccc(O)cc1)c1ccc(O)cc1          16           0           2   \n",
       "4             CC(C)(C)c1cc(O)ccc1O          10           0           2   \n",
       "..                             ...         ...         ...         ...   \n",
       "582                    CSCCCCN=C=S           3           2           0   \n",
       "583                       CCCN=C=S           2           2           0   \n",
       "584                  CS(=O)CCCCC#N           4           1           0   \n",
       "585                      CSCCCCC#N           4           1           0   \n",
       "586                       C=CCSC#N           2           1           0   \n",
       "\n",
       "     APC2D1_C_S  APC2D1_C_P  APC2D1_C_F  ...  SubFPC303  SubFPC304  SubFPC305  \\\n",
       "0             0           0           0  ...          0          0          0   \n",
       "1             0           0           0  ...          0          0          0   \n",
       "2             1           0           0  ...          0          0          0   \n",
       "3             0           0           0  ...          0          0          0   \n",
       "4             0           0           0  ...          0          0          0   \n",
       "..          ...         ...         ...  ...        ...        ...        ...   \n",
       "582           3           0           0  ...          0          0          0   \n",
       "583           1           0           0  ...          0          0          0   \n",
       "584           2           0           0  ...          0          0          0   \n",
       "585           2           0           0  ...          0          0          0   \n",
       "586           2           0           0  ...          0          0          0   \n",
       "\n",
       "     SubFPC306  SubFPC307  bond:C=S_carbonyl_thio_generic  \\\n",
       "0            0          6                               0   \n",
       "1            0          6                               0   \n",
       "2            0          9                               0   \n",
       "3            0         13                               0   \n",
       "4            0          7                               0   \n",
       "..         ...        ...                             ...   \n",
       "582          0          0                               1   \n",
       "583          0          0                               1   \n",
       "584          0          1                               0   \n",
       "585          0          0                               0   \n",
       "586          0          1                               0   \n",
       "\n",
       "     bond:CN_amine_pri-NH2_aromatic  bond:CS_sulfide  \\\n",
       "0                                 1                0   \n",
       "1                                 1                0   \n",
       "2                                 0                1   \n",
       "3                                 0                0   \n",
       "4                                 0                0   \n",
       "..                              ...              ...   \n",
       "582                               0                1   \n",
       "583                               0                0   \n",
       "584                               0                0   \n",
       "585                               0                1   \n",
       "586                               0                1   \n",
       "\n",
       "     bond:S=O_sulfonyl_generic  ring:hetero_[6_6]_O_benzopyrone_(1_4-)  \n",
       "0                            0                                       0  \n",
       "1                            0                                       0  \n",
       "2                            0                                       0  \n",
       "3                            0                                       0  \n",
       "4                            0                                       0  \n",
       "..                         ...                                     ...  \n",
       "582                          0                                       0  \n",
       "583                          0                                       0  \n",
       "584                          0                                       0  \n",
       "585                          0                                       0  \n",
       "586                          0                                       0  \n",
       "\n",
       "[587 rows x 1096 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "APCFP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_bin = APCFP.loc[:, 'target_name_bin']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_bin = pd.DataFrame(target_bin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_ter = APCFP.loc[:, 'target_name_ter']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_ter = pd.DataFrame(target_ter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_quater = APCFP.loc[:, 'target_name_quater']\n",
    "target_quater = pd.DataFrame(target_quater)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target_name_ter</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>582</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>583</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>584</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>585</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>586</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>587 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    target_name_ter\n",
       "0                 A\n",
       "1                 A\n",
       "2                 A\n",
       "3                 A\n",
       "4                 A\n",
       "..              ...\n",
       "582               C\n",
       "583               C\n",
       "584               C\n",
       "585               C\n",
       "586               C\n",
       "\n",
       "[587 rows x 1 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target_ter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target_name_quater</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>A1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>A1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>A1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>A1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>A1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>582</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>583</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>584</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>585</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>586</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>587 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    target_name_quater\n",
       "0                   A1\n",
       "1                   A1\n",
       "2                   A1\n",
       "3                   A1\n",
       "4                   A1\n",
       "..                 ...\n",
       "582                  C\n",
       "583                  C\n",
       "584                  C\n",
       "585                  C\n",
       "586                  C\n",
       "\n",
       "[587 rows x 1 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target_quater"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "features = APCFP.loc[:, 'APC2D1_C_C':'ring:hetero_[6_6]_O_benzopyrone_(1_4-)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APC2D1_C_C</th>\n",
       "      <th>APC2D1_C_N</th>\n",
       "      <th>APC2D1_C_O</th>\n",
       "      <th>APC2D1_C_S</th>\n",
       "      <th>APC2D1_C_P</th>\n",
       "      <th>APC2D1_C_F</th>\n",
       "      <th>APC2D1_C_Cl</th>\n",
       "      <th>APC2D1_C_Br</th>\n",
       "      <th>APC2D1_C_I</th>\n",
       "      <th>APC2D1_C_B</th>\n",
       "      <th>...</th>\n",
       "      <th>SubFPC303</th>\n",
       "      <th>SubFPC304</th>\n",
       "      <th>SubFPC305</th>\n",
       "      <th>SubFPC306</th>\n",
       "      <th>SubFPC307</th>\n",
       "      <th>bond:C=S_carbonyl_thio_generic</th>\n",
       "      <th>bond:CN_amine_pri-NH2_aromatic</th>\n",
       "      <th>bond:CS_sulfide</th>\n",
       "      <th>bond:S=O_sulfonyl_generic</th>\n",
       "      <th>ring:hetero_[6_6]_O_benzopyrone_(1_4-)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>16</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>582</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>583</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>584</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>585</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>586</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>587 rows × 1092 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     APC2D1_C_C  APC2D1_C_N  APC2D1_C_O  APC2D1_C_S  APC2D1_C_P  APC2D1_C_F  \\\n",
       "0             6           1           0           0           0           0   \n",
       "1             6           1           2           0           0           0   \n",
       "2             7           3           3           1           0           0   \n",
       "3            16           0           2           0           0           0   \n",
       "4            10           0           2           0           0           0   \n",
       "..          ...         ...         ...         ...         ...         ...   \n",
       "582           3           2           0           3           0           0   \n",
       "583           2           2           0           1           0           0   \n",
       "584           4           1           0           2           0           0   \n",
       "585           4           1           0           2           0           0   \n",
       "586           2           1           0           2           0           0   \n",
       "\n",
       "     APC2D1_C_Cl  APC2D1_C_Br  APC2D1_C_I  APC2D1_C_B  ...  SubFPC303  \\\n",
       "0              0            0           0           0  ...          0   \n",
       "1              0            0           0           0  ...          0   \n",
       "2              0            0           0           0  ...          0   \n",
       "3              0            0           0           0  ...          0   \n",
       "4              0            0           0           0  ...          0   \n",
       "..           ...          ...         ...         ...  ...        ...   \n",
       "582            0            0           0           0  ...          0   \n",
       "583            0            0           0           0  ...          0   \n",
       "584            0            0           0           0  ...          0   \n",
       "585            0            0           0           0  ...          0   \n",
       "586            0            0           0           0  ...          0   \n",
       "\n",
       "     SubFPC304  SubFPC305  SubFPC306  SubFPC307  \\\n",
       "0            0          0          0          6   \n",
       "1            0          0          0          6   \n",
       "2            0          0          0          9   \n",
       "3            0          0          0         13   \n",
       "4            0          0          0          7   \n",
       "..         ...        ...        ...        ...   \n",
       "582          0          0          0          0   \n",
       "583          0          0          0          0   \n",
       "584          0          0          0          1   \n",
       "585          0          0          0          0   \n",
       "586          0          0          0          1   \n",
       "\n",
       "     bond:C=S_carbonyl_thio_generic  bond:CN_amine_pri-NH2_aromatic  \\\n",
       "0                                 0                               1   \n",
       "1                                 0                               1   \n",
       "2                                 0                               0   \n",
       "3                                 0                               0   \n",
       "4                                 0                               0   \n",
       "..                              ...                             ...   \n",
       "582                               1                               0   \n",
       "583                               1                               0   \n",
       "584                               0                               0   \n",
       "585                               0                               0   \n",
       "586                               0                               0   \n",
       "\n",
       "     bond:CS_sulfide  bond:S=O_sulfonyl_generic  \\\n",
       "0                  0                          0   \n",
       "1                  0                          0   \n",
       "2                  1                          0   \n",
       "3                  0                          0   \n",
       "4                  0                          0   \n",
       "..               ...                        ...   \n",
       "582                1                          0   \n",
       "583                0                          0   \n",
       "584                0                          0   \n",
       "585                1                          0   \n",
       "586                1                          0   \n",
       "\n",
       "     ring:hetero_[6_6]_O_benzopyrone_(1_4-)  \n",
       "0                                         0  \n",
       "1                                         0  \n",
       "2                                         0  \n",
       "3                                         0  \n",
       "4                                         0  \n",
       "..                                      ...  \n",
       "582                                       0  \n",
       "583                                       0  \n",
       "584                                       0  \n",
       "585                                       0  \n",
       "586                                       0  \n",
       "\n",
       "[587 rows x 1092 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "from imblearn.over_sampling import *\n",
    "from sklearn.neural_network import MLPClassifier"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# AtomPairCount_Binary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "seed=28\n",
    "X_train_bin, X_test_bin, y_train_bin, y_test_bin = train_test_split(features, target_bin, test_size=0.2, random_state=seed, stratify=target_bin)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe_ann_pca = Pipeline([(\"std\", MinMaxScaler()),\n",
    "                         (\"thresholder\", VarianceThreshold(threshold=0.01)),\n",
    "                         (\"PCA\", PCA()),\n",
    "                         (\"smote\", SMOTE(random_state=seed)),\n",
    "                         (\"classifier\", MLPClassifier(random_state=seed, max_iter=10000))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "random_grid_pca = [{\"PCA__n_components\": [1, 2, 3],\n",
    "                   \"classifier__hidden_layer_sizes\": [(10,), (50,), (100,), (200,)],\n",
    "                   \"classifier__activation\": ['relu', 'logistic', 'tanh', 'identity'],\n",
    "                   \"classifier__solver\": ['lbfgs', 'adam', 'sgd'],\n",
    "                   \"classifier__alpha\": [0.00001, 0.001, 0.1, 10]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv = StratifiedKFold(n_splits=5, random_state=seed, shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "rand_ann_pca = RandomizedSearchCV(pipe_ann_pca, random_grid_pca, n_iter=100, cv=cv, random_state=seed, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   13.8s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:   46.0s\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  1.9min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  4.0min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('PCA',\n",
       "                                              PCA(copy=True,\n",
       "                                                  iterated_power='auto',\n",
       "                                                  n_components=None,\n",
       "                                                  random_state=None,\n",
       "                                                  svd_solver='auto', tol=0.0,\n",
       "                                                  whiten=Fal...\n",
       "                   param_distributions=[{'PCA__n_components': [1, 2, 3],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.fit(X_train_bin, y_train_bin.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5521919013688538"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'lbfgs',\n",
       " 'classifier__hidden_layer_sizes': (100,),\n",
       " 'classifier__alpha': 1e-05,\n",
       " 'classifier__activation': 'logistic',\n",
       " 'PCA__n_components': 3}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_pca_bin = [{\"PCA__n_components\": [3],\n",
    "                   \"classifier__hidden_layer_sizes\": [(100,), (100, 100,), (100, 100, 100,), (100, 100, 100, 100,), (100, 100, 100, 100, 100,)],\n",
    "                   \"classifier__activation\": ['logistic'],\n",
    "                   \"classifier__solver\": ['lbfgs'],\n",
    "                   \"classifier__alpha\": [0.00001, 0.00005, 0.0001, 0.0005]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_pca_bin = GridSearchCV(pipe_ann_pca, param_grid_pca_bin, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 20 candidates, totalling 100 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   50.5s\n",
      "[Parallel(n_jobs=-1)]: Done 100 out of 100 | elapsed:  3.7min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('PCA',\n",
       "                                        PCA(copy=True, iterated_power='auto',\n",
       "                                            n_components=None,\n",
       "                                            random_state=None,\n",
       "                                            svd_solver='auto', tol=0.0,\n",
       "                                            whiten=False)),\n",
       "                                       (...\n",
       "             param_grid=[{'PCA__n_components': [3],\n",
       "                          'classifier__activation': ['logistic'],\n",
       "                          'classifier__alpha': [1e-05, 5e-05, 0.0001, 0.0005],\n",
       "                          'classifier__hidden_layer_sizes': [(100,), (100, 100),\n",
       "                                                             (100, 100, 100),\n",
       "                                                             (100, 100, 100,\n",
       "                                                              100),\n",
       "                                                             (100, 100, 100,\n",
       "                                                              100, 100)],\n",
       "                          'classifier__solver': ['lbfgs']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_bin.fit(X_train_bin, y_train_bin.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'PCA__n_components': 3,\n",
       " 'classifier__activation': 'logistic',\n",
       " 'classifier__alpha': 1e-05,\n",
       " 'classifier__hidden_layer_sizes': (100, 100),\n",
       " 'classifier__solver': 'lbfgs'}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_bin.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5789953331756281"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_bin.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4008\n"
     ]
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "bin_pca_predict = clf_ann_pca_bin.predict(X_test_bin)\n",
    "testscore_bin_pca = metrics.f1_score(y_test_bin, bin_pca_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_bin_pca))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[39 58]\n",
      " [ 9 12]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_bin, bin_pca_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Binary_APC_ANN_PCA.pkl']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import joblib\n",
    "joblib.dump(clf_ann_pca_bin, \"Binary_APC_ANN_PCA.pkl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "LDA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe_ann_lda = Pipeline([(\"std\", MinMaxScaler()),\n",
    "                        (\"thresholder\", VarianceThreshold(threshold=0.01)),\n",
    "                        (\"LDA\", LinearDiscriminantAnalysis()),\n",
    "                        (\"smote\", SMOTE(random_state=seed)),\n",
    "                        (\"classifier\", MLPClassifier(random_state=seed, max_iter=10000))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "random_grid_lda_bin = [{\"LDA__n_components\": [1],\n",
    "                        \"classifier__hidden_layer_sizes\": [(10,), (50,), (100,), (200,)],\n",
    "                        \"classifier__activation\": ['relu', 'logistic', 'tanh', 'identity'],\n",
    "                        \"classifier__solver\": ['lbfgs', 'adam', 'sgd'],\n",
    "                        \"classifier__alpha\": [0.00001, 0.001, 0.1, 10]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "rand_ann_lda_bin = RandomizedSearchCV(pipe_ann_lda, random_grid_lda_bin, n_iter=100, cv=cv, random_state=seed, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:    9.9s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:   38.3s\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:   56.9s\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  2.7min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('LDA',\n",
       "                                              LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                         priors=None,\n",
       "                                                                         shrinkage=None,\n",
       "                                                                         solver='svd',\n",
       "                                                                         store_covariance=False,...\n",
       "                   param_distributions=[{'LDA__n_components': [1],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_bin.fit(X_train_bin, y_train_bin.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6335683345630023"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_bin.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'lbfgs',\n",
       " 'classifier__hidden_layer_sizes': (200,),\n",
       " 'classifier__alpha': 1e-05,\n",
       " 'classifier__activation': 'logistic',\n",
       " 'LDA__n_components': 1}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_bin.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_lda_bin = [{\"LDA__n_components\": [1],\n",
    "                       \"classifier__hidden_layer_sizes\": [(200,), (200, 200,), (200, 200, 200,), (200, 200, 200, 200,), (200, 200, 200, 200, 200,)],\n",
    "                       \"classifier__activation\": ['logistic'],\n",
    "                       \"classifier__solver\": ['lbfgs'],\n",
    "                       \"classifier__alpha\": [0.00001, 0.00005, 0.0001, 0.0005, 0.001]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_lda_bin = GridSearchCV(pipe_ann_lda, param_grid_lda_bin, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 25 candidates, totalling 125 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   22.9s\n",
      "[Parallel(n_jobs=-1)]: Done 125 out of 125 | elapsed: 41.9min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('LDA',\n",
       "                                        LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                   priors=None,\n",
       "                                                                   shrinkage=None,\n",
       "                                                                   solver='svd',\n",
       "                                                                   store_covariance=False,\n",
       "                                                                   tol=0....\n",
       "             param_grid=[{'LDA__n_components': [1],\n",
       "                          'classifier__activation': ['logistic'],\n",
       "                          'classifier__alpha': [1e-05, 5e-05, 0.0001, 0.0005,\n",
       "                                                0.001],\n",
       "                          'classifier__hidden_layer_sizes': [(200,), (200, 200),\n",
       "                                                             (200, 200, 200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200, 200)],\n",
       "                          'classifier__solver': ['lbfgs']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_bin.fit(X_train_bin, y_train_bin.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'LDA__n_components': 1,\n",
       " 'classifier__activation': 'logistic',\n",
       " 'classifier__alpha': 1e-05,\n",
       " 'classifier__hidden_layer_sizes': (200,),\n",
       " 'classifier__solver': 'lbfgs'}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_bin.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6335683345630023"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_bin.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.5851\n"
     ]
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "bin_lda_predict = clf_ann_lda_bin.predict(X_test_bin)\n",
    "testscore_bin_lda = metrics.f1_score(y_test_bin, bin_lda_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_bin_lda))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[73 24]\n",
      " [11 10]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_bin, bin_lda_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Binary_APC_ANN_LDA.pkl']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import joblib\n",
    "joblib.dump(clf_ann_lda_bin, \"Binary_APC_ANN_LDA.pkl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Morgan_Ternary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train_ter, X_test_ter, y_train_ter, y_test_ter = train_test_split(features, target_ter, test_size=0.2, random_state=seed, stratify=target_ter)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   41.7s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  2.1min\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  5.3min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  7.9min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('PCA',\n",
       "                                              PCA(copy=True,\n",
       "                                                  iterated_power='auto',\n",
       "                                                  n_components=None,\n",
       "                                                  random_state=None,\n",
       "                                                  svd_solver='auto', tol=0.0,\n",
       "                                                  whiten=Fal...\n",
       "                   param_distributions=[{'PCA__n_components': [1, 2, 3],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.fit(X_train_ter, y_train_ter.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4255029778502319"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'lbfgs',\n",
       " 'classifier__hidden_layer_sizes': (10,),\n",
       " 'classifier__alpha': 1e-05,\n",
       " 'classifier__activation': 'tanh',\n",
       " 'PCA__n_components': 3}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_pca_ter = [{\"PCA__n_components\": [3],\n",
    "                       \"classifier__hidden_layer_sizes\": [(10,), (10, 10,), (10, 10, 10,), (10, 10, 10, 10,), (10, 10, 10, 10, 10,)],\n",
    "                       \"classifier__activation\": ['tanh'],\n",
    "                       \"classifier__solver\": ['lbfgs'],\n",
    "                       \"classifier__alpha\": [0.00005, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_pca_ter = GridSearchCV(pipe_ann_pca, param_grid_pca_ter, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 35 candidates, totalling 175 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   46.1s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  4.6min\n",
      "[Parallel(n_jobs=-1)]: Done 175 out of 175 | elapsed:  5.6min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('PCA',\n",
       "                                        PCA(copy=True, iterated_power='auto',\n",
       "                                            n_components=None,\n",
       "                                            random_state=None,\n",
       "                                            svd_solver='auto', tol=0.0,\n",
       "                                            whiten=False)),\n",
       "                                       (...\n",
       "             iid='deprecated', n_jobs=-1,\n",
       "             param_grid=[{'PCA__n_components': [3],\n",
       "                          'classifier__activation': ['tanh'],\n",
       "                          'classifier__alpha': [5e-05, 0.0001, 0.0005, 0.001,\n",
       "                                                0.005, 0.01, 0.05],\n",
       "                          'classifier__hidden_layer_sizes': [(10,), (10, 10),\n",
       "                                                             (10, 10, 10),\n",
       "                                                             (10, 10, 10, 10),\n",
       "                                                             (10, 10, 10, 10,\n",
       "                                                              10)],\n",
       "                          'classifier__solver': ['lbfgs']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_ter.fit(X_train_ter, y_train_ter.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'PCA__n_components': 3,\n",
       " 'classifier__activation': 'tanh',\n",
       " 'classifier__alpha': 5e-05,\n",
       " 'classifier__hidden_layer_sizes': (10,),\n",
       " 'classifier__solver': 'lbfgs'}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_ter.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.453891322636644"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_ter.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4030\n"
     ]
    }
   ],
   "source": [
    "ter_pca_predict = clf_ann_pca_ter.predict(X_test_ter)\n",
    "testscore_ter_pca = metrics.f1_score(y_test_ter, ter_pca_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_ter_pca))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[34 25 12]\n",
      " [12  9  5]\n",
      " [ 5  7  9]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_ter, ter_pca_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ternary_APC_ANN_PCA.pkl']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_ann_pca_ter, 'Ternary_APC_ANN_PCA.pkl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "LDA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "random_grid_lda_ter = [{\"LDA__n_components\": [1, 2],\n",
    "                        \"classifier__hidden_layer_sizes\": [(10,), (50,), (100,), (200,)],\n",
    "                        \"classifier__activation\": ['relu', 'logistic', 'tanh', 'identity'],\n",
    "                        \"classifier__solver\": ['lbfgs', 'adam', 'sgd'],\n",
    "                        \"classifier__alpha\": [0.00001, 0.001, 0.1, 10]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "rand_ann_lda_ter = RandomizedSearchCV(pipe_ann_lda, random_grid_lda_ter, n_iter=100, cv=cv, random_state=seed, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   15.6s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  1.3min\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  2.7min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  6.1min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('LDA',\n",
       "                                              LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                         priors=None,\n",
       "                                                                         shrinkage=None,\n",
       "                                                                         solver='svd',\n",
       "                                                                         store_covariance=False,...\n",
       "                   param_distributions=[{'LDA__n_components': [1, 2],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_ter.fit(X_train_ter, y_train_ter.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48399687241472683"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_ter.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'lbfgs',\n",
       " 'classifier__hidden_layer_sizes': (200,),\n",
       " 'classifier__alpha': 0.1,\n",
       " 'classifier__activation': 'relu',\n",
       " 'LDA__n_components': 2}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_ter.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_lda_ter = [{\"LDA__n_components\": [2],\n",
    "                       \"classifier__hidden_layer_sizes\": [(200,), (200, 200,), (200, 200, 200,), (200, 200, 200, 200,), (200, 200, 200, 200, 200,)],\n",
    "                       \"classifier__activation\": ['relu'],\n",
    "                       \"classifier__solver\": ['lbfgs'],\n",
    "                       \"classifier__alpha\": [0.005, 0.01, 0.05, 0.1, 0.5, 1, 5]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_lda_ter = GridSearchCV(pipe_ann_lda, param_grid_lda_ter, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 35 candidates, totalling 175 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed: 11.8min\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed: 146.4min\n",
      "[Parallel(n_jobs=-1)]: Done 175 out of 175 | elapsed: 169.5min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('LDA',\n",
       "                                        LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                   priors=None,\n",
       "                                                                   shrinkage=None,\n",
       "                                                                   solver='svd',\n",
       "                                                                   store_covariance=False,\n",
       "                                                                   tol=0....\n",
       "             iid='deprecated', n_jobs=-1,\n",
       "             param_grid=[{'LDA__n_components': [2],\n",
       "                          'classifier__activation': ['relu'],\n",
       "                          'classifier__alpha': [0.005, 0.01, 0.05, 0.1, 0.5, 1,\n",
       "                                                5],\n",
       "                          'classifier__hidden_layer_sizes': [(200,), (200, 200),\n",
       "                                                             (200, 200, 200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200, 200)],\n",
       "                          'classifier__solver': ['lbfgs']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_ter.fit(X_train_ter, y_train_ter.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'LDA__n_components': 2,\n",
       " 'classifier__activation': 'relu',\n",
       " 'classifier__alpha': 0.1,\n",
       " 'classifier__hidden_layer_sizes': (200,),\n",
       " 'classifier__solver': 'lbfgs'}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_ter.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48399687241472683"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_ter.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4224\n"
     ]
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "ter_lda_predict = clf_ann_lda_ter.predict(X_test_ter)\n",
    "testscore_ter_lda = metrics.f1_score(y_test_ter, ter_lda_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_ter_lda))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[44 17 10]\n",
      " [15  7  4]\n",
      " [ 3 10  8]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_ter, ter_lda_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ternary_APC_ANN_LDA.pkl']"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import joblib\n",
    "joblib.dump(clf_ann_lda_ter, 'Ternary_APC_ANN_LDA.pkl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Quaternary(w/o SMOTE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train_quater, X_test_quater, y_train_quater, y_test_quater = train_test_split(features, target_quater, test_size=0.2, random_state=seed, stratify=target_quater)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe_ann_pca_smotx = Pipeline([(\"std\", MinMaxScaler()),\n",
    "                              (\"thresholder\", VarianceThreshold(threshold=0.01)),\n",
    "                              (\"PCA\", PCA()),\n",
    "                              (\"classifier\", MLPClassifier(random_state=seed, max_iter=10000))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "rand_ann_pca_smotx = RandomizedSearchCV(pipe_ann_pca_smotx, random_grid_pca, n_iter=100, cv=cv, random_state=seed, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   35.3s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  1.4min\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  3.2min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  4.3min finished\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:470: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "  self.n_iter_ = _check_optimize_result(\"lbfgs\", opt_res, self.max_iter)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('PCA',\n",
       "                                              PCA(copy=True,\n",
       "                                                  iterated_power='auto',\n",
       "                                                  n_components=None,\n",
       "                                                  random_state=None,\n",
       "                                                  svd_solver='auto', tol=0.0,\n",
       "                                                  whiten=Fal...\n",
       "                   param_distributions=[{'PCA__n_components': [1, 2, 3],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca_smotx.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.39999282896523203"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca_smotx.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'lbfgs',\n",
       " 'classifier__hidden_layer_sizes': (50,),\n",
       " 'classifier__alpha': 0.001,\n",
       " 'classifier__activation': 'logistic',\n",
       " 'PCA__n_components': 3}"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca_smotx.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_pca_quater = [{\"PCA__n_components\": [3],\n",
    "                       \"classifier__hidden_layer_sizes\": [(50,), (50, 50,), (50, 50, 50,), (50, 50, 50, 50,), (50, 50, 50, 50, 50,)],\n",
    "                       \"classifier__activation\": ['logistic'],\n",
    "                       \"classifier__solver\": ['lbfgs'],\n",
    "                       \"classifier__alpha\": [0.00005, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_pca_smotx = GridSearchCV(pipe_ann_pca_smotx, param_grid_pca_quater, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 35 candidates, totalling 175 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   54.4s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  5.2min\n",
      "[Parallel(n_jobs=-1)]: Done 175 out of 175 | elapsed:  6.5min finished\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:470: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "  self.n_iter_ = _check_optimize_result(\"lbfgs\", opt_res, self.max_iter)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('PCA',\n",
       "                                        PCA(copy=True, iterated_power='auto',\n",
       "                                            n_components=None,\n",
       "                                            random_state=None,\n",
       "                                            svd_solver='auto', tol=0.0,\n",
       "                                            whiten=False)),\n",
       "                                       (...\n",
       "             param_grid=[{'PCA__n_components': [3],\n",
       "                          'classifier__activation': ['logistic'],\n",
       "                          'classifier__alpha': [5e-05, 0.0001, 0.0005, 0.001,\n",
       "                                                0.005, 0.01, 0.05],\n",
       "                          'classifier__hidden_layer_sizes': [(50,), (50, 50),\n",
       "                                                             (50, 50, 50),\n",
       "                                                             (50, 50, 50, 50),\n",
       "                                                             (50, 50, 50, 50,\n",
       "                                                              50)],\n",
       "                          'classifier__solver': ['lbfgs']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_smotx.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'PCA__n_components': 3,\n",
       " 'classifier__activation': 'logistic',\n",
       " 'classifier__alpha': 0.001,\n",
       " 'classifier__hidden_layer_sizes': (50,),\n",
       " 'classifier__solver': 'lbfgs'}"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_smotx.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.39999282896523203"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_smotx.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4372\n"
     ]
    }
   ],
   "source": [
    "quater_pca_predict = clf_ann_pca_smotx.predict(X_test_quater)\n",
    "testscore_quater_pca = metrics.f1_score(y_test_quater, quater_pca_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_quater_pca))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[14  8  2  1]\n",
      " [11 24  5  6]\n",
      " [ 2  9  9  6]\n",
      " [ 4  6  4  7]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_quater, quater_pca_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Quaternary_APC_ANN_PCA_smotx.pkl']"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_ann_pca_smotx, 'Quaternary_APC_ANN_PCA_smotx.pkl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "LDA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "random_grid_lda_quater = [{\"LDA__n_components\": [1, 2, 3],\n",
    "                           \"classifier__hidden_layer_sizes\": [(10,), (50,), (100,), (200,)],\n",
    "                           \"classifier__activation\": ['relu', 'logistic', 'tanh', 'identity'],\n",
    "                           \"classifier__solver\": ['lbfgs', 'adam', 'sgd'],\n",
    "                           \"classifier__alpha\": [0.00001, 0.001, 0.1, 10]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe_ann_lda_smotx = Pipeline([(\"std\", MinMaxScaler()),\n",
    "                              (\"thresholder\", VarianceThreshold(threshold=0.01)),\n",
    "                              (\"LDA\", LinearDiscriminantAnalysis()),\n",
    "                              (\"classifier\", MLPClassifier(random_state=seed, max_iter=10000))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "rand_ann_lda_smotx = RandomizedSearchCV(pipe_ann_lda_smotx, random_grid_lda_quater, n_iter=100, cv=cv, random_state=seed, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   37.0s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  1.3min\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  2.3min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  2.7min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('LDA',\n",
       "                                              LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                         priors=None,\n",
       "                                                                         shrinkage=None,\n",
       "                                                                         solver='svd',\n",
       "                                                                         store_covariance=False,...\n",
       "                   param_distributions=[{'LDA__n_components': [1, 2, 3],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_smotx.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4096238223269629"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_smotx.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'sgd',\n",
       " 'classifier__hidden_layer_sizes': (10,),\n",
       " 'classifier__alpha': 0.1,\n",
       " 'classifier__activation': 'relu',\n",
       " 'LDA__n_components': 2}"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_smotx.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_lda_quater = [{\"LDA__n_components\": [2],\n",
    "                       \"classifier__hidden_layer_sizes\": [(10,), (10, 10,), (10, 10, 10,), (10, 10, 10, 10,), (10, 10, 10, 10, 10,)],\n",
    "                       \"classifier__activation\": ['relu'],\n",
    "                       \"classifier__solver\": ['sgd'],\n",
    "                       \"classifier__alpha\": [0.005, 0.01, 0.05, 0.1, 0.5, 1, 5]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_lda_smotx = GridSearchCV(pipe_ann_lda_smotx, param_grid_lda_quater, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 35 candidates, totalling 175 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   11.0s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:   26.9s\n",
      "[Parallel(n_jobs=-1)]: Done 175 out of 175 | elapsed:   35.0s finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('LDA',\n",
       "                                        LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                   priors=None,\n",
       "                                                                   shrinkage=None,\n",
       "                                                                   solver='svd',\n",
       "                                                                   store_covariance=False,\n",
       "                                                                   tol=0....\n",
       "             iid='deprecated', n_jobs=-1,\n",
       "             param_grid=[{'LDA__n_components': [2],\n",
       "                          'classifier__activation': ['relu'],\n",
       "                          'classifier__alpha': [0.005, 0.01, 0.05, 0.1, 0.5, 1,\n",
       "                                                5],\n",
       "                          'classifier__hidden_layer_sizes': [(10,), (10, 10),\n",
       "                                                             (10, 10, 10),\n",
       "                                                             (10, 10, 10, 10),\n",
       "                                                             (10, 10, 10, 10,\n",
       "                                                              10)],\n",
       "                          'classifier__solver': ['sgd']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_smotx.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'LDA__n_components': 2,\n",
       " 'classifier__activation': 'relu',\n",
       " 'classifier__alpha': 0.005,\n",
       " 'classifier__hidden_layer_sizes': (10,),\n",
       " 'classifier__solver': 'sgd'}"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_smotx.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4096238223269629"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_smotx.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4218\n"
     ]
    }
   ],
   "source": [
    "quater_pca_predict = clf_ann_lda_smotx.predict(X_test_quater)\n",
    "testscore_quater_pca = metrics.f1_score(y_test_quater, quater_pca_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_quater_pca))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[17  7  0  1]\n",
      " [ 9 22  3 12]\n",
      " [ 2 14  3  7]\n",
      " [ 1  6  3 11]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_quater, quater_pca_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Quaternary_APC_ANN_LDA_smotx.pkl']"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_ann_lda_smotx, 'Quaternary_APC_ANN_LDA_smotx.pkl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Quaternary (w/ SMOTE)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   32.5s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  1.8min\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  4.8min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  6.5min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('PCA',\n",
       "                                              PCA(copy=True,\n",
       "                                                  iterated_power='auto',\n",
       "                                                  n_components=None,\n",
       "                                                  random_state=None,\n",
       "                                                  svd_solver='auto', tol=0.0,\n",
       "                                                  whiten=Fal...\n",
       "                   param_distributions=[{'PCA__n_components': [1, 2, 3],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.35272702321954014"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'adam',\n",
       " 'classifier__hidden_layer_sizes': (200,),\n",
       " 'classifier__alpha': 0.001,\n",
       " 'classifier__activation': 'relu',\n",
       " 'PCA__n_components': 3}"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_pca.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_pca_quater_smot = [{\"PCA__n_components\": [3],\n",
    "                               \"classifier__hidden_layer_sizes\": [(200,), (200, 200,), (200, 200, 200,), (200, 200, 200, 200,), (200, 200, 200, 200, 200,)],\n",
    "                               \"classifier__activation\": ['relu'],\n",
    "                               \"classifier__solver\": ['adam'],\n",
    "                               \"classifier__alpha\": [0.00005, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_pca_quater_smot = GridSearchCV(pipe_ann_pca, param_grid_pca_quater_smot, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 35 candidates, totalling 175 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:  1.6min\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  8.1min\n",
      "[Parallel(n_jobs=-1)]: Done 175 out of 175 | elapsed:  9.3min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('PCA',\n",
       "                                        PCA(copy=True, iterated_power='auto',\n",
       "                                            n_components=None,\n",
       "                                            random_state=None,\n",
       "                                            svd_solver='auto', tol=0.0,\n",
       "                                            whiten=False)),\n",
       "                                       (...\n",
       "             param_grid=[{'PCA__n_components': [3],\n",
       "                          'classifier__activation': ['relu'],\n",
       "                          'classifier__alpha': [5e-05, 0.0001, 0.0005, 0.001,\n",
       "                                                0.005, 0.01, 0.05],\n",
       "                          'classifier__hidden_layer_sizes': [(200,), (200, 200),\n",
       "                                                             (200, 200, 200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200, 200)],\n",
       "                          'classifier__solver': ['adam']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_quater_smot.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'PCA__n_components': 3,\n",
       " 'classifier__activation': 'relu',\n",
       " 'classifier__alpha': 0.01,\n",
       " 'classifier__hidden_layer_sizes': (200, 200),\n",
       " 'classifier__solver': 'adam'}"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_quater_smot.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.37698143449720856"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_pca_quater_smot.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4746\n"
     ]
    }
   ],
   "source": [
    "quater_smot_pca_predict = clf_ann_pca_quater_smot.predict(X_test_quater)\n",
    "testscore_quater_smot_pca = metrics.f1_score(y_test_quater, quater_smot_pca_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_quater_smot_pca))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[15  4  3  3]\n",
      " [ 2 17 16 11]\n",
      " [ 2  8 10  6]\n",
      " [ 0  3  6 12]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_quater, quater_smot_pca_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Quaternary_APC_ANN_PCA_smot.pkl']"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_ann_pca_quater_smot, 'Quaternary_APC_ANN_PCA_smot.pkl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "LDA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "rand_ann_lda_quater = RandomizedSearchCV(pipe_ann_lda, random_grid_lda_quater, n_iter=100, cv=cv, random_state=seed, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 100 candidates, totalling 500 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:   46.7s\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  2.0min\n",
      "[Parallel(n_jobs=-1)]: Done 349 tasks      | elapsed:  3.3min\n",
      "[Parallel(n_jobs=-1)]: Done 500 out of 500 | elapsed:  3.9min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RandomizedSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "                   error_score=nan,\n",
       "                   estimator=Pipeline(memory=None,\n",
       "                                      steps=[('std',\n",
       "                                              MinMaxScaler(copy=True,\n",
       "                                                           feature_range=(0,\n",
       "                                                                          1))),\n",
       "                                             ('thresholder',\n",
       "                                              VarianceThreshold(threshold=0.01)),\n",
       "                                             ('LDA',\n",
       "                                              LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                         priors=None,\n",
       "                                                                         shrinkage=None,\n",
       "                                                                         solver='svd',\n",
       "                                                                         store_covariance=False,...\n",
       "                   param_distributions=[{'LDA__n_components': [1, 2, 3],\n",
       "                                         'classifier__activation': ['relu',\n",
       "                                                                    'logistic',\n",
       "                                                                    'tanh',\n",
       "                                                                    'identity'],\n",
       "                                         'classifier__alpha': [1e-05, 0.001,\n",
       "                                                               0.1, 10],\n",
       "                                         'classifier__hidden_layer_sizes': [(10,),\n",
       "                                                                            (50,),\n",
       "                                                                            (100,),\n",
       "                                                                            (200,)],\n",
       "                                         'classifier__solver': ['lbfgs', 'adam',\n",
       "                                                                'sgd']}],\n",
       "                   pre_dispatch='2*n_jobs', random_state=28, refit=True,\n",
       "                   return_train_score=False, scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_quater.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.407606924055982"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_quater.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'classifier__solver': 'adam',\n",
       " 'classifier__hidden_layer_sizes': (200,),\n",
       " 'classifier__alpha': 0.001,\n",
       " 'classifier__activation': 'relu',\n",
       " 'LDA__n_components': 3}"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_ann_lda_quater.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "param_grid_lda_quater_smot = [{\"LDA__n_components\": [3],\n",
    "                               \"classifier__hidden_layer_sizes\": [(200,), (200, 200,), (200, 200, 200,), (200, 200, 200, 200,), (200, 200, 200, 200, 200,)],\n",
    "                               \"classifier__activation\": ['relu'],\n",
    "                               \"classifier__solver\": ['adam'],\n",
    "                               \"classifier__alpha\": [0.00005, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05]}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_ann_lda_quater_smot = GridSearchCV(pipe_ann_lda, param_grid_lda_quater_smot, cv=cv, scoring='f1_macro', verbose=2, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 5 folds for each of 35 candidates, totalling 175 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n",
      "[Parallel(n_jobs=-1)]: Done  25 tasks      | elapsed:  1.4min\n",
      "[Parallel(n_jobs=-1)]: Done 146 tasks      | elapsed:  7.7min\n",
      "[Parallel(n_jobs=-1)]: Done 175 out of 175 | elapsed:  9.0min finished\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=StratifiedKFold(n_splits=5, random_state=28, shuffle=True),\n",
       "             error_score=nan,\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('std',\n",
       "                                        MinMaxScaler(copy=True,\n",
       "                                                     feature_range=(0, 1))),\n",
       "                                       ('thresholder',\n",
       "                                        VarianceThreshold(threshold=0.01)),\n",
       "                                       ('LDA',\n",
       "                                        LinearDiscriminantAnalysis(n_components=None,\n",
       "                                                                   priors=None,\n",
       "                                                                   shrinkage=None,\n",
       "                                                                   solver='svd',\n",
       "                                                                   store_covariance=False,\n",
       "                                                                   tol=0....\n",
       "             param_grid=[{'LDA__n_components': [3],\n",
       "                          'classifier__activation': ['relu'],\n",
       "                          'classifier__alpha': [5e-05, 0.0001, 0.0005, 0.001,\n",
       "                                                0.005, 0.01, 0.05],\n",
       "                          'classifier__hidden_layer_sizes': [(200,), (200, 200),\n",
       "                                                             (200, 200, 200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200),\n",
       "                                                             (200, 200, 200,\n",
       "                                                              200, 200)],\n",
       "                          'classifier__solver': ['adam']}],\n",
       "             pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n",
       "             scoring='f1_macro', verbose=2)"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_quater_smot.fit(X_train_quater, y_train_quater.values.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'LDA__n_components': 3,\n",
       " 'classifier__activation': 'relu',\n",
       " 'classifier__alpha': 0.005,\n",
       " 'classifier__hidden_layer_sizes': (200, 200),\n",
       " 'classifier__solver': 'adam'}"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_quater_smot.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.40966437761403685"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_ann_lda_quater_smot.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 score (test): 0.4152\n"
     ]
    }
   ],
   "source": [
    "quater_smot_lda_predict = clf_ann_lda_quater_smot.predict(X_test_quater)\n",
    "testscore_quater_smot_lda = metrics.f1_score(y_test_quater, quater_smot_lda_predict, average='macro')\n",
    "\n",
    "print(\"f1 score (test): {:.4f}\".format(testscore_quater_smot_lda))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "오차 행렬: \n",
      " [[16  5  4  0]\n",
      " [ 9 18  5 14]\n",
      " [ 1 12  4  9]\n",
      " [ 0  5  4 12]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "print(\"오차 행렬: \\n\", confusion_matrix(y_test_quater, quater_smot_lda_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Quaternary_APC_ANN_LDA_smot.pkl']"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_ann_lda_quater_smot, 'Quaternary_APC_ANN_LDA_smot.pkl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
