Last active
November 26, 2022 23:23
-
-
Save kn1kn1/133526aadf029f50fc5b97564aac29f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "provenance": [] | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "x-VA-SLtBiHb", | |
| "outputId": "91b924fa-e677-4ae8-fb8c-d1d648cc6940" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting onnxruntime\n", | |
| " Downloading onnxruntime-1.13.1-cp37-cp37m-manylinux_2_27_x86_64.whl (4.5 MB)\n", | |
| "\u001b[K |████████████████████████████████| 4.5 MB 5.4 MB/s \n", | |
| "\u001b[?25hCollecting coloredlogs\n", | |
| " Downloading coloredlogs-15.0.1-py2.py3-none-any.whl (46 kB)\n", | |
| "\u001b[K |████████████████████████████████| 46 kB 1.2 MB/s \n", | |
| "\u001b[?25hRequirement already satisfied: numpy>=1.21.6 in /usr/local/lib/python3.7/dist-packages (from onnxruntime) (1.21.6)\n", | |
| "Requirement already satisfied: flatbuffers in /usr/local/lib/python3.7/dist-packages (from onnxruntime) (1.12)\n", | |
| "Requirement already satisfied: sympy in /usr/local/lib/python3.7/dist-packages (from onnxruntime) (1.7.1)\n", | |
| "Requirement already satisfied: protobuf in /usr/local/lib/python3.7/dist-packages (from onnxruntime) (3.19.6)\n", | |
| "Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from onnxruntime) (21.3)\n", | |
| "Collecting humanfriendly>=9.1\n", | |
| " Downloading humanfriendly-10.0-py2.py3-none-any.whl (86 kB)\n", | |
| "\u001b[K |████████████████████████████████| 86 kB 2.6 MB/s \n", | |
| "\u001b[?25hRequirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->onnxruntime) (3.0.9)\n", | |
| "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.7/dist-packages (from sympy->onnxruntime) (1.2.1)\n", | |
| "Installing collected packages: humanfriendly, coloredlogs, onnxruntime\n", | |
| "Successfully installed coloredlogs-15.0.1 humanfriendly-10.0 onnxruntime-1.13.1\n", | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting skl2onnx\n", | |
| " Downloading skl2onnx-1.13-py2.py3-none-any.whl (288 kB)\n", | |
| "\u001b[K |████████████████████████████████| 288 kB 5.3 MB/s \n", | |
| "\u001b[?25hRequirement already satisfied: scikit-learn>=0.19 in /usr/local/lib/python3.7/dist-packages (from skl2onnx) (1.0.2)\n", | |
| "Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.7/dist-packages (from skl2onnx) (1.21.6)\n", | |
| "Collecting onnxconverter-common>=1.7.0\n", | |
| " Downloading onnxconverter_common-1.13.0-py2.py3-none-any.whl (83 kB)\n", | |
| "\u001b[K |████████████████████████████████| 83 kB 1.1 MB/s \n", | |
| "\u001b[?25hRequirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.7/dist-packages (from skl2onnx) (1.7.3)\n", | |
| "Requirement already satisfied: protobuf in /usr/local/lib/python3.7/dist-packages (from skl2onnx) (3.19.6)\n", | |
| "Collecting onnx>=1.2.1\n", | |
| " Downloading onnx-1.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB)\n", | |
| "\u001b[K |████████████████████████████████| 13.1 MB 1.5 MB/s \n", | |
| "\u001b[?25hRequirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.7/dist-packages (from onnx>=1.2.1->skl2onnx) (4.1.1)\n", | |
| "Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from onnxconverter-common>=1.7.0->skl2onnx) (21.3)\n", | |
| "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19->skl2onnx) (3.1.0)\n", | |
| "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19->skl2onnx) (1.2.0)\n", | |
| "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->onnxconverter-common>=1.7.0->skl2onnx) (3.0.9)\n", | |
| "Installing collected packages: onnx, onnxconverter-common, skl2onnx\n", | |
| "Successfully installed onnx-1.12.0 onnxconverter-common-1.13.0 skl2onnx-1.13\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!pip install onnxruntime\n", | |
| "!pip install skl2onnx" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "import pandas as pd\n", | |
| "import numpy as np\n", | |
| "import os\n", | |
| "import pickle\n", | |
| "\n", | |
| "from skl2onnx import to_onnx\n", | |
| "from skl2onnx import convert_sklearn\n", | |
| "from skl2onnx.common.data_types import FloatTensorType" | |
| ], | |
| "metadata": { | |
| "id": "AuiV6hi2Cogg" | |
| }, | |
| "execution_count": 2, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "raw_df = pd.read_csv('https://storage.googleapis.com/download.tensorflow.org/data/creditcard.csv')\n", | |
| "raw_df.head()" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 300 | |
| }, | |
| "id": "IrQRKeyj6tKL", | |
| "outputId": "01623764-6897-4509-ed91-f1bcf72af6d3" | |
| }, | |
| "execution_count": 3, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| " Time V1 V2 V3 V4 V5 V6 V7 \\\n", | |
| "0 0.0 -1.359807 -0.072781 2.536347 1.378155 -0.338321 0.462388 0.239599 \n", | |
| "1 0.0 1.191857 0.266151 0.166480 0.448154 0.060018 -0.082361 -0.078803 \n", | |
| "2 1.0 -1.358354 -1.340163 1.773209 0.379780 -0.503198 1.800499 0.791461 \n", | |
| "3 1.0 -0.966272 -0.185226 1.792993 -0.863291 -0.010309 1.247203 0.237609 \n", | |
| "4 2.0 -1.158233 0.877737 1.548718 0.403034 -0.407193 0.095921 0.592941 \n", | |
| "\n", | |
| " V8 V9 ... V21 V22 V23 V24 V25 \\\n", | |
| "0 0.098698 0.363787 ... -0.018307 0.277838 -0.110474 0.066928 0.128539 \n", | |
| "1 0.085102 -0.255425 ... -0.225775 -0.638672 0.101288 -0.339846 0.167170 \n", | |
| "2 0.247676 -1.514654 ... 0.247998 0.771679 0.909412 -0.689281 -0.327642 \n", | |
| "3 0.377436 -1.387024 ... -0.108300 0.005274 -0.190321 -1.175575 0.647376 \n", | |
| "4 -0.270533 0.817739 ... -0.009431 0.798278 -0.137458 0.141267 -0.206010 \n", | |
| "\n", | |
| " V26 V27 V28 Amount Class \n", | |
| "0 -0.189115 0.133558 -0.021053 149.62 0 \n", | |
| "1 0.125895 -0.008983 0.014724 2.69 0 \n", | |
| "2 -0.139097 -0.055353 -0.059752 378.66 0 \n", | |
| "3 -0.221929 0.062723 0.061458 123.50 0 \n", | |
| "4 0.502292 0.219422 0.215153 69.99 0 \n", | |
| "\n", | |
| "[5 rows x 31 columns]" | |
| ], | |
| "text/html": [ | |
| "\n", | |
| " <div id=\"df-3f3ef54b-7fc6-4f25-90c3-8cbcf2c37b3f\">\n", | |
| " <div class=\"colab-df-container\">\n", | |
| " <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>Time</th>\n", | |
| " <th>V1</th>\n", | |
| " <th>V2</th>\n", | |
| " <th>V3</th>\n", | |
| " <th>V4</th>\n", | |
| " <th>V5</th>\n", | |
| " <th>V6</th>\n", | |
| " <th>V7</th>\n", | |
| " <th>V8</th>\n", | |
| " <th>V9</th>\n", | |
| " <th>...</th>\n", | |
| " <th>V21</th>\n", | |
| " <th>V22</th>\n", | |
| " <th>V23</th>\n", | |
| " <th>V24</th>\n", | |
| " <th>V25</th>\n", | |
| " <th>V26</th>\n", | |
| " <th>V27</th>\n", | |
| " <th>V28</th>\n", | |
| " <th>Amount</th>\n", | |
| " <th>Class</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>0.0</td>\n", | |
| " <td>-1.359807</td>\n", | |
| " <td>-0.072781</td>\n", | |
| " <td>2.536347</td>\n", | |
| " <td>1.378155</td>\n", | |
| " <td>-0.338321</td>\n", | |
| " <td>0.462388</td>\n", | |
| " <td>0.239599</td>\n", | |
| " <td>0.098698</td>\n", | |
| " <td>0.363787</td>\n", | |
| " <td>...</td>\n", | |
| " <td>-0.018307</td>\n", | |
| " <td>0.277838</td>\n", | |
| " <td>-0.110474</td>\n", | |
| " <td>0.066928</td>\n", | |
| " <td>0.128539</td>\n", | |
| " <td>-0.189115</td>\n", | |
| " <td>0.133558</td>\n", | |
| " <td>-0.021053</td>\n", | |
| " <td>149.62</td>\n", | |
| " <td>0</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>1</th>\n", | |
| " <td>0.0</td>\n", | |
| " <td>1.191857</td>\n", | |
| " <td>0.266151</td>\n", | |
| " <td>0.166480</td>\n", | |
| " <td>0.448154</td>\n", | |
| " <td>0.060018</td>\n", | |
| " <td>-0.082361</td>\n", | |
| " <td>-0.078803</td>\n", | |
| " <td>0.085102</td>\n", | |
| " <td>-0.255425</td>\n", | |
| " <td>...</td>\n", | |
| " <td>-0.225775</td>\n", | |
| " <td>-0.638672</td>\n", | |
| " <td>0.101288</td>\n", | |
| " <td>-0.339846</td>\n", | |
| " <td>0.167170</td>\n", | |
| " <td>0.125895</td>\n", | |
| " <td>-0.008983</td>\n", | |
| " <td>0.014724</td>\n", | |
| " <td>2.69</td>\n", | |
| " <td>0</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>2</th>\n", | |
| " <td>1.0</td>\n", | |
| " <td>-1.358354</td>\n", | |
| " <td>-1.340163</td>\n", | |
| " <td>1.773209</td>\n", | |
| " <td>0.379780</td>\n", | |
| " <td>-0.503198</td>\n", | |
| " <td>1.800499</td>\n", | |
| " <td>0.791461</td>\n", | |
| " <td>0.247676</td>\n", | |
| " <td>-1.514654</td>\n", | |
| " <td>...</td>\n", | |
| " <td>0.247998</td>\n", | |
| " <td>0.771679</td>\n", | |
| " <td>0.909412</td>\n", | |
| " <td>-0.689281</td>\n", | |
| " <td>-0.327642</td>\n", | |
| " <td>-0.139097</td>\n", | |
| " <td>-0.055353</td>\n", | |
| " <td>-0.059752</td>\n", | |
| " <td>378.66</td>\n", | |
| " <td>0</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>3</th>\n", | |
| " <td>1.0</td>\n", | |
| " <td>-0.966272</td>\n", | |
| " <td>-0.185226</td>\n", | |
| " <td>1.792993</td>\n", | |
| " <td>-0.863291</td>\n", | |
| " <td>-0.010309</td>\n", | |
| " <td>1.247203</td>\n", | |
| " <td>0.237609</td>\n", | |
| " <td>0.377436</td>\n", | |
| " <td>-1.387024</td>\n", | |
| " <td>...</td>\n", | |
| " <td>-0.108300</td>\n", | |
| " <td>0.005274</td>\n", | |
| " <td>-0.190321</td>\n", | |
| " <td>-1.175575</td>\n", | |
| " <td>0.647376</td>\n", | |
| " <td>-0.221929</td>\n", | |
| " <td>0.062723</td>\n", | |
| " <td>0.061458</td>\n", | |
| " <td>123.50</td>\n", | |
| " <td>0</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>4</th>\n", | |
| " <td>2.0</td>\n", | |
| " <td>-1.158233</td>\n", | |
| " <td>0.877737</td>\n", | |
| " <td>1.548718</td>\n", | |
| " <td>0.403034</td>\n", | |
| " <td>-0.407193</td>\n", | |
| " <td>0.095921</td>\n", | |
| " <td>0.592941</td>\n", | |
| " <td>-0.270533</td>\n", | |
| " <td>0.817739</td>\n", | |
| " <td>...</td>\n", | |
| " <td>-0.009431</td>\n", | |
| " <td>0.798278</td>\n", | |
| " <td>-0.137458</td>\n", | |
| " <td>0.141267</td>\n", | |
| " <td>-0.206010</td>\n", | |
| " <td>0.502292</td>\n", | |
| " <td>0.219422</td>\n", | |
| " <td>0.215153</td>\n", | |
| " <td>69.99</td>\n", | |
| " <td>0</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<p>5 rows × 31 columns</p>\n", | |
| "</div>\n", | |
| " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-3f3ef54b-7fc6-4f25-90c3-8cbcf2c37b3f')\"\n", | |
| " title=\"Convert this dataframe to an interactive table.\"\n", | |
| " style=\"display:none;\">\n", | |
| " \n", | |
| " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n", | |
| " width=\"24px\">\n", | |
| " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n", | |
| " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n", | |
| " </svg>\n", | |
| " </button>\n", | |
| " \n", | |
| " <style>\n", | |
| " .colab-df-container {\n", | |
| " display:flex;\n", | |
| " flex-wrap:wrap;\n", | |
| " gap: 12px;\n", | |
| " }\n", | |
| "\n", | |
| " .colab-df-convert {\n", | |
| " background-color: #E8F0FE;\n", | |
| " border: none;\n", | |
| " border-radius: 50%;\n", | |
| " cursor: pointer;\n", | |
| " display: none;\n", | |
| " fill: #1967D2;\n", | |
| " height: 32px;\n", | |
| " padding: 0 0 0 0;\n", | |
| " width: 32px;\n", | |
| " }\n", | |
| "\n", | |
| " .colab-df-convert:hover {\n", | |
| " background-color: #E2EBFA;\n", | |
| " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n", | |
| " fill: #174EA6;\n", | |
| " }\n", | |
| "\n", | |
| " [theme=dark] .colab-df-convert {\n", | |
| " background-color: #3B4455;\n", | |
| " fill: #D2E3FC;\n", | |
| " }\n", | |
| "\n", | |
| " [theme=dark] .colab-df-convert:hover {\n", | |
| " background-color: #434B5C;\n", | |
| " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n", | |
| " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n", | |
| " fill: #FFFFFF;\n", | |
| " }\n", | |
| " </style>\n", | |
| "\n", | |
| " <script>\n", | |
| " const buttonEl =\n", | |
| " document.querySelector('#df-3f3ef54b-7fc6-4f25-90c3-8cbcf2c37b3f button.colab-df-convert');\n", | |
| " buttonEl.style.display =\n", | |
| " google.colab.kernel.accessAllowed ? 'block' : 'none';\n", | |
| "\n", | |
| " async function convertToInteractive(key) {\n", | |
| " const element = document.querySelector('#df-3f3ef54b-7fc6-4f25-90c3-8cbcf2c37b3f');\n", | |
| " const dataTable =\n", | |
| " await google.colab.kernel.invokeFunction('convertToInteractive',\n", | |
| " [key], {});\n", | |
| " if (!dataTable) return;\n", | |
| "\n", | |
| " const docLinkHtml = 'Like what you see? Visit the ' +\n", | |
| " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n", | |
| " + ' to learn more about interactive tables.';\n", | |
| " element.innerHTML = '';\n", | |
| " dataTable['output_type'] = 'display_data';\n", | |
| " await google.colab.output.renderOutput(dataTable, element);\n", | |
| " const docLink = document.createElement('div');\n", | |
| " docLink.innerHTML = docLinkHtml;\n", | |
| " element.appendChild(docLink);\n", | |
| " }\n", | |
| " </script>\n", | |
| " </div>\n", | |
| " </div>\n", | |
| " " | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 3 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "raw_df[\"Class_bool\"] = raw_df[\"Class\"].astype(bool)" | |
| ], | |
| "metadata": { | |
| "id": "jkErb1MG61HK" | |
| }, | |
| "execution_count": 4, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "raw_df[['Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V26', 'V27', 'V28', 'Amount', 'Class', 'Class_bool']].head()" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 206 | |
| }, | |
| "id": "YdWfdjCO64b-", | |
| "outputId": "61db20fe-838b-414b-b46e-978ddd3f7193" | |
| }, | |
| "execution_count": 5, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| " Time V1 V2 V3 V4 V5 V26 V27 \\\n", | |
| "0 0.0 -1.359807 -0.072781 2.536347 1.378155 -0.338321 -0.189115 0.133558 \n", | |
| "1 0.0 1.191857 0.266151 0.166480 0.448154 0.060018 0.125895 -0.008983 \n", | |
| "2 1.0 -1.358354 -1.340163 1.773209 0.379780 -0.503198 -0.139097 -0.055353 \n", | |
| "3 1.0 -0.966272 -0.185226 1.792993 -0.863291 -0.010309 -0.221929 0.062723 \n", | |
| "4 2.0 -1.158233 0.877737 1.548718 0.403034 -0.407193 0.502292 0.219422 \n", | |
| "\n", | |
| " V28 Amount Class Class_bool \n", | |
| "0 -0.021053 149.62 0 False \n", | |
| "1 0.014724 2.69 0 False \n", | |
| "2 -0.059752 378.66 0 False \n", | |
| "3 0.061458 123.50 0 False \n", | |
| "4 0.215153 69.99 0 False " | |
| ], | |
| "text/html": [ | |
| "\n", | |
| " <div id=\"df-1602b06e-6f5a-4289-9d12-c0c9dc09612b\">\n", | |
| " <div class=\"colab-df-container\">\n", | |
| " <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>Time</th>\n", | |
| " <th>V1</th>\n", | |
| " <th>V2</th>\n", | |
| " <th>V3</th>\n", | |
| " <th>V4</th>\n", | |
| " <th>V5</th>\n", | |
| " <th>V26</th>\n", | |
| " <th>V27</th>\n", | |
| " <th>V28</th>\n", | |
| " <th>Amount</th>\n", | |
| " <th>Class</th>\n", | |
| " <th>Class_bool</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>0.0</td>\n", | |
| " <td>-1.359807</td>\n", | |
| " <td>-0.072781</td>\n", | |
| " <td>2.536347</td>\n", | |
| " <td>1.378155</td>\n", | |
| " <td>-0.338321</td>\n", | |
| " <td>-0.189115</td>\n", | |
| " <td>0.133558</td>\n", | |
| " <td>-0.021053</td>\n", | |
| " <td>149.62</td>\n", | |
| " <td>0</td>\n", | |
| " <td>False</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>1</th>\n", | |
| " <td>0.0</td>\n", | |
| " <td>1.191857</td>\n", | |
| " <td>0.266151</td>\n", | |
| " <td>0.166480</td>\n", | |
| " <td>0.448154</td>\n", | |
| " <td>0.060018</td>\n", | |
| " <td>0.125895</td>\n", | |
| " <td>-0.008983</td>\n", | |
| " <td>0.014724</td>\n", | |
| " <td>2.69</td>\n", | |
| " <td>0</td>\n", | |
| " <td>False</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>2</th>\n", | |
| " <td>1.0</td>\n", | |
| " <td>-1.358354</td>\n", | |
| " <td>-1.340163</td>\n", | |
| " <td>1.773209</td>\n", | |
| " <td>0.379780</td>\n", | |
| " <td>-0.503198</td>\n", | |
| " <td>-0.139097</td>\n", | |
| " <td>-0.055353</td>\n", | |
| " <td>-0.059752</td>\n", | |
| " <td>378.66</td>\n", | |
| " <td>0</td>\n", | |
| " <td>False</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>3</th>\n", | |
| " <td>1.0</td>\n", | |
| " <td>-0.966272</td>\n", | |
| " <td>-0.185226</td>\n", | |
| " <td>1.792993</td>\n", | |
| " <td>-0.863291</td>\n", | |
| " <td>-0.010309</td>\n", | |
| " <td>-0.221929</td>\n", | |
| " <td>0.062723</td>\n", | |
| " <td>0.061458</td>\n", | |
| " <td>123.50</td>\n", | |
| " <td>0</td>\n", | |
| " <td>False</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>4</th>\n", | |
| " <td>2.0</td>\n", | |
| " <td>-1.158233</td>\n", | |
| " <td>0.877737</td>\n", | |
| " <td>1.548718</td>\n", | |
| " <td>0.403034</td>\n", | |
| " <td>-0.407193</td>\n", | |
| " <td>0.502292</td>\n", | |
| " <td>0.219422</td>\n", | |
| " <td>0.215153</td>\n", | |
| " <td>69.99</td>\n", | |
| " <td>0</td>\n", | |
| " <td>False</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>\n", | |
| " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-1602b06e-6f5a-4289-9d12-c0c9dc09612b')\"\n", | |
| " title=\"Convert this dataframe to an interactive table.\"\n", | |
| " style=\"display:none;\">\n", | |
| " \n", | |
| " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n", | |
| " width=\"24px\">\n", | |
| " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n", | |
| " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n", | |
| " </svg>\n", | |
| " </button>\n", | |
| " \n", | |
| " <style>\n", | |
| " .colab-df-container {\n", | |
| " display:flex;\n", | |
| " flex-wrap:wrap;\n", | |
| " gap: 12px;\n", | |
| " }\n", | |
| "\n", | |
| " .colab-df-convert {\n", | |
| " background-color: #E8F0FE;\n", | |
| " border: none;\n", | |
| " border-radius: 50%;\n", | |
| " cursor: pointer;\n", | |
| " display: none;\n", | |
| " fill: #1967D2;\n", | |
| " height: 32px;\n", | |
| " padding: 0 0 0 0;\n", | |
| " width: 32px;\n", | |
| " }\n", | |
| "\n", | |
| " .colab-df-convert:hover {\n", | |
| " background-color: #E2EBFA;\n", | |
| " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n", | |
| " fill: #174EA6;\n", | |
| " }\n", | |
| "\n", | |
| " [theme=dark] .colab-df-convert {\n", | |
| " background-color: #3B4455;\n", | |
| " fill: #D2E3FC;\n", | |
| " }\n", | |
| "\n", | |
| " [theme=dark] .colab-df-convert:hover {\n", | |
| " background-color: #434B5C;\n", | |
| " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n", | |
| " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n", | |
| " fill: #FFFFFF;\n", | |
| " }\n", | |
| " </style>\n", | |
| "\n", | |
| " <script>\n", | |
| " const buttonEl =\n", | |
| " document.querySelector('#df-1602b06e-6f5a-4289-9d12-c0c9dc09612b button.colab-df-convert');\n", | |
| " buttonEl.style.display =\n", | |
| " google.colab.kernel.accessAllowed ? 'block' : 'none';\n", | |
| "\n", | |
| " async function convertToInteractive(key) {\n", | |
| " const element = document.querySelector('#df-1602b06e-6f5a-4289-9d12-c0c9dc09612b');\n", | |
| " const dataTable =\n", | |
| " await google.colab.kernel.invokeFunction('convertToInteractive',\n", | |
| " [key], {});\n", | |
| " if (!dataTable) return;\n", | |
| "\n", | |
| " const docLinkHtml = 'Like what you see? Visit the ' +\n", | |
| " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n", | |
| " + ' to learn more about interactive tables.';\n", | |
| " element.innerHTML = '';\n", | |
| " dataTable['output_type'] = 'display_data';\n", | |
| " await google.colab.output.renderOutput(dataTable, element);\n", | |
| " const docLink = document.createElement('div');\n", | |
| " docLink.innerHTML = docLinkHtml;\n", | |
| " element.appendChild(docLink);\n", | |
| " }\n", | |
| " </script>\n", | |
| " </div>\n", | |
| " </div>\n", | |
| " " | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 5 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from sklearn.ensemble import RandomForestClassifier\n", | |
| "\n", | |
| "classifier = RandomForestClassifier(\n", | |
| " n_estimators = 5,\n", | |
| " random_state = 42,\n", | |
| " n_jobs = -1\n", | |
| ")" | |
| ], | |
| "metadata": { | |
| "id": "42igMctG7G_O" | |
| }, | |
| "execution_count": 6, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "features = ['Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V26', 'V27', 'V28', 'Amount']" | |
| ], | |
| "metadata": { | |
| "id": "VcPZ3BmN7kOm" | |
| }, | |
| "execution_count": 7, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "x = raw_df[features]\n", | |
| "y = raw_df['Class_bool']\n", | |
| "classifier.fit(x, y)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "s_x8nQ-S7TQ9", | |
| "outputId": "5df57b0c-fdfa-40b4-b144-7e87f12ce4ce" | |
| }, | |
| "execution_count": 8, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "RandomForestClassifier(n_estimators=5, n_jobs=-1, random_state=42)" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 8 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "x1 = x[:1]\n", | |
| "x1" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 81 | |
| }, | |
| "id": "JyZL0x9M8OrI", | |
| "outputId": "329bf5f8-5a41-423c-cfaf-81a2ff21cd0d" | |
| }, | |
| "execution_count": 9, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| " Time V1 V2 V3 V4 V5 V26 V27 \\\n", | |
| "0 0.0 -1.359807 -0.072781 2.536347 1.378155 -0.338321 -0.189115 0.133558 \n", | |
| "\n", | |
| " V28 Amount \n", | |
| "0 -0.021053 149.62 " | |
| ], | |
| "text/html": [ | |
| "\n", | |
| " <div id=\"df-0a23a998-486a-4545-b538-4da30c0e2ae7\">\n", | |
| " <div class=\"colab-df-container\">\n", | |
| " <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>Time</th>\n", | |
| " <th>V1</th>\n", | |
| " <th>V2</th>\n", | |
| " <th>V3</th>\n", | |
| " <th>V4</th>\n", | |
| " <th>V5</th>\n", | |
| " <th>V26</th>\n", | |
| " <th>V27</th>\n", | |
| " <th>V28</th>\n", | |
| " <th>Amount</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>0.0</td>\n", | |
| " <td>-1.359807</td>\n", | |
| " <td>-0.072781</td>\n", | |
| " <td>2.536347</td>\n", | |
| " <td>1.378155</td>\n", | |
| " <td>-0.338321</td>\n", | |
| " <td>-0.189115</td>\n", | |
| " <td>0.133558</td>\n", | |
| " <td>-0.021053</td>\n", | |
| " <td>149.62</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>\n", | |
| " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-0a23a998-486a-4545-b538-4da30c0e2ae7')\"\n", | |
| " title=\"Convert this dataframe to an interactive table.\"\n", | |
| " style=\"display:none;\">\n", | |
| " \n", | |
| " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n", | |
| " width=\"24px\">\n", | |
| " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n", | |
| " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n", | |
| " </svg>\n", | |
| " </button>\n", | |
| " \n", | |
| " <style>\n", | |
| " .colab-df-container {\n", | |
| " display:flex;\n", | |
| " flex-wrap:wrap;\n", | |
| " gap: 12px;\n", | |
| " }\n", | |
| "\n", | |
| " .colab-df-convert {\n", | |
| " background-color: #E8F0FE;\n", | |
| " border: none;\n", | |
| " border-radius: 50%;\n", | |
| " cursor: pointer;\n", | |
| " display: none;\n", | |
| " fill: #1967D2;\n", | |
| " height: 32px;\n", | |
| " padding: 0 0 0 0;\n", | |
| " width: 32px;\n", | |
| " }\n", | |
| "\n", | |
| " .colab-df-convert:hover {\n", | |
| " background-color: #E2EBFA;\n", | |
| " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n", | |
| " fill: #174EA6;\n", | |
| " }\n", | |
| "\n", | |
| " [theme=dark] .colab-df-convert {\n", | |
| " background-color: #3B4455;\n", | |
| " fill: #D2E3FC;\n", | |
| " }\n", | |
| "\n", | |
| " [theme=dark] .colab-df-convert:hover {\n", | |
| " background-color: #434B5C;\n", | |
| " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n", | |
| " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n", | |
| " fill: #FFFFFF;\n", | |
| " }\n", | |
| " </style>\n", | |
| "\n", | |
| " <script>\n", | |
| " const buttonEl =\n", | |
| " document.querySelector('#df-0a23a998-486a-4545-b538-4da30c0e2ae7 button.colab-df-convert');\n", | |
| " buttonEl.style.display =\n", | |
| " google.colab.kernel.accessAllowed ? 'block' : 'none';\n", | |
| "\n", | |
| " async function convertToInteractive(key) {\n", | |
| " const element = document.querySelector('#df-0a23a998-486a-4545-b538-4da30c0e2ae7');\n", | |
| " const dataTable =\n", | |
| " await google.colab.kernel.invokeFunction('convertToInteractive',\n", | |
| " [key], {});\n", | |
| " if (!dataTable) return;\n", | |
| "\n", | |
| " const docLinkHtml = 'Like what you see? Visit the ' +\n", | |
| " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n", | |
| " + ' to learn more about interactive tables.';\n", | |
| " element.innerHTML = '';\n", | |
| " dataTable['output_type'] = 'display_data';\n", | |
| " await google.colab.output.renderOutput(dataTable, element);\n", | |
| " const docLink = document.createElement('div');\n", | |
| " docLink.innerHTML = docLinkHtml;\n", | |
| " element.appendChild(docLink);\n", | |
| " }\n", | |
| " </script>\n", | |
| " </div>\n", | |
| " </div>\n", | |
| " " | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 9 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "onx = to_onnx(classifier, x1.to_numpy().astype(np.float32), target_opset=12)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 316 | |
| }, | |
| "id": "1gh5flMH_M5u", | |
| "outputId": "4a27649d-3d88-420d-edd3-c7911b033e61" | |
| }, | |
| "execution_count": 10, | |
| "outputs": [ | |
| { | |
| "output_type": "error", | |
| "ename": "AttributeError", | |
| "evalue": "ignored", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", | |
| "\u001b[0;32m<ipython-input-10-70444daf22cb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0monx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mto_onnx\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mclassifier\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtarget_opset\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m12\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/convert.py\u001b[0m in \u001b[0;36mto_onnx\u001b[0;34m(model, X, name, initial_types, target_opset, options, white_op, black_op, final_types, dtype, naming, verbose)\u001b[0m\n\u001b[1;32m 266\u001b[0m \u001b[0mwhite_op\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mwhite_op\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mblack_op\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mblack_op\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 267\u001b[0m \u001b[0mfinal_types\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfinal_types\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 268\u001b[0;31m verbose=verbose, naming=naming)\n\u001b[0m\u001b[1;32m 269\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/convert.py\u001b[0m in \u001b[0;36mconvert_sklearn\u001b[0;34m(model, name, initial_types, doc_string, target_opset, custom_conversion_functions, custom_shape_calculators, custom_parsers, options, intermediate, white_op, black_op, final_types, dtype, naming, verbose)\u001b[0m\n\u001b[1;32m 176\u001b[0m \u001b[0mcustom_shape_calculators\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcustom_parsers\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 177\u001b[0m \u001b[0mwhite_op\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mwhite_op\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mblack_op\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mblack_op\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 178\u001b[0;31m final_types=final_types, naming=naming)\n\u001b[0m\u001b[1;32m 179\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 180\u001b[0m \u001b[0;31m# Convert our Topology object into ONNX. The outcome is an ONNX model.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/_parse.py\u001b[0m in \u001b[0;36mparse_sklearn_model\u001b[0;34m(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators, custom_parsers, options, white_op, black_op, final_types, naming)\u001b[0m\n\u001b[1;32m 787\u001b[0m outputs = parse_sklearn(scope, model, inputs,\n\u001b[1;32m 788\u001b[0m \u001b[0mcustom_parsers\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcustom_parsers\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 789\u001b[0;31m final_types=final_types)\n\u001b[0m\u001b[1;32m 790\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 791\u001b[0m \u001b[0;31m# The object raw_model_container is a part of the topology we're\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/_parse.py\u001b[0m in \u001b[0;36mparse_sklearn\u001b[0;34m(scope, model, inputs, custom_parsers, final_types)\u001b[0m\n\u001b[1;32m 706\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 707\u001b[0m res = _parse_sklearn(\n\u001b[0;32m--> 708\u001b[0;31m scope, model, inputs, custom_parsers=custom_parsers)\n\u001b[0m\u001b[1;32m 709\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mr\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mres\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 710\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minit_status\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mis_leaf\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/_parse.py\u001b[0m in \u001b[0;36m_parse_sklearn\u001b[0;34m(scope, model, inputs, custom_parsers, alias)\u001b[0m\n\u001b[1;32m 643\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mtmodel\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msklearn_parsers_map\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 644\u001b[0m outputs = sklearn_parsers_map[tmodel](scope, model, inputs,\n\u001b[0;32m--> 645\u001b[0;31m custom_parsers=custom_parsers)\n\u001b[0m\u001b[1;32m 646\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpipeline\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPipeline\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 647\u001b[0m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msklearn_parsers_map\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mpipeline\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPipeline\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/_parse.py\u001b[0m in \u001b[0;36m_parse_sklearn_classifier\u001b[0;34m(scope, model, inputs, custom_parsers)\u001b[0m\n\u001b[1;32m 519\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 520\u001b[0m return _apply_zipmap(\n\u001b[0;32m--> 521\u001b[0;31m options['zipmap'], scope, model, inputs[0].type, probability_tensor)\n\u001b[0m\u001b[1;32m 522\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 523\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/_parse.py\u001b[0m in \u001b[0;36m_apply_zipmap\u001b[0;34m(zipmap_options, scope, model, input_type, probability_tensor)\u001b[0m\n\u001b[1;32m 457\u001b[0m \u001b[0mzipmap_operator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclasslabels_int64s\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 458\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 459\u001b[0;31m \u001b[0mclasses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'utf-8'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 460\u001b[0m \u001b[0mzipmap_operator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclasslabels_strings\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 461\u001b[0m \u001b[0mlabel_type\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mStringTensorType\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/skl2onnx/_parse.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 457\u001b[0m \u001b[0mzipmap_operator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclasslabels_int64s\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 458\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 459\u001b[0;31m \u001b[0mclasses\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'utf-8'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 460\u001b[0m \u001b[0mzipmap_operator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclasslabels_strings\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 461\u001b[0m \u001b[0mlabel_type\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mStringTensorType\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| "\u001b[0;31mAttributeError\u001b[0m: 'numpy.bool_' object has no attribute 'encode'" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "# apply a workaround described at https://github.com/onnx/sklearn-onnx/issues/813\n", | |
| "classifier.classes_ = classifier.classes_.astype(np.int32)\n", | |
| "onx = to_onnx(classifier, x1.to_numpy().astype(np.float32), target_opset=12)" | |
| ], | |
| "metadata": { | |
| "id": "AcHnl9mDkGdK" | |
| }, | |
| "execution_count": 11, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [], | |
| "metadata": { | |
| "id": "J-9xRWtvIG5v" | |
| }, | |
| "execution_count": null, | |
| "outputs": [] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment