This commit is contained in:
shoney.arickathil 2023-06-20 00:10:45 +02:00
parent 3f5fb77cc2
commit 7f1bafdf5c
5 changed files with 367 additions and 456 deletions

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -21,17 +21,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"dbpedia_df = pd.read_csv('./datasets/dbpedia_csv/train.csv', \n", "dbpedia_df = pd.read_csv('../building-features-from-text-data/datasets/dbpedia_csv/train.csv', \n",
" skiprows=1, names = ['Label', 'Name', 'Text'])" " skiprows=1, names = ['Label', 'Name', 'Text'])"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -40,16 +40,18 @@
"(559999, 3)" "(559999, 3)"
] ]
}, },
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"dbpedia_df.shape" "dbpedia_df.shape\n",
"\n"
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
@ -73,7 +75,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -82,7 +84,7 @@
"array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])" "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])"
] ]
}, },
"execution_count": 5, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -93,7 +95,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -102,7 +104,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -133,64 +135,64 @@
" </thead>\n", " </thead>\n",
" <tbody>\n", " <tbody>\n",
" <tr>\n", " <tr>\n",
" <th>500996</th>\n", " <th>380616</th>\n",
" <td>10</td>\n",
" <td>Stilifer akahitode</td>\n",
" <td>Stilifer akahitode is a species of sea snail ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>500198</th>\n",
" <td>13</td>\n", " <td>13</td>\n",
" <td>The County Chairman</td>\n", " <td>Ip Man 2</td>\n",
" <td>The County Chairman is a 1935 comedy film dir...</td>\n", " <td>Ip Man 2 is a 2010 Hong Kong biographical mar...</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>40795</th>\n", " <th>88377</th>\n",
" <td>2</td>\n", " <td>3</td>\n",
" <td>Our Lady of Mount Carmel High School (Baltimor...</td>\n", " <td>Achuta Manasa</td>\n",
" <td>Our Lady of Mount Carmel High School (OLMC HS...</td>\n", " <td>Achuta Manasa is an Indian kuchipudi dancer.</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>131453</th>\n", " <th>377145</th>\n",
" <td>4</td>\n", " <td>10</td>\n",
" <td>Jim Kleinsasser</td>\n", " <td>Bombyx incomposita</td>\n",
" <td>Jimmy Carter Kleinsasser (/ˈklaɪnsɑːsər/; bor...</td>\n", " <td>Bombyx incomposita is a moth in the Bombycida...</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>122291</th>\n", " <th>29060</th>\n",
" <td>4</td>\n",
" <td>August Klingler</td>\n",
" <td>August Klingler (24 February 1918 – 23 Novemb...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38965</th>\n",
" <td>1</td>\n", " <td>1</td>\n",
" <td>Fine Fare</td>\n", " <td>W. W. Greener</td>\n",
" <td>Fine Fare was the name of a chain of supermar...</td>\n", " <td>W.W. Greener is a sporting shotgun and rifle ...</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>89852</th>\n", " <th>198749</th>\n",
" <td>3</td>\n", " <td>5</td>\n",
" <td>Desmond Devlin</td>\n", " <td>Robert E. Holmes</td>\n",
" <td>Desmond Devlin is an American comedy writer. ...</td>\n", " <td>Robert Edward Holmes (November 14 1922 – July...</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>481930</th>\n", " <th>488653</th>\n",
" <td>13</td>\n", " <td>13</td>\n",
" <td>A Sister to Assist 'Er (1938 film)</td>\n", " <td>My Giant</td>\n",
" <td>A Sister to Assist 'Er is a 1938 British come...</td>\n", " <td>My Giant is a 1998 comedy drama film starring...</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>95008</th>\n", " <th>320765</th>\n",
" <td>3</td>\n",
" <td>Megumi Makihara</td>\n",
" <td>Megumi Makihara (槇原めぐみ or 槙原めぐみ or 慎原めぐみ Maki...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>543571</th>\n",
" <td>14</td>\n",
" <td>Annals of Science</td>\n",
" <td>Annals of Science is a peer-reviewed academic...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>356791</th>\n",
" <td>9</td>\n", " <td>9</td>\n",
" <td>Dula Gavabar</td>\n", " <td>Lockland Ohio</td>\n",
" <td>Dula Gavabar (Persian: دولاگوابر‎ also Romani...</td>\n", " <td>Lockland is a village in Hamilton County Ohio...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7583</th>\n",
" <td>1</td>\n",
" <td>Fresh to Order</td>\n",
" <td>Fresh to Order (f2o) is an Atlanta Fine fast ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95113</th>\n",
" <td>3</td>\n",
" <td>Donald Deskey</td>\n",
" <td>Donald Deskey (November 23 1894 – April 29 19...</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
@ -198,31 +200,31 @@
], ],
"text/plain": [ "text/plain": [
" Label Name \\\n", " Label Name \\\n",
"500996 13 The County Chairman \n", "380616 10 Stilifer akahitode \n",
"40795 2 Our Lady of Mount Carmel High School (Baltimor... \n", "500198 13 Ip Man 2 \n",
"131453 4 Jim Kleinsasser \n", "88377 3 Achuta Manasa \n",
"122291 4 August Klingler \n", "377145 10 Bombyx incomposita \n",
"38965 1 Fine Fare \n", "29060 1 W. W. Greener \n",
"89852 3 Desmond Devlin \n", "198749 5 Robert E. Holmes \n",
"481930 13 A Sister to Assist 'Er (1938 film) \n", "488653 13 My Giant \n",
"95008 3 Megumi Makihara \n", "320765 9 Lockland Ohio \n",
"543571 14 Annals of Science \n", "7583 1 Fresh to Order \n",
"356791 9 Dula Gavabar \n", "95113 3 Donald Deskey \n",
"\n", "\n",
" Text \n", " Text \n",
"500996 The County Chairman is a 1935 comedy film dir... \n", "380616 Stilifer akahitode is a species of sea snail ... \n",
"40795 Our Lady of Mount Carmel High School (OLMC HS... \n", "500198 Ip Man 2 is a 2010 Hong Kong biographical mar... \n",
"131453 Jimmy Carter Kleinsasser (/ˈklaɪnsɑːsər/; bor... \n", "88377 Achuta Manasa is an Indian kuchipudi dancer. \n",
"122291 August Klingler (24 February 1918 – 23 Novemb... \n", "377145 Bombyx incomposita is a moth in the Bombycida... \n",
"38965 Fine Fare was the name of a chain of supermar... \n", "29060 W.W. Greener is a sporting shotgun and rifle ... \n",
"89852 Desmond Devlin is an American comedy writer. ... \n", "198749 Robert Edward Holmes (November 14 1922 – July... \n",
"481930 A Sister to Assist 'Er is a 1938 British come... \n", "488653 My Giant is a 1998 comedy drama film starring... \n",
"95008 Megumi Makihara (槇原めぐみ or 槙原めぐみ or 慎原めぐみ Maki... \n", "320765 Lockland is a village in Hamilton County Ohio... \n",
"543571 Annals of Science is a peer-reviewed academic... \n", "7583 Fresh to Order (f2o) is an Atlanta Fine fast ... \n",
"356791 Dula Gavabar (Persian: دولاگوابر‎ also Romani... " "95113 Donald Deskey (November 23 1894 – April 29 19... "
] ]
}, },
"execution_count": 7, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -233,7 +235,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -242,7 +244,7 @@
"(10000, 3)" "(10000, 3)"
] ]
}, },
"execution_count": 8, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -253,7 +255,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -264,21 +266,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"113209 Eisuke Yoshiyuki (吉行 エイスケ Yoshiyuki Eisuke Ma...\n", "37295 Malibu Comics (also known as Malibu Graphics)...\n",
"10443 Schroders plc is a British multinational asse...\n", "543193 Data & Knowledge Engineering (DKE) is a journ...\n",
"152897 Patrice Ferri is a retired French association...\n", "221689 USS Swordfish (SS-193) a Sargo-class submarin...\n",
"485929 Honey 2 is a dance film which is a sequel to ...\n", "374962 Dioryctria is a genus of snout moths. It was ...\n",
"312910 Marjanah is an impact crater in the northern ...\n", "240744 Midsummer House is a restaurant located in Ca...\n",
"Name: Text, dtype: object" "Name: Text, dtype: object"
] ]
}, },
"execution_count": 10, "execution_count": 9,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -289,21 +291,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"113209 3\n", "37295 1\n",
"10443 1\n", "543193 14\n",
"152897 4\n", "221689 6\n",
"485929 13\n", "374962 10\n",
"312910 8\n", "240744 7\n",
"Name: Label, dtype: int64" "Name: Label, dtype: int64"
] ]
}, },
"execution_count": 11, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -314,7 +316,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -334,16 +336,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"(10000, 48133)" "(10000, 47912)"
] ]
}, },
"execution_count": 13, "execution_count": 12,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -358,51 +360,59 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
" (0, 44965)\t1\n", " (0, 25727)\t4\n",
" (0, 45159)\t1\n", " (0, 10069)\t3\n",
" (0, 24477)\t1\n", " (0, 3015)\t1\n",
" (0, 30174)\t1\n", " (0, 22973)\t2\n",
" (0, 5353)\t1\n", " (0, 4138)\t1\n",
" (0, 2617)\t2\n", " (0, 17865)\t1\n",
" (0, 4213)\t1\n", " (0, 44316)\t2\n",
" (0, 29184)\t1\n", " (0, 3249)\t1\n",
" (0, 770)\t1\n", " (0, 3150)\t1\n",
" (0, 41370)\t1\n", " (0, 10066)\t1\n",
" (0, 2229)\t1\n", " (0, 6616)\t1\n",
" (0, 22994)\t1\n", " (0, 33404)\t1\n",
" (0, 44731)\t1\n", " (0, 2204)\t1\n",
" (0, 22447)\t1\n", " (0, 20470)\t3\n",
" (0, 11806)\t1\n", " (0, 41304)\t5\n",
" (0, 3406)\t1\n", " (0, 23891)\t1\n",
" (0, 29564)\t1\n", " (0, 793)\t1\n",
" (0, 3087)\t1\n", " (0, 3321)\t3\n",
" (0, 21905)\t1\n", " (0, 13674)\t1\n",
" (0, 38741)\t1\n", " (0, 806)\t1\n",
" (0, 19410)\t3\n", " (0, 5866)\t1\n",
" (0, 32904)\t1\n", " (0, 16106)\t1\n",
" (0, 30043)\t1\n", " (0, 21167)\t1\n",
" (0, 20446)\t1\n", " (0, 42818)\t1\n",
" (0, 6733)\t1\n", " (0, 24564)\t1\n",
" (0, 18881)\t1\n", " (0, 29944)\t1\n",
" (0, 4662)\t2\n", " (0, 40128)\t1\n",
" (0, 21408)\t1\n", " (0, 41698)\t2\n",
" (0, 44526)\t4\n", " (0, 29511)\t1\n",
" (0, 696)\t1\n", " (0, 42877)\t1\n",
" (0, 21879)\t1\n", " (0, 23582)\t1\n",
" (0, 653)\t1\n", " (0, 20509)\t2\n",
" (0, 27)\t1\n", " (0, 26866)\t1\n",
" (0, 26417)\t1\n", " (0, 6248)\t2\n",
" (0, 47763)\t1\n", " (0, 42815)\t1\n",
" (0, 47850)\t1\n", " (0, 29227)\t1\n",
" (0, 45736)\t4\n", " (0, 25786)\t1\n",
" (0, 13969)\t3\n" " (0, 14980)\t1\n",
" (0, 37256)\t1\n",
" (0, 10150)\t1\n",
" (0, 18936)\t1\n",
" (0, 7837)\t1\n",
" (0, 7874)\t1\n",
" (0, 20452)\t1\n",
" (0, 2632)\t1\n",
" (0, 14758)\t1\n"
] ]
} }
], ],
@ -412,7 +422,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -421,16 +431,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"(10000, 48133)" "(10000, 47912)"
] ]
}, },
"execution_count": 16, "execution_count": 15,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -441,7 +451,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -450,16 +460,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"((8000, 48133), (2000, 48133))" "((8000, 47912), (2000, 47912))"
] ]
}, },
"execution_count": 18, "execution_count": 17,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -470,7 +480,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -479,7 +489,7 @@
"((8000,), (2000,))" "((8000,), (2000,))"
] ]
}, },
"execution_count": 19, "execution_count": 18,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -490,9 +500,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"ename": "TypeError",
"evalue": "np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[19], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m clf \u001b[39m=\u001b[39m GaussianNB()\u001b[39m.\u001b[39;49mfit(x_train, y_train)\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.9/site-packages/sklearn/naive_bayes.py:267\u001b[0m, in \u001b[0;36mGaussianNB.fit\u001b[0;34m(self, X, y, sample_weight)\u001b[0m\n\u001b[1;32m 265\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_validate_params()\n\u001b[1;32m 266\u001b[0m y \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_validate_data(y\u001b[39m=\u001b[39my)\n\u001b[0;32m--> 267\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_partial_fit(\n\u001b[1;32m 268\u001b[0m X, y, np\u001b[39m.\u001b[39;49munique(y), _refit\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m, sample_weight\u001b[39m=\u001b[39;49msample_weight\n\u001b[1;32m 269\u001b[0m )\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.9/site-packages/sklearn/naive_bayes.py:428\u001b[0m, in \u001b[0;36mGaussianNB._partial_fit\u001b[0;34m(self, X, y, classes, _refit, sample_weight)\u001b[0m\n\u001b[1;32m 425\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mclasses_ \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 427\u001b[0m first_call \u001b[39m=\u001b[39m _check_partial_fit_first_call(\u001b[39mself\u001b[39m, classes)\n\u001b[0;32m--> 428\u001b[0m X, y \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_validate_data(X, y, reset\u001b[39m=\u001b[39;49mfirst_call)\n\u001b[1;32m 429\u001b[0m \u001b[39mif\u001b[39;00m sample_weight \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 430\u001b[0m sample_weight \u001b[39m=\u001b[39m _check_sample_weight(sample_weight, X)\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.9/site-packages/sklearn/base.py:584\u001b[0m, in \u001b[0;36mBaseEstimator._validate_data\u001b[0;34m(self, X, y, reset, validate_separately, **check_params)\u001b[0m\n\u001b[1;32m 582\u001b[0m y \u001b[39m=\u001b[39m check_array(y, input_name\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39my\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mcheck_y_params)\n\u001b[1;32m 583\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 584\u001b[0m X, y \u001b[39m=\u001b[39m check_X_y(X, y, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mcheck_params)\n\u001b[1;32m 585\u001b[0m out \u001b[39m=\u001b[39m X, y\n\u001b[1;32m 587\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m no_val_X \u001b[39mand\u001b[39;00m check_params\u001b[39m.\u001b[39mget(\u001b[39m\"\u001b[39m\u001b[39mensure_2d\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39mTrue\u001b[39;00m):\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.9/site-packages/sklearn/utils/validation.py:1106\u001b[0m, in \u001b[0;36mcheck_X_y\u001b[0;34m(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, estimator)\u001b[0m\n\u001b[1;32m 1101\u001b[0m estimator_name \u001b[39m=\u001b[39m _check_estimator_name(estimator)\n\u001b[1;32m 1102\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 1103\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m{\u001b[39;00mestimator_name\u001b[39m}\u001b[39;00m\u001b[39m requires y to be passed, but the target y is None\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 1104\u001b[0m )\n\u001b[0;32m-> 1106\u001b[0m X \u001b[39m=\u001b[39m check_array(\n\u001b[1;32m 1107\u001b[0m X,\n\u001b[1;32m 1108\u001b[0m accept_sparse\u001b[39m=\u001b[39;49maccept_sparse,\n\u001b[1;32m 1109\u001b[0m accept_large_sparse\u001b[39m=\u001b[39;49maccept_large_sparse,\n\u001b[1;32m 1110\u001b[0m dtype\u001b[39m=\u001b[39;49mdtype,\n\u001b[1;32m 1111\u001b[0m order\u001b[39m=\u001b[39;49morder,\n\u001b[1;32m 1112\u001b[0m copy\u001b[39m=\u001b[39;49mcopy,\n\u001b[1;32m 1113\u001b[0m force_all_finite\u001b[39m=\u001b[39;49mforce_all_finite,\n\u001b[1;32m 1114\u001b[0m ensure_2d\u001b[39m=\u001b[39;49mensure_2d,\n\u001b[1;32m 1115\u001b[0m allow_nd\u001b[39m=\u001b[39;49mallow_nd,\n\u001b[1;32m 1116\u001b[0m ensure_min_samples\u001b[39m=\u001b[39;49mensure_min_samples,\n\u001b[1;32m 1117\u001b[0m ensure_min_features\u001b[39m=\u001b[39;49mensure_min_features,\n\u001b[1;32m 1118\u001b[0m estimator\u001b[39m=\u001b[39;49mestimator,\n\u001b[1;32m 1119\u001b[0m input_name\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39mX\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m 1120\u001b[0m )\n\u001b[1;32m 1122\u001b[0m y \u001b[39m=\u001b[39m _check_y(y, multi_output\u001b[39m=\u001b[39mmulti_output, y_numeric\u001b[39m=\u001b[39my_numeric, estimator\u001b[39m=\u001b[39mestimator)\n\u001b[1;32m 1124\u001b[0m check_consistent_length(X, y)\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.9/site-packages/sklearn/utils/validation.py:737\u001b[0m, in \u001b[0;36mcheck_array\u001b[0;34m(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name)\u001b[0m\n\u001b[1;32m 646\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Input validation on an array, list, sparse matrix or similar.\u001b[39;00m\n\u001b[1;32m 647\u001b[0m \n\u001b[1;32m 648\u001b[0m \u001b[39mBy default, the input is checked to be a non-empty 2D array containing\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 734\u001b[0m \u001b[39m The converted and validated array.\u001b[39;00m\n\u001b[1;32m 735\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 736\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(array, np\u001b[39m.\u001b[39mmatrix):\n\u001b[0;32m--> 737\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\n\u001b[1;32m 738\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnp.matrix is not supported. Please convert to a numpy array with \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 739\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mnp.asarray. For more information see: \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 740\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mhttps://numpy.org/doc/stable/reference/generated/numpy.matrix.html\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 741\u001b[0m )\n\u001b[1;32m 743\u001b[0m xp, is_array_api \u001b[39m=\u001b[39m get_namespace(array)\n\u001b[1;32m 745\u001b[0m \u001b[39m# store reference to original array to check if copy is needed when\u001b[39;00m\n\u001b[1;32m 746\u001b[0m \u001b[39m# function returns\u001b[39;00m\n",
"\u001b[0;31mTypeError\u001b[0m: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html"
]
}
],
"source": [ "source": [
"clf = GaussianNB().fit(x_train, y_train)" "clf = GaussianNB().fit(x_train, y_train)"
] ]
@ -563,7 +590,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.1" "version": "3.9.7"
} }
}, },
"nbformat": 4, "nbformat": 4,

View file

@ -39,12 +39,24 @@ In table \ref{table:features}, the feature description details are listed. In be
sparepart/cooling-system/thermostat sparepart/cooling-system/thermostat
\end{quote} \end{quote}
The number of category levels differ for each products. The number of category levels differ for each products. In this experiment, consider 5 levels of categories as the maximum limit.
\begin{table}
\caption{Level 5 category sample data}
\label{table:l5}
\begin{tabular}{llllll}
\toprule
catlevel0 & catlevel1 & catlevel2 & catlevel3 & catlevel4 & catlevel5 \\
\midrule
sparepart & cooling system & thermostat & NaN & NaN & NaN \\
\begin{table}[h!] \bottomrule
\begin{center} \end{tabular}
\end{table}
\begin{table}
\caption{Feature descriptions} \caption{Feature descriptions}
\begin{tabular}{ p{0.3cm}p{3cm}p{6cm} } \label{table:features}
\begin{tabular}{ lll }
\toprule \toprule
\textbf{No}& \textbf{Feature} & \textbf{Value}\\ \textbf{No}& \textbf{Feature} & \textbf{Value}\\
@ -54,29 +66,11 @@ The number of category levels differ for each products.
3&Manufacturere & name of company manfactured\\ 3&Manufacturere & name of company manfactured\\
4&Short description & product info displayed\\ 4&Short description & product info displayed\\
5&Supplier & supplier of the product\\ 5&Supplier & supplier of the product\\
6&n number of \newline category levels & feature extracted from category tree\\ \color{red}6&n number of category levels & feature extracted from category tree\\
\hline
\end{tabular}
\end{center}
\label{table:features}
\end{table}
\begin{tabular}{llllllllrr}
\toprule
& name & sdesc & category & catlevel0 & catlevel1 & catlevel2 & catlevel3 & catlevel4 & catlevel5 \\
\midrule
0 & denso dtm82363 thermostat coolant & thermostat coolant & thermostat & sparepart & cooling system & thermostat & NaN & NaN & NaN \\
1 & zf 1043 010 297 automatic transmission & automatic transmission & automatic transmission & sparepart & transmission & automatic transmission & automatic transmission & NaN & NaN \\
2 & zf 1060 040 003 automatic transmission & automatic transmission & automatic transmission & sparepart & transmission & automatic transmission & automatic transmission & NaN & NaN \\
3 & vaico v10 0131 camshaft & camshaft & camshaft & sparepart & engine & engine timing & camshaft & NaN & NaN \\
4 & vaico v26 0302 track control arm & track control arm & track control arm & sparepart & powertrain suspension & wheel suspension & track control arm & NaN & NaN \\
5 & vaico v30 1250 1 suspension kit & suspension kit & suspension kit & sparepart & powertrain suspension & wheel suspension & suspension kit & NaN & NaN \\
6 & vaico v10 0474 1 tensioner pulley timing belt & tensioner pulley timing belt & tensioner pulley & sparepart & belt drive & tensioner pulley & NaN & NaN & NaN \\
7 & vaico v10 2660 mounting automatic transmission & mounting automatic transmission & mounting & sparepart & transmission & automatic transmission & mounting & NaN & NaN \\
8 & vaico v10 4245 shock absorber & shock absorber & shock absorber & sparepart & powertrain suspension & suspension & shock absorber & NaN & NaN \\
9 & vaico v24 0908 wheel hub & wheel hub & wheel hub & sparepart & powertrain suspension & wheel suspension & wheel hub & NaN & NaN \\
\bottomrule \bottomrule
\end{tabular} \end{tabular}
\end{table}
The table headings of \ref{table:l5} are also the features.

View file

@ -7,10 +7,10 @@
\usepackage[nohyperlinks, printonlyused, withpage, smaller]{acronym} \usepackage[nohyperlinks, printonlyused, withpage, smaller]{acronym}
\usepackage[sorting=ynt,backend=biber,style=authoryear,block=par]{biblatex} \usepackage[sorting=ynt,backend=biber,style=authoryear,block=par]{biblatex}
\usepackage[inkscapeformat=png]{svg} \usepackage[inkscapeformat=png]{svg}
\usepackage{booktabs,array} \usepackage{booktabs,multirow,array}
\usepackage{listings} \usepackage{listings}
\usepackage{xcolor} \usepackage{xcolor}
\usepackage{caption} \usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\captionsetup[table]{skip=5pt} \captionsetup[table]{skip=5pt}

View file

@ -20,7 +20,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -42,7 +42,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -59,7 +59,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -74,7 +74,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -84,7 +84,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -130,7 +130,7 @@
"Index: []" "Index: []"
] ]
}, },
"execution_count": 11, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -141,7 +141,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -165,7 +165,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -176,7 +176,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -266,7 +266,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -367,17 +367,29 @@
"</div>" "</div>"
], ],
"text/plain": [ "text/plain": [
" name ... catlevel5\n", " name sdesc \\\n",
"0 denso dtm82363 thermostat coolant ... NaN\n", "0 denso dtm82363 thermostat coolant thermostat coolant \n",
"1 zf 1043 010 297 automatic transmission ... NaN\n", "1 zf 1043 010 297 automatic transmission automatic transmission \n",
"2 zf 1060 040 003 automatic transmission ... NaN\n", "2 zf 1060 040 003 automatic transmission automatic transmission \n",
"3 vaico v10 0131 camshaft ... NaN\n", "3 vaico v10 0131 camshaft camshaft \n",
"4 vaico v26 0302 track control arm ... NaN\n", "4 vaico v26 0302 track control arm track control arm \n",
"\n", "\n",
"[5 rows x 9 columns]" " category catlevel0 catlevel1 \\\n",
"0 thermostat sparepart cooling system \n",
"1 automatic transmission sparepart transmission \n",
"2 automatic transmission sparepart transmission \n",
"3 camshaft sparepart engine \n",
"4 track control arm sparepart powertrain suspension \n",
"\n",
" catlevel2 catlevel3 catlevel4 catlevel5 \n",
"0 thermostat NaN NaN NaN \n",
"1 automatic transmission automatic transmission NaN NaN \n",
"2 automatic transmission automatic transmission NaN NaN \n",
"3 engine timing camshaft NaN NaN \n",
"4 wheel suspension track control arm NaN NaN "
] ]
}, },
"execution_count": 15, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -386,6 +398,39 @@
"df_eng.head()" "df_eng.head()"
] ]
}, },
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{tabular}{llllllllrr}\n",
"\\toprule\n",
" & name & sdesc & category & catlevel0 & catlevel1 & catlevel2 & catlevel3 & catlevel4 & catlevel5 \\\\\n",
"\\midrule\n",
"0 & denso dtm82363 thermostat coolant & thermostat coolant & thermostat & sparepart & cooling system & thermostat & NaN & NaN & NaN \\\\\n",
"1 & zf 1043 010 297 automatic transmission & automatic transmission & automatic transmission & sparepart & transmission & automatic transmission & automatic transmission & NaN & NaN \\\\\n",
"2 & zf 1060 040 003 automatic transmission & automatic transmission & automatic transmission & sparepart & transmission & automatic transmission & automatic transmission & NaN & NaN \\\\\n",
"3 & vaico v10 0131 camshaft & camshaft & camshaft & sparepart & engine & engine timing & camshaft & NaN & NaN \\\\\n",
"4 & vaico v26 0302 track control arm & track control arm & track control arm & sparepart & powertrain suspension & wheel suspension & track control arm & NaN & NaN \\\\\n",
"5 & vaico v30 1250 1 suspension kit & suspension kit & suspension kit & sparepart & powertrain suspension & wheel suspension & suspension kit & NaN & NaN \\\\\n",
"6 & vaico v10 0474 1 tensioner pulley timing belt & tensioner pulley timing belt & tensioner pulley & sparepart & belt drive & tensioner pulley & NaN & NaN & NaN \\\\\n",
"7 & vaico v10 2660 mounting automatic transmission & mounting automatic transmission & mounting & sparepart & transmission & automatic transmission & mounting & NaN & NaN \\\\\n",
"8 & vaico v10 4245 shock absorber & shock absorber & shock absorber & sparepart & powertrain suspension & suspension & shock absorber & NaN & NaN \\\\\n",
"9 & vaico v24 0908 wheel hub & wheel hub & wheel hub & sparepart & powertrain suspension & wheel suspension & wheel hub & NaN & NaN \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"\n"
]
}
],
"source": [
"print (df_eng.to_latex())"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,