diff --git a/4-Classification/4-Applied/solution/index.html b/4-Classification/4-Applied/solution/index.html
index 56992014e8..99d200246d 100644
--- a/4-Classification/4-Applied/solution/index.html
+++ b/4-Classification/4-Applied/solution/index.html
@@ -1,28 +1,36 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+ ONNX Runtime JavaScript examples: Quick Start - Web (using script tag)
+
+
+
+
+
+
+
+
diff --git a/4-Classification/4-Applied/solution/model.onnx b/4-Classification/4-Applied/solution/model.onnx
new file mode 100644
index 0000000000..591e0c2ba8
Binary files /dev/null and b/4-Classification/4-Applied/solution/model.onnx differ
diff --git a/4-Classification/4-Applied/solution/notebook.ipynb b/4-Classification/4-Applied/solution/notebook.ipynb
index 3eaba762d2..b619dfbfc1 100644
--- a/4-Classification/4-Applied/solution/notebook.ipynb
+++ b/4-Classification/4-Applied/solution/notebook.ipynb
@@ -10,47 +10,296 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": 3
+ "version": "3.7.0"
},
- "orig_nbformat": 2
+ "orig_nbformat": 2,
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3.7.0 64-bit ('3.7')"
+ },
+ "metadata": {
+ "interpreter": {
+ "hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
+ }
+ },
+ "interpreter": {
+ "hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
+ }
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Requirement already satisfied: skl2onnx in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.8.0)\n",
+ "Requirement already satisfied: numpy>=1.15 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.19.2)\n",
+ "Requirement already satisfied: onnxconverter-common<1.9,>=1.6.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.8.1)\n",
+ "Requirement already satisfied: protobuf in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (3.8.0)\n",
+ "Requirement already satisfied: scikit-learn>=0.19 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (0.24.2)\n",
+ "Requirement already satisfied: scipy>=1.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.4.1)\n",
+ "Requirement already satisfied: six in /Users/jenlooper/Library/Python/3.7/lib/python/site-packages (from skl2onnx) (1.12.0)\n",
+ "Requirement already satisfied: onnx>=1.2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.9.0)\n",
+ "Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from protobuf->skl2onnx) (45.1.0)\n",
+ "Requirement already satisfied: joblib>=0.11 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from scikit-learn>=0.19->skl2onnx) (0.16.0)\n",
+ "Requirement already satisfied: threadpoolctl>=2.0.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from scikit-learn>=0.19->skl2onnx) (2.1.0)\n",
+ "Requirement already satisfied: typing-extensions>=3.6.2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnx>=1.2.1->skl2onnx) (3.10.0.0)\n",
+ "\u001b[33mWARNING: You are using pip version 20.2.3; however, version 21.1.2 is available.\n",
+ "You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
+ "Note: you may need to restart the kernel to use updated packages.\n"
+ ]
+ }
+ ],
"source": [
- "## Build a web app"
+ "pip install skl2onnx"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Requirement already satisfied: onnxruntime in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.8.0)\n",
+ "Requirement already satisfied: flatbuffers in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnxruntime) (2.0)\n",
+ "Requirement already satisfied: protobuf in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnxruntime) (3.8.0)\n",
+ "Requirement already satisfied: numpy>=1.16.6 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnxruntime) (1.19.2)\n",
+ "Requirement already satisfied: six>=1.9 in /Users/jenlooper/Library/Python/3.7/lib/python/site-packages (from protobuf->onnxruntime) (1.12.0)\n",
+ "Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from protobuf->onnxruntime) (45.1.0)\n",
+ "\u001b[33mWARNING: You are using pip version 20.2.3; however, version 21.1.2 is available.\n",
+ "You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
+ "Note: you may need to restart the kernel to use updated packages.\n"
+ ]
+ }
],
- "cell_type": "markdown",
- "metadata": {}
+ "source": [
+ "pip install onnxruntime"
+ ]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
- "pip install skl2onnx"
+ "import numpy as np \n",
+ "import pandas as pd \n"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 28,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Unnamed: 0 cuisine almond angelica anise anise_seed apple \\\n",
+ "0 0 indian 0 0 0 0 0 \n",
+ "1 1 indian 1 0 0 0 0 \n",
+ "2 2 indian 0 0 0 0 0 \n",
+ "3 3 indian 0 0 0 0 0 \n",
+ "4 4 indian 0 0 0 0 0 \n",
+ "\n",
+ " apple_brandy apricot armagnac ... whiskey white_bread white_wine \\\n",
+ "0 0 0 0 ... 0 0 0 \n",
+ "1 0 0 0 ... 0 0 0 \n",
+ "2 0 0 0 ... 0 0 0 \n",
+ "3 0 0 0 ... 0 0 0 \n",
+ "4 0 0 0 ... 0 0 0 \n",
+ "\n",
+ " whole_grain_wheat_flour wine wood yam yeast yogurt zucchini \n",
+ "0 0 0 0 0 0 0 0 \n",
+ "1 0 0 0 0 0 0 0 \n",
+ "2 0 0 0 0 0 0 0 \n",
+ "3 0 0 0 0 0 0 0 \n",
+ "4 0 0 0 0 0 1 0 \n",
+ "\n",
+ "[5 rows x 382 columns]"
+ ],
+ "text/html": "\n\n
\n \n \n | \n Unnamed: 0 | \n cuisine | \n almond | \n angelica | \n anise | \n anise_seed | \n apple | \n apple_brandy | \n apricot | \n armagnac | \n ... | \n whiskey | \n white_bread | \n white_wine | \n whole_grain_wheat_flour | \n wine | \n wood | \n yam | \n yeast | \n yogurt | \n zucchini | \n
\n \n \n \n 0 | \n 0 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 1 | \n 1 | \n indian | \n 1 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 2 | \n 2 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 3 | \n 3 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 4 | \n 4 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 1 | \n 0 | \n
\n \n
\n
5 rows × 382 columns
\n
"
+ },
+ "metadata": {},
+ "execution_count": 28
+ }
+ ],
+ "source": [
+ "data = pd.read_csv('../../data/cleaned_cuisine.csv')\n",
+ "data.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " almond angelica anise anise_seed apple apple_brandy apricot \\\n",
+ "0 0 0 0 0 0 0 0 \n",
+ "1 1 0 0 0 0 0 0 \n",
+ "2 0 0 0 0 0 0 0 \n",
+ "3 0 0 0 0 0 0 0 \n",
+ "4 0 0 0 0 0 0 0 \n",
+ "\n",
+ " armagnac artemisia artichoke ... whiskey white_bread white_wine \\\n",
+ "0 0 0 0 ... 0 0 0 \n",
+ "1 0 0 0 ... 0 0 0 \n",
+ "2 0 0 0 ... 0 0 0 \n",
+ "3 0 0 0 ... 0 0 0 \n",
+ "4 0 0 0 ... 0 0 0 \n",
+ "\n",
+ " whole_grain_wheat_flour wine wood yam yeast yogurt zucchini \n",
+ "0 0 0 0 0 0 0 0 \n",
+ "1 0 0 0 0 0 0 0 \n",
+ "2 0 0 0 0 0 0 0 \n",
+ "3 0 0 0 0 0 0 0 \n",
+ "4 0 0 0 0 0 1 0 \n",
+ "\n",
+ "[5 rows x 380 columns]"
+ ],
+ "text/html": "\n\n
\n \n \n | \n almond | \n angelica | \n anise | \n anise_seed | \n apple | \n apple_brandy | \n apricot | \n armagnac | \n artemisia | \n artichoke | \n ... | \n whiskey | \n white_bread | \n white_wine | \n whole_grain_wheat_flour | \n wine | \n wood | \n yam | \n yeast | \n yogurt | \n zucchini | \n
\n \n \n \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 1 | \n 1 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 2 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 3 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 4 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 1 | \n 0 | \n
\n \n
\n
5 rows × 380 columns
\n
"
+ },
+ "metadata": {},
+ "execution_count": 29
+ }
+ ],
+ "source": [
+ "X = data.iloc[:,2:]\n",
+ "X.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " cuisine\n",
+ "0 indian\n",
+ "1 indian\n",
+ "2 indian\n",
+ "3 indian\n",
+ "4 indian"
+ ],
+ "text/html": "\n\n
\n \n \n | \n cuisine | \n
\n \n \n \n 0 | \n indian | \n
\n \n 1 | \n indian | \n
\n \n 2 | \n indian | \n
\n \n 3 | \n indian | \n
\n \n 4 | \n indian | \n
\n \n
\n
"
+ },
+ "metadata": {},
+ "execution_count": 30
+ }
+ ],
+ "source": [
+ "y = data[['cuisine']]\n",
+ "y.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
- "pip install onnxruntime"
+ "from sklearn.model_selection import train_test_split\n",
+ "from sklearn.svm import SVC\n",
+ "from sklearn.model_selection import cross_val_score\n",
+ "from sklearn.metrics import accuracy_score,precision_score,confusion_matrix,classification_report"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
- "import numpy as np \n",
- "import pandas as pd "
+ "X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "SVC(C=10, kernel='linear', probability=True, random_state=0)"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 33
+ }
+ ],
+ "source": [
+ "model = SVC(kernel='linear', C=10, probability=True,random_state=0)\n",
+ "model.fit(X_train,y_train.values.ravel())\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "y_pred = model.predict(X_test)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ " precision recall f1-score support\n\n chinese 0.67 0.68 0.67 243\n indian 0.90 0.87 0.89 238\n japanese 0.75 0.73 0.74 251\n korean 0.84 0.74 0.79 242\n thai 0.74 0.86 0.80 225\n\n accuracy 0.77 1199\n macro avg 0.78 0.78 0.78 1199\nweighted avg 0.78 0.77 0.78 1199\n\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(classification_report(y_test,y_pred))"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from skl2onnx import convert_sklearn\n",
+ "from skl2onnx.common.data_types import FloatTensorType\n",
+ "\n",
+ "initial_type = [('float_input', FloatTensorType([None, 10]))]\n",
+ "options = {id(model): {'nocl': True, 'zipmap': False}}\n",
+ "onx = convert_sklearn(model, initial_types=initial_type,options=options)\n",
+ "with open(\"./model2.onnx\", \"wb\") as f:\n",
+ " f.write(onx.SerializeToString())\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
]
}
\ No newline at end of file
diff --git a/4-Classification/4-Applied/solution/recipe-detector.ipynb b/4-Classification/4-Applied/solution/recipe-detector.ipynb
deleted file mode 100644
index 6d466b60e3..0000000000
--- a/4-Classification/4-Applied/solution/recipe-detector.ipynb
+++ /dev/null
@@ -1,305 +0,0 @@
-{
- "metadata": {
- "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.0"
- },
- "orig_nbformat": 2,
- "kernelspec": {
- "name": "python3",
- "display_name": "Python 3.7.0 64-bit ('3.7')"
- },
- "metadata": {
- "interpreter": {
- "hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
- }
- },
- "interpreter": {
- "hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2,
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Requirement already satisfied: skl2onnx in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.8.0)\n",
- "Requirement already satisfied: scikit-learn>=0.19 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (0.24.2)\n",
- "Requirement already satisfied: scipy>=1.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.4.1)\n",
- "Requirement already satisfied: six in /Users/jenlooper/Library/Python/3.7/lib/python/site-packages (from skl2onnx) (1.12.0)\n",
- "Requirement already satisfied: onnx>=1.2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.9.0)\n",
- "Requirement already satisfied: onnxconverter-common<1.9,>=1.6.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.8.1)\n",
- "Requirement already satisfied: protobuf in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (3.8.0)\n",
- "Requirement already satisfied: numpy>=1.15 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from skl2onnx) (1.19.2)\n",
- "Requirement already satisfied: joblib>=0.11 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from scikit-learn>=0.19->skl2onnx) (0.16.0)\n",
- "Requirement already satisfied: threadpoolctl>=2.0.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from scikit-learn>=0.19->skl2onnx) (2.1.0)\n",
- "Requirement already satisfied: typing-extensions>=3.6.2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnx>=1.2.1->skl2onnx) (3.10.0.0)\n",
- "Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from protobuf->skl2onnx) (45.1.0)\n",
- "\u001b[33mWARNING: You are using pip version 20.2.3; however, version 21.1.2 is available.\n",
- "You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
- "Note: you may need to restart the kernel to use updated packages.\n"
- ]
- }
- ],
- "source": [
- "pip install skl2onnx"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Requirement already satisfied: onnxruntime in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.8.0)\n",
- "Requirement already satisfied: protobuf in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnxruntime) (3.8.0)\n",
- "Requirement already satisfied: flatbuffers in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnxruntime) (2.0)\n",
- "Requirement already satisfied: numpy>=1.16.6 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from onnxruntime) (1.19.2)\n",
- "Requirement already satisfied: six>=1.9 in /Users/jenlooper/Library/Python/3.7/lib/python/site-packages (from protobuf->onnxruntime) (1.12.0)\n",
- "Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from protobuf->onnxruntime) (45.1.0)\n",
- "\u001b[33mWARNING: You are using pip version 20.2.3; however, version 21.1.2 is available.\n",
- "You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
- "Note: you may need to restart the kernel to use updated packages.\n"
- ]
- }
- ],
- "source": [
- "pip install onnxruntime"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np \n",
- "import pandas as pd \n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " Unnamed: 0 cuisine almond angelica anise anise_seed apple \\\n",
- "0 0 indian 0 0 0 0 0 \n",
- "1 1 indian 1 0 0 0 0 \n",
- "2 2 indian 0 0 0 0 0 \n",
- "3 3 indian 0 0 0 0 0 \n",
- "4 4 indian 0 0 0 0 0 \n",
- "\n",
- " apple_brandy apricot armagnac ... whiskey white_bread white_wine \\\n",
- "0 0 0 0 ... 0 0 0 \n",
- "1 0 0 0 ... 0 0 0 \n",
- "2 0 0 0 ... 0 0 0 \n",
- "3 0 0 0 ... 0 0 0 \n",
- "4 0 0 0 ... 0 0 0 \n",
- "\n",
- " whole_grain_wheat_flour wine wood yam yeast yogurt zucchini \n",
- "0 0 0 0 0 0 0 0 \n",
- "1 0 0 0 0 0 0 0 \n",
- "2 0 0 0 0 0 0 0 \n",
- "3 0 0 0 0 0 0 0 \n",
- "4 0 0 0 0 0 1 0 \n",
- "\n",
- "[5 rows x 382 columns]"
- ],
- "text/html": "\n\n
\n \n \n | \n Unnamed: 0 | \n cuisine | \n almond | \n angelica | \n anise | \n anise_seed | \n apple | \n apple_brandy | \n apricot | \n armagnac | \n ... | \n whiskey | \n white_bread | \n white_wine | \n whole_grain_wheat_flour | \n wine | \n wood | \n yam | \n yeast | \n yogurt | \n zucchini | \n
\n \n \n \n 0 | \n 0 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 1 | \n 1 | \n indian | \n 1 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 2 | \n 2 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 3 | \n 3 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 4 | \n 4 | \n indian | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 1 | \n 0 | \n
\n \n
\n
5 rows × 382 columns
\n
"
- },
- "metadata": {},
- "execution_count": 4
- }
- ],
- "source": [
- "data = pd.read_csv('../../data/cleaned_cuisine.csv')\n",
- "data.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " almond angelica anise anise_seed apple apple_brandy apricot \\\n",
- "0 0 0 0 0 0 0 0 \n",
- "1 1 0 0 0 0 0 0 \n",
- "2 0 0 0 0 0 0 0 \n",
- "3 0 0 0 0 0 0 0 \n",
- "4 0 0 0 0 0 0 0 \n",
- "\n",
- " armagnac artemisia artichoke ... whiskey white_bread white_wine \\\n",
- "0 0 0 0 ... 0 0 0 \n",
- "1 0 0 0 ... 0 0 0 \n",
- "2 0 0 0 ... 0 0 0 \n",
- "3 0 0 0 ... 0 0 0 \n",
- "4 0 0 0 ... 0 0 0 \n",
- "\n",
- " whole_grain_wheat_flour wine wood yam yeast yogurt zucchini \n",
- "0 0 0 0 0 0 0 0 \n",
- "1 0 0 0 0 0 0 0 \n",
- "2 0 0 0 0 0 0 0 \n",
- "3 0 0 0 0 0 0 0 \n",
- "4 0 0 0 0 0 1 0 \n",
- "\n",
- "[5 rows x 380 columns]"
- ],
- "text/html": "\n\n
\n \n \n | \n almond | \n angelica | \n anise | \n anise_seed | \n apple | \n apple_brandy | \n apricot | \n armagnac | \n artemisia | \n artichoke | \n ... | \n whiskey | \n white_bread | \n white_wine | \n whole_grain_wheat_flour | \n wine | \n wood | \n yam | \n yeast | \n yogurt | \n zucchini | \n
\n \n \n \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 1 | \n 1 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 2 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 3 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n
\n \n 4 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n ... | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 0 | \n 1 | \n 0 | \n
\n \n
\n
5 rows × 380 columns
\n
"
- },
- "metadata": {},
- "execution_count": 5
- }
- ],
- "source": [
- "X = data.iloc[:,2:]\n",
- "X.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " cuisine\n",
- "0 indian\n",
- "1 indian\n",
- "2 indian\n",
- "3 indian\n",
- "4 indian"
- ],
- "text/html": "\n\n
\n \n \n | \n cuisine | \n
\n \n \n \n 0 | \n indian | \n
\n \n 1 | \n indian | \n
\n \n 2 | \n indian | \n
\n \n 3 | \n indian | \n
\n \n 4 | \n indian | \n
\n \n
\n
"
- },
- "metadata": {},
- "execution_count": 6
- }
- ],
- "source": [
- "y = data[['cuisine']]\n",
- "y.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [],
- "source": [
- "from sklearn.model_selection import train_test_split\n",
- "from sklearn.svm import SVC\n",
- "from sklearn.model_selection import cross_val_score\n",
- "from sklearn.metrics import accuracy_score,precision_score,confusion_matrix,classification_report"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "SVC(C=10, kernel='linear', probability=True, random_state=0)"
- ]
- },
- "metadata": {},
- "execution_count": 9
- }
- ],
- "source": [
- "model = SVC(kernel='linear', C=10, probability=True,random_state=0)\n",
- "model.fit(X_train,y_train.values.ravel())\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [],
- "source": [
- "y_pred = model.predict(X_test)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- " precision recall f1-score support\n\n chinese 0.68 0.69 0.68 249\n indian 0.92 0.88 0.90 238\n japanese 0.77 0.68 0.72 236\n korean 0.84 0.79 0.82 247\n thai 0.73 0.88 0.80 229\n\n accuracy 0.78 1199\n macro avg 0.79 0.79 0.78 1199\nweighted avg 0.79 0.78 0.78 1199\n\n"
- ]
- }
- ],
- "source": [
- "print(classification_report(y_test,y_pred))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [],
- "source": [
- "from skl2onnx import convert_sklearn\n",
- "from skl2onnx.common.data_types import FloatTensorType\n",
- "\n",
- "initial_type = [('float_input', FloatTensorType([None, 4]))]\n",
- "options = {id(model): {'nocl': True, 'zipmap': False}}\n",
- "onx = convert_sklearn(model, initial_types=initial_type,options=options)\n",
- "with open(\"./model.onnx\", \"wb\") as f:\n",
- " f.write(onx.SerializeToString())\n",
- "\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ]
-}
\ No newline at end of file