Proof of concept for automatic category guessing for OpenFoodFacts data.

notebook.ipynb 62KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 2,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import collections\n",
  10. "import itertools\n",
  11. "import json\n",
  12. "import os\n",
  13. "\n",
  14. "import numpy as np\n",
  15. "import pandas\n",
  16. "import random\n",
  17. "\n",
  18. "from sklearn.externals import joblib\n",
  19. "from sklearn.feature_extraction.text import CountVectorizer\n",
  20. "from sklearn.feature_extraction.text import TfidfTransformer\n",
  21. "from sklearn.multiclass import OneVsRestClassifier\n",
  22. "from sklearn.pipeline import Pipeline\n",
  23. "from sklearn.preprocessing import MultiLabelBinarizer\n",
  24. "from sklearn.svm import LinearSVC\n",
  25. "\n",
  26. "MIN_NUMBER_PRODUCTS_PER_CATEGORY = 25\n",
  27. "TRAINING_DATASET_SIZE = 50 / 100"
  28. ]
  29. },
  30. {
  31. "cell_type": "markdown",
  32. "metadata": {},
  33. "source": [
  34. "## Load data from CSV dump"
  35. ]
  36. },
  37. {
  38. "cell_type": "code",
  39. "execution_count": 26,
  40. "metadata": {},
  41. "outputs": [],
  42. "source": [
  43. "csv = pandas.read_csv(\n",
  44. " 'en.openfoodfacts.org.products.csv',\n",
  45. " sep='\\t',\n",
  46. " usecols=[0, 7, 15],\n",
  47. " dtype={'code': 'str', 'product_name': 'str'},\n",
  48. " converters={'categories_tags': lambda x: x.split(',') if x else np.NaN}\n",
  49. ")\n",
  50. "# Filter products with and without categories in two different DataFrames\n",
  51. "products_with_categories = csv[pandas.notnull(csv['categories_tags'])]\n",
  52. "products_without_categories = csv[pandas.isnull(csv['categories_tags'])]"
  53. ]
  54. },
  55. {
  56. "cell_type": "markdown",
  57. "metadata": {},
  58. "source": [
  59. "## Fitting on dataset"
  60. ]
  61. },
  62. {
  63. "cell_type": "code",
  64. "execution_count": 27,
  65. "metadata": {},
  66. "outputs": [],
  67. "source": [
  68. "# Let's build vectors of products and categories, for training purpose.\n",
  69. "categories = [\n",
  70. " category\n",
  71. " for category, count in collections.Counter(\n",
  72. " category for category_list in products_with_categories['categories_tags'] for category in category_list\n",
  73. " ).items()\n",
  74. " if count > MIN_NUMBER_PRODUCTS_PER_CATEGORY and category != ''\n",
  75. "]\n",
  76. "# Filter out empty lists of categories\n",
  77. "XY = products_with_categories.copy()\n",
  78. "XY['categories_tags'] = XY['categories_tags'].map(lambda c_list: [c for c in c_list if c in categories])\n",
  79. "mask = XY['categories_tags'].str.len() > 0\n",
  80. "XY = XY[mask]\n",
  81. "# TODO: We should ensure each category is sufficiently represented"
  82. ]
  83. },
  84. {
  85. "cell_type": "code",
  86. "execution_count": 28,
  87. "metadata": {},
  88. "outputs": [],
  89. "source": [
  90. "# Select training sample\n",
  91. "XY_training = XY.sample(frac=0.5)\n",
  92. "X_train = XY_training['product_name'].values.astype('U')\n",
  93. "Y_train = [np.array(c).astype('U') for c in XY_training['categories_tags'].values]"
  94. ]
  95. },
  96. {
  97. "cell_type": "code",
  98. "execution_count": 29,
  99. "metadata": {},
  100. "outputs": [],
  101. "source": [
  102. "mlb = MultiLabelBinarizer()\n",
  103. "Y_train_transformed = mlb.fit_transform(Y_train)"
  104. ]
  105. },
  106. {
  107. "cell_type": "code",
  108. "execution_count": 335,
  109. "metadata": {},
  110. "outputs": [
  111. {
  112. "data": {
  113. "text/plain": [
  114. "Pipeline(memory=None,\n",
  115. " steps=[('vectorizer', CountVectorizer(analyzer='word', binary=False, decode_error='strict',\n",
  116. " dtype=<class 'numpy.int64'>, encoding='utf-8', input='content',\n",
  117. " lowercase=True, max_df=1.0, max_features=None, min_df=1,\n",
  118. " ngram_range=(1, 1), preprocessor=None, stop_words=None,\n",
  119. " ...lti_class='ovr', penalty='l2', random_state=None, tol=0.0001,\n",
  120. " verbose=0),\n",
  121. " n_jobs=1))])"
  122. ]
  123. },
  124. "execution_count": 335,
  125. "metadata": {},
  126. "output_type": "execute_result"
  127. }
  128. ],
  129. "source": [
  130. "# Fit our classifier\n",
  131. "classifier = Pipeline([\n",
  132. " ('vectorizer', CountVectorizer()),\n",
  133. " ('tfidf', TfidfTransformer()),\n",
  134. " ('clf', OneVsRestClassifier(LinearSVC()))])\n",
  135. "\n",
  136. "classifier.fit(X_train, Y_train_transformed)"
  137. ]
  138. },
  139. {
  140. "cell_type": "code",
  141. "execution_count": 380,
  142. "metadata": {},
  143. "outputs": [],
  144. "source": [
  145. "# Check score on a testing set\n",
  146. "training_indices = np.in1d(XY['product_name'].values.astype('U'), X_train, invert=True)\n",
  147. "X_test = XY['product_name'][training_indices]\n",
  148. "Y_test = [np.array(c).astype('U') for c in XY['categories_tags'][training_indices].values]\n",
  149. "\n",
  150. "predicted = classifier.predict(X_test)\n",
  151. "all_labels = mlb.inverse_transform(predicted)"
  152. ]
  153. },
  154. {
  155. "cell_type": "code",
  156. "execution_count": 394,
  157. "metadata": {},
  158. "outputs": [
  159. {
  160. "data": {
  161. "text/html": [
  162. "<div>\n",
  163. "<style>\n",
  164. " .dataframe thead tr:only-child th {\n",
  165. " text-align: right;\n",
  166. " }\n",
  167. "\n",
  168. " .dataframe thead th {\n",
  169. " text-align: left;\n",
  170. " }\n",
  171. "\n",
  172. " .dataframe tbody tr th {\n",
  173. " vertical-align: top;\n",
  174. " }\n",
  175. "</style>\n",
  176. "<table border=\"1\" class=\"dataframe\">\n",
  177. " <thead>\n",
  178. " <tr style=\"text-align: right;\">\n",
  179. " <th></th>\n",
  180. " <th>product_name</th>\n",
  181. " <th>original_labels</th>\n",
  182. " <th>guessed_labels</th>\n",
  183. " </tr>\n",
  184. " </thead>\n",
  185. " <tbody>\n",
  186. " <tr>\n",
  187. " <th>176</th>\n",
  188. " <td>Salade Cesar</td>\n",
  189. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  190. " <td>(en:meals, fr:salades-composees)</td>\n",
  191. " </tr>\n",
  192. " <tr>\n",
  193. " <th>184</th>\n",
  194. " <td>lentilles vertes</td>\n",
  195. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  196. " <td>(en:green-lentils, en:legume-seeds, en:legumes...</td>\n",
  197. " </tr>\n",
  198. " <tr>\n",
  199. " <th>185</th>\n",
  200. " <td>Root Beer</td>\n",
  201. " <td>[en:beverages, en:carbonated-drinks, en:sodas,...</td>\n",
  202. " <td>(en:alcoholic-beverages, en:beers, en:beverage...</td>\n",
  203. " </tr>\n",
  204. " <tr>\n",
  205. " <th>186</th>\n",
  206. " <td>Biscuits sablés fourrage au cacao</td>\n",
  207. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  208. " <td>(en:biscuits, en:biscuits-and-cakes, en:chocol...</td>\n",
  209. " </tr>\n",
  210. " <tr>\n",
  211. " <th>238</th>\n",
  212. " <td>Blle Pet 50CL Coca Cola Cherry</td>\n",
  213. " <td>[en:beverages, en:sugared-beverages]</td>\n",
  214. " <td>(en:beverages, en:non-sugared-beverages, en:so...</td>\n",
  215. " </tr>\n",
  216. " <tr>\n",
  217. " <th>244</th>\n",
  218. " <td>Cauliflower</td>\n",
  219. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  220. " <td>(en:fruits-and-vegetables-based-foods, en:leaf...</td>\n",
  221. " </tr>\n",
  222. " <tr>\n",
  223. " <th>247</th>\n",
  224. " <td>Salsa de mostaza</td>\n",
  225. " <td>[en:groceries, en:condiments, en:sauces, en:mu...</td>\n",
  226. " <td>(en:condiments, en:groceries, en:mustards, en:...</td>\n",
  227. " </tr>\n",
  228. " <tr>\n",
  229. " <th>249</th>\n",
  230. " <td>7Up</td>\n",
  231. " <td>[en:plant-based-foods-and-beverages, en:bevera...</td>\n",
  232. " <td>(en:beverages, en:non-sugared-beverages)</td>\n",
  233. " </tr>\n",
  234. " <tr>\n",
  235. " <th>276</th>\n",
  236. " <td>Mehrkomponeneten Protein 90 C6 Haselnuß</td>\n",
  237. " <td>[en:dietary-supplements, en:bodybuilding-suppl...</td>\n",
  238. " <td>(en:bodybuilding-supplements, en:dietary-suppl...</td>\n",
  239. " </tr>\n",
  240. " <tr>\n",
  241. " <th>292</th>\n",
  242. " <td>Cakes aux Fruits</td>\n",
  243. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:d...</td>\n",
  244. " <td>(en:biscuits-and-cakes, en:cakes, en:desserts,...</td>\n",
  245. " </tr>\n",
  246. " <tr>\n",
  247. " <th>309</th>\n",
  248. " <td>Whey Protein aus Molke 1000 Gramm Vanilla</td>\n",
  249. " <td>[en:dietary-supplements, en:bodybuilding-suppl...</td>\n",
  250. " <td>(en:bodybuilding-supplements, en:dietary-suppl...</td>\n",
  251. " </tr>\n",
  252. " <tr>\n",
  253. " <th>310</th>\n",
  254. " <td>Fondants Citron</td>\n",
  255. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:d...</td>\n",
  256. " <td>()</td>\n",
  257. " </tr>\n",
  258. " <tr>\n",
  259. " <th>369</th>\n",
  260. " <td>Sour Fruit Gummies</td>\n",
  261. " <td>[en:sugary-snacks, en:confectioneries, en:cand...</td>\n",
  262. " <td>(en:candies, en:confectioneries, en:sugary-sna...</td>\n",
  263. " </tr>\n",
  264. " <tr>\n",
  265. " <th>421</th>\n",
  266. " <td>Mixed peppers</td>\n",
  267. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  268. " <td>(en:fruits-and-vegetables-based-foods, en:plan...</td>\n",
  269. " </tr>\n",
  270. " <tr>\n",
  271. " <th>437</th>\n",
  272. " <td>30 Panach' Fruits</td>\n",
  273. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:d...</td>\n",
  274. " <td>(en:fruits-and-vegetables-based-foods, en:frui...</td>\n",
  275. " </tr>\n",
  276. " <tr>\n",
  277. " <th>440</th>\n",
  278. " <td>Foie gras de canard du Périgord</td>\n",
  279. " <td>[en:fish-and-meat-and-eggs, fr:foies-gras, fr:...</td>\n",
  280. " <td>(en:fish-and-meat-and-eggs, fr:foies-gras, fr:...</td>\n",
  281. " </tr>\n",
  282. " <tr>\n",
  283. " <th>454</th>\n",
  284. " <td>Terrine de caille aux pruneaux d'Agen</td>\n",
  285. " <td>[en:terrine, fr:terrines-de-volailles]</td>\n",
  286. " <td>(en:terrine,)</td>\n",
  287. " </tr>\n",
  288. " <tr>\n",
  289. " <th>455</th>\n",
  290. " <td>Foie de canard aux figues</td>\n",
  291. " <td>[en:fish-and-meat-and-eggs, fr:foies-gras, fr:...</td>\n",
  292. " <td>(en:fish-and-meat-and-eggs, en:meats)</td>\n",
  293. " </tr>\n",
  294. " <tr>\n",
  295. " <th>458</th>\n",
  296. " <td>Foie gras d'oie Périgord</td>\n",
  297. " <td>[en:fish-and-meat-and-eggs, fr:foies-gras]</td>\n",
  298. " <td>(en:fish-and-meat-and-eggs, fr:foies-gras)</td>\n",
  299. " </tr>\n",
  300. " <tr>\n",
  301. " <th>459</th>\n",
  302. " <td>Foie gras d'oie du Périgord</td>\n",
  303. " <td>[en:fish-and-meat-and-eggs, fr:foies-gras]</td>\n",
  304. " <td>(en:fish-and-meat-and-eggs, fr:foies-gras)</td>\n",
  305. " </tr>\n",
  306. " <tr>\n",
  307. " <th>464</th>\n",
  308. " <td>All Butter Belgian White Chocolate Chunk Cookies</td>\n",
  309. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  310. " <td>(en:biscuits, en:biscuits-and-cakes, en:chocol...</td>\n",
  311. " </tr>\n",
  312. " <tr>\n",
  313. " <th>465</th>\n",
  314. " <td>All Butter Fruity Flapjack Cookies</td>\n",
  315. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  316. " <td>(en:biscuits, en:biscuits-and-cakes, en:cookie...</td>\n",
  317. " </tr>\n",
  318. " <tr>\n",
  319. " <th>467</th>\n",
  320. " <td>All butter Cranberry &amp; Orange Cookies</td>\n",
  321. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  322. " <td>(en:biscuits, en:biscuits-and-cakes, en:cookie...</td>\n",
  323. " </tr>\n",
  324. " <tr>\n",
  325. " <th>468</th>\n",
  326. " <td>All Butter Triple Belgian Chocolate Chunk Cookies</td>\n",
  327. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  328. " <td>(en:biscuits, en:biscuits-and-cakes, en:cookie...</td>\n",
  329. " </tr>\n",
  330. " <tr>\n",
  331. " <th>469</th>\n",
  332. " <td>Cookies Stem Ginger</td>\n",
  333. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  334. " <td>(en:biscuits, en:biscuits-and-cakes, en:cookie...</td>\n",
  335. " </tr>\n",
  336. " <tr>\n",
  337. " <th>472</th>\n",
  338. " <td>Stem Ginger Dunkers</td>\n",
  339. " <td>[en:sugary-snacks, en:biscuits-and-cakes, en:b...</td>\n",
  340. " <td>()</td>\n",
  341. " </tr>\n",
  342. " <tr>\n",
  343. " <th>484</th>\n",
  344. " <td>Reduced Fat Mayonnaise</td>\n",
  345. " <td>[en:groceries, en:sauces, en:mayonnaises]</td>\n",
  346. " <td>(en:dairies, en:groceries, en:milks, en:sauces)</td>\n",
  347. " </tr>\n",
  348. " <tr>\n",
  349. " <th>492</th>\n",
  350. " <td>mostly mesquite honey</td>\n",
  351. " <td>[en:spreads, en:breakfasts, en:sweet-spreads, ...</td>\n",
  352. " <td>(en:breakfasts,)</td>\n",
  353. " </tr>\n",
  354. " <tr>\n",
  355. " <th>496</th>\n",
  356. " <td>Clam Chowder A Condensed Soup</td>\n",
  357. " <td>[en:meals, en:soups]</td>\n",
  358. " <td>(en:meals, en:soups)</td>\n",
  359. " </tr>\n",
  360. " <tr>\n",
  361. " <th>509</th>\n",
  362. " <td>Salade Mac</td>\n",
  363. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  364. " <td>()</td>\n",
  365. " </tr>\n",
  366. " <tr>\n",
  367. " <th>...</th>\n",
  368. " <td>...</td>\n",
  369. " <td>...</td>\n",
  370. " <td>...</td>\n",
  371. " </tr>\n",
  372. " <tr>\n",
  373. " <th>358216</th>\n",
  374. " <td>Sauc Nuoc Mam</td>\n",
  375. " <td>[en:groceries, en:sauces]</td>\n",
  376. " <td>(en:plant-based-foods, en:plant-based-foods-an...</td>\n",
  377. " </tr>\n",
  378. " <tr>\n",
  379. " <th>358217</th>\n",
  380. " <td>Sauce piment doux Thaï</td>\n",
  381. " <td>[en:groceries, en:sauces, en:pimented-sauces]</td>\n",
  382. " <td>(en:groceries, en:sauces)</td>\n",
  383. " </tr>\n",
  384. " <tr>\n",
  385. " <th>358220</th>\n",
  386. " <td>Sauce Piment Sriracha</td>\n",
  387. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  388. " <td>(en:groceries, en:pimented-sauces, en:sauces)</td>\n",
  389. " </tr>\n",
  390. " <tr>\n",
  391. " <th>358222</th>\n",
  392. " <td>Sauce Thaï Satay</td>\n",
  393. " <td>[en:groceries, en:sauces, en:pimented-sauces]</td>\n",
  394. " <td>(en:groceries, en:sauces)</td>\n",
  395. " </tr>\n",
  396. " <tr>\n",
  397. " <th>358225</th>\n",
  398. " <td>Crème de coco allégée</td>\n",
  399. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  400. " <td>(en:plant-based-creams, en:plant-based-foods-a...</td>\n",
  401. " </tr>\n",
  402. " <tr>\n",
  403. " <th>358226</th>\n",
  404. " <td>Nouilles instantanées</td>\n",
  405. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  406. " <td>(en:cereals-and-potatoes, en:cereals-and-their...</td>\n",
  407. " </tr>\n",
  408. " <tr>\n",
  409. " <th>358231</th>\n",
  410. " <td>Pad Thaï Sauce Wok</td>\n",
  411. " <td>[en:groceries, en:sauces]</td>\n",
  412. " <td>(en:sauces,)</td>\n",
  413. " </tr>\n",
  414. " <tr>\n",
  415. " <th>358233</th>\n",
  416. " <td>Pâte de Curry Vert</td>\n",
  417. " <td>[en:groceries, en:sauces]</td>\n",
  418. " <td>(en:curry-pastes, en:groceries)</td>\n",
  419. " </tr>\n",
  420. " <tr>\n",
  421. " <th>358234</th>\n",
  422. " <td>Pâte de curry rouge</td>\n",
  423. " <td>[en:groceries, en:sauces, en:curry-pastes]</td>\n",
  424. " <td>(en:groceries,)</td>\n",
  425. " </tr>\n",
  426. " <tr>\n",
  427. " <th>358242</th>\n",
  428. " <td>Gula Gula Durian</td>\n",
  429. " <td>[en:sugary-snacks, en:confectioneries, en:cand...</td>\n",
  430. " <td>()</td>\n",
  431. " </tr>\n",
  432. " <tr>\n",
  433. " <th>358254</th>\n",
  434. " <td>Boisson au chrysanthème</td>\n",
  435. " <td>[en:plant-based-foods-and-beverages, en:bevera...</td>\n",
  436. " <td>(en:beverages, en:non-sugared-beverages, en:pl...</td>\n",
  437. " </tr>\n",
  438. " <tr>\n",
  439. " <th>358255</th>\n",
  440. " <td>Lychee Drink</td>\n",
  441. " <td>[en:plant-based-foods-and-beverages, en:bevera...</td>\n",
  442. " <td>(en:beverages, en:fruit-based-beverages, en:pl...</td>\n",
  443. " </tr>\n",
  444. " <tr>\n",
  445. " <th>358279</th>\n",
  446. " <td>Pudding nata de coco</td>\n",
  447. " <td>[en:desserts, en:puddings]</td>\n",
  448. " <td>(en:desserts, en:puddings)</td>\n",
  449. " </tr>\n",
  450. " <tr>\n",
  451. " <th>358282</th>\n",
  452. " <td>Glinter Soft Drink Orange</td>\n",
  453. " <td>[en:beverages, en:non-sugared-beverages]</td>\n",
  454. " <td>(en:beverages, en:plant-based-foods-and-bevera...</td>\n",
  455. " </tr>\n",
  456. " <tr>\n",
  457. " <th>358283</th>\n",
  458. " <td>Soft Drink</td>\n",
  459. " <td>[en:beverages, en:artificially-sweetened-bever...</td>\n",
  460. " <td>()</td>\n",
  461. " </tr>\n",
  462. " <tr>\n",
  463. " <th>358293</th>\n",
  464. " <td>Healtier palm oil (L'huile de palme)</td>\n",
  465. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  466. " <td>(en:fats, en:plant-based-foods, en:plant-based...</td>\n",
  467. " </tr>\n",
  468. " <tr>\n",
  469. " <th>358306</th>\n",
  470. " <td>100% Pur Jus 4 agrumes</td>\n",
  471. " <td>[en:plant-based-foods-and-beverages, en:bevera...</td>\n",
  472. " <td>(en:beverages, en:fruit-based-beverages, en:fr...</td>\n",
  473. " </tr>\n",
  474. " <tr>\n",
  475. " <th>358325</th>\n",
  476. " <td>tuna chunks in spring water</td>\n",
  477. " <td>[en:canned-foods, en:seafood, en:fishes, en:ca...</td>\n",
  478. " <td>(en:canned-fishes, en:canned-foods, en:canned-...</td>\n",
  479. " </tr>\n",
  480. " <tr>\n",
  481. " <th>358335</th>\n",
  482. " <td>Santa Cruz Chilli &amp; Lime Dressing</td>\n",
  483. " <td>[en:groceries, en:sauces, en:salad-dressings]</td>\n",
  484. " <td>(en:groceries, en:salad-dressings, en:sauces)</td>\n",
  485. " </tr>\n",
  486. " <tr>\n",
  487. " <th>358343</th>\n",
  488. " <td>Fisherman's Friend Miel-Citron</td>\n",
  489. " <td>[en:sugary-snacks, en:confectioneries, en:cand...</td>\n",
  490. " <td>(en:candies, en:confectioneries, en:sugary-sna...</td>\n",
  491. " </tr>\n",
  492. " <tr>\n",
  493. " <th>358347</th>\n",
  494. " <td>Dessert Noir (lot de 2)</td>\n",
  495. " <td>[en:sugary-snacks, en:chocolates, en:dark-choc...</td>\n",
  496. " <td>(en:chocolates, en:dark-chocolates, en:dessert...</td>\n",
  497. " </tr>\n",
  498. " <tr>\n",
  499. " <th>358351</th>\n",
  500. " <td>Kirkland Purified Drinking Water</td>\n",
  501. " <td>[en:beverages, en:waters, en:non-sugared-bever...</td>\n",
  502. " <td>(en:beverages, en:non-sugared-beverages, en:wa...</td>\n",
  503. " </tr>\n",
  504. " <tr>\n",
  505. " <th>358372</th>\n",
  506. " <td>Boîte de saumon frais trouvée à l'extérieur d'...</td>\n",
  507. " <td>[en:seafood, en:fishes, en:salmons]</td>\n",
  508. " <td>()</td>\n",
  509. " </tr>\n",
  510. " <tr>\n",
  511. " <th>358389</th>\n",
  512. " <td>Cervoise Mexicaine</td>\n",
  513. " <td>[en:beverages, en:alcoholic-beverages, en:arti...</td>\n",
  514. " <td>(en:alcoholic-beverages, en:amber-beers, en:be...</td>\n",
  515. " </tr>\n",
  516. " <tr>\n",
  517. " <th>358399</th>\n",
  518. " <td>Ma bite</td>\n",
  519. " <td>[en:beverages, en:non-sugared-beverages]</td>\n",
  520. " <td>(en:plant-based-foods, en:plant-based-foods-an...</td>\n",
  521. " </tr>\n",
  522. " <tr>\n",
  523. " <th>358400</th>\n",
  524. " <td>Les schtroumpfs &amp; le village des fille</td>\n",
  525. " <td>[en:fats]</td>\n",
  526. " <td>(en:confectioneries, en:sugary-snacks)</td>\n",
  527. " </tr>\n",
  528. " <tr>\n",
  529. " <th>358426</th>\n",
  530. " <td>Les Belles Tranches Bacon fumé</td>\n",
  531. " <td>[en:meats, en:pork, en:bacon, en:sliced-bacon]</td>\n",
  532. " <td>(en:bacon, en:meats, en:pork, en:sliced-bacon)</td>\n",
  533. " </tr>\n",
  534. " <tr>\n",
  535. " <th>358428</th>\n",
  536. " <td>Tartines craquantes bio au sarrasin</td>\n",
  537. " <td>[en:plant-based-foods-and-beverages, en:plant-...</td>\n",
  538. " <td>(en:breads, en:cereals-and-potatoes, en:crispb...</td>\n",
  539. " </tr>\n",
  540. " <tr>\n",
  541. " <th>358438</th>\n",
  542. " <td>Roussette du Bugey (2011)</td>\n",
  543. " <td>[en:beverages, en:alcoholic-beverages, en:wine...</td>\n",
  544. " <td>(en:alcoholic-beverages, en:beverages, en:fren...</td>\n",
  545. " </tr>\n",
  546. " <tr>\n",
  547. " <th>358446</th>\n",
  548. " <td>乐吧泡菜味薯片</td>\n",
  549. " <td>[en:salty-snacks, en:appetizers, en:chips-and-...</td>\n",
  550. " <td>()</td>\n",
  551. " </tr>\n",
  552. " </tbody>\n",
  553. "</table>\n",
  554. "<p>38381 rows × 3 columns</p>\n",
  555. "</div>"
  556. ],
  557. "text/plain": [
  558. " product_name \\\n",
  559. "176 Salade Cesar \n",
  560. "184 lentilles vertes \n",
  561. "185 Root Beer \n",
  562. "186 Biscuits sablés fourrage au cacao \n",
  563. "238 Blle Pet 50CL Coca Cola Cherry \n",
  564. "244 Cauliflower \n",
  565. "247 Salsa de mostaza \n",
  566. "249 7Up \n",
  567. "276 Mehrkomponeneten Protein 90 C6 Haselnuß \n",
  568. "292 Cakes aux Fruits \n",
  569. "309 Whey Protein aus Molke 1000 Gramm Vanilla \n",
  570. "310 Fondants Citron \n",
  571. "369 Sour Fruit Gummies \n",
  572. "421 Mixed peppers \n",
  573. "437 30 Panach' Fruits \n",
  574. "440 Foie gras de canard du Périgord \n",
  575. "454 Terrine de caille aux pruneaux d'Agen \n",
  576. "455 Foie de canard aux figues \n",
  577. "458 Foie gras d'oie Périgord \n",
  578. "459 Foie gras d'oie du Périgord \n",
  579. "464 All Butter Belgian White Chocolate Chunk Cookies \n",
  580. "465 All Butter Fruity Flapjack Cookies \n",
  581. "467 All butter Cranberry & Orange Cookies \n",
  582. "468 All Butter Triple Belgian Chocolate Chunk Cookies \n",
  583. "469 Cookies Stem Ginger \n",
  584. "472 Stem Ginger Dunkers \n",
  585. "484 Reduced Fat Mayonnaise \n",
  586. "492 mostly mesquite honey \n",
  587. "496 Clam Chowder A Condensed Soup \n",
  588. "509 Salade Mac \n",
  589. "... ... \n",
  590. "358216 Sauc Nuoc Mam \n",
  591. "358217 Sauce piment doux Thaï \n",
  592. "358220 Sauce Piment Sriracha \n",
  593. "358222 Sauce Thaï Satay \n",
  594. "358225 Crème de coco allégée \n",
  595. "358226 Nouilles instantanées \n",
  596. "358231 Pad Thaï Sauce Wok \n",
  597. "358233 Pâte de Curry Vert \n",
  598. "358234 Pâte de curry rouge \n",
  599. "358242 Gula Gula Durian \n",
  600. "358254 Boisson au chrysanthème \n",
  601. "358255 Lychee Drink \n",
  602. "358279 Pudding nata de coco \n",
  603. "358282 Glinter Soft Drink Orange \n",
  604. "358283 Soft Drink \n",
  605. "358293 Healtier palm oil (L'huile de palme) \n",
  606. "358306 100% Pur Jus 4 agrumes \n",
  607. "358325 tuna chunks in spring water \n",
  608. "358335 Santa Cruz Chilli & Lime Dressing \n",
  609. "358343 Fisherman's Friend Miel-Citron \n",
  610. "358347 Dessert Noir (lot de 2) \n",
  611. "358351 Kirkland Purified Drinking Water \n",
  612. "358372 Boîte de saumon frais trouvée à l'extérieur d'... \n",
  613. "358389 Cervoise Mexicaine \n",
  614. "358399 Ma bite \n",
  615. "358400 Les schtroumpfs & le village des fille \n",
  616. "358426 Les Belles Tranches Bacon fumé \n",
  617. "358428 Tartines craquantes bio au sarrasin \n",
  618. "358438 Roussette du Bugey (2011) \n",
  619. "358446 乐吧泡菜味薯片 \n",
  620. "\n",
  621. " original_labels \\\n",
  622. "176 [en:plant-based-foods-and-beverages, en:plant-... \n",
  623. "184 [en:plant-based-foods-and-beverages, en:plant-... \n",
  624. "185 [en:beverages, en:carbonated-drinks, en:sodas,... \n",
  625. "186 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  626. "238 [en:beverages, en:sugared-beverages] \n",
  627. "244 [en:plant-based-foods-and-beverages, en:plant-... \n",
  628. "247 [en:groceries, en:condiments, en:sauces, en:mu... \n",
  629. "249 [en:plant-based-foods-and-beverages, en:bevera... \n",
  630. "276 [en:dietary-supplements, en:bodybuilding-suppl... \n",
  631. "292 [en:sugary-snacks, en:biscuits-and-cakes, en:d... \n",
  632. "309 [en:dietary-supplements, en:bodybuilding-suppl... \n",
  633. "310 [en:sugary-snacks, en:biscuits-and-cakes, en:d... \n",
  634. "369 [en:sugary-snacks, en:confectioneries, en:cand... \n",
  635. "421 [en:plant-based-foods-and-beverages, en:plant-... \n",
  636. "437 [en:sugary-snacks, en:biscuits-and-cakes, en:d... \n",
  637. "440 [en:fish-and-meat-and-eggs, fr:foies-gras, fr:... \n",
  638. "454 [en:terrine, fr:terrines-de-volailles] \n",
  639. "455 [en:fish-and-meat-and-eggs, fr:foies-gras, fr:... \n",
  640. "458 [en:fish-and-meat-and-eggs, fr:foies-gras] \n",
  641. "459 [en:fish-and-meat-and-eggs, fr:foies-gras] \n",
  642. "464 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  643. "465 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  644. "467 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  645. "468 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  646. "469 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  647. "472 [en:sugary-snacks, en:biscuits-and-cakes, en:b... \n",
  648. "484 [en:groceries, en:sauces, en:mayonnaises] \n",
  649. "492 [en:spreads, en:breakfasts, en:sweet-spreads, ... \n",
  650. "496 [en:meals, en:soups] \n",
  651. "509 [en:plant-based-foods-and-beverages, en:plant-... \n",
  652. "... ... \n",
  653. "358216 [en:groceries, en:sauces] \n",
  654. "358217 [en:groceries, en:sauces, en:pimented-sauces] \n",
  655. "358220 [en:plant-based-foods-and-beverages, en:plant-... \n",
  656. "358222 [en:groceries, en:sauces, en:pimented-sauces] \n",
  657. "358225 [en:plant-based-foods-and-beverages, en:plant-... \n",
  658. "358226 [en:plant-based-foods-and-beverages, en:plant-... \n",
  659. "358231 [en:groceries, en:sauces] \n",
  660. "358233 [en:groceries, en:sauces] \n",
  661. "358234 [en:groceries, en:sauces, en:curry-pastes] \n",
  662. "358242 [en:sugary-snacks, en:confectioneries, en:cand... \n",
  663. "358254 [en:plant-based-foods-and-beverages, en:bevera... \n",
  664. "358255 [en:plant-based-foods-and-beverages, en:bevera... \n",
  665. "358279 [en:desserts, en:puddings] \n",
  666. "358282 [en:beverages, en:non-sugared-beverages] \n",
  667. "358283 [en:beverages, en:artificially-sweetened-bever... \n",
  668. "358293 [en:plant-based-foods-and-beverages, en:plant-... \n",
  669. "358306 [en:plant-based-foods-and-beverages, en:bevera... \n",
  670. "358325 [en:canned-foods, en:seafood, en:fishes, en:ca... \n",
  671. "358335 [en:groceries, en:sauces, en:salad-dressings] \n",
  672. "358343 [en:sugary-snacks, en:confectioneries, en:cand... \n",
  673. "358347 [en:sugary-snacks, en:chocolates, en:dark-choc... \n",
  674. "358351 [en:beverages, en:waters, en:non-sugared-bever... \n",
  675. "358372 [en:seafood, en:fishes, en:salmons] \n",
  676. "358389 [en:beverages, en:alcoholic-beverages, en:arti... \n",
  677. "358399 [en:beverages, en:non-sugared-beverages] \n",
  678. "358400 [en:fats] \n",
  679. "358426 [en:meats, en:pork, en:bacon, en:sliced-bacon] \n",
  680. "358428 [en:plant-based-foods-and-beverages, en:plant-... \n",
  681. "358438 [en:beverages, en:alcoholic-beverages, en:wine... \n",
  682. "358446 [en:salty-snacks, en:appetizers, en:chips-and-... \n",
  683. "\n",
  684. " guessed_labels \n",
  685. "176 (en:meals, fr:salades-composees) \n",
  686. "184 (en:green-lentils, en:legume-seeds, en:legumes... \n",
  687. "185 (en:alcoholic-beverages, en:beers, en:beverage... \n",
  688. "186 (en:biscuits, en:biscuits-and-cakes, en:chocol... \n",
  689. "238 (en:beverages, en:non-sugared-beverages, en:so... \n",
  690. "244 (en:fruits-and-vegetables-based-foods, en:leaf... \n",
  691. "247 (en:condiments, en:groceries, en:mustards, en:... \n",
  692. "249 (en:beverages, en:non-sugared-beverages) \n",
  693. "276 (en:bodybuilding-supplements, en:dietary-suppl... \n",
  694. "292 (en:biscuits-and-cakes, en:cakes, en:desserts,... \n",
  695. "309 (en:bodybuilding-supplements, en:dietary-suppl... \n",
  696. "310 () \n",
  697. "369 (en:candies, en:confectioneries, en:sugary-sna... \n",
  698. "421 (en:fruits-and-vegetables-based-foods, en:plan... \n",
  699. "437 (en:fruits-and-vegetables-based-foods, en:frui... \n",
  700. "440 (en:fish-and-meat-and-eggs, fr:foies-gras, fr:... \n",
  701. "454 (en:terrine,) \n",
  702. "455 (en:fish-and-meat-and-eggs, en:meats) \n",
  703. "458 (en:fish-and-meat-and-eggs, fr:foies-gras) \n",
  704. "459 (en:fish-and-meat-and-eggs, fr:foies-gras) \n",
  705. "464 (en:biscuits, en:biscuits-and-cakes, en:chocol... \n",
  706. "465 (en:biscuits, en:biscuits-and-cakes, en:cookie... \n",
  707. "467 (en:biscuits, en:biscuits-and-cakes, en:cookie... \n",
  708. "468 (en:biscuits, en:biscuits-and-cakes, en:cookie... \n",
  709. "469 (en:biscuits, en:biscuits-and-cakes, en:cookie... \n",
  710. "472 () \n",
  711. "484 (en:dairies, en:groceries, en:milks, en:sauces) \n",
  712. "492 (en:breakfasts,) \n",
  713. "496 (en:meals, en:soups) \n",
  714. "509 () \n",
  715. "... ... \n",
  716. "358216 (en:plant-based-foods, en:plant-based-foods-an... \n",
  717. "358217 (en:groceries, en:sauces) \n",
  718. "358220 (en:groceries, en:pimented-sauces, en:sauces) \n",
  719. "358222 (en:groceries, en:sauces) \n",
  720. "358225 (en:plant-based-creams, en:plant-based-foods-a... \n",
  721. "358226 (en:cereals-and-potatoes, en:cereals-and-their... \n",
  722. "358231 (en:sauces,) \n",
  723. "358233 (en:curry-pastes, en:groceries) \n",
  724. "358234 (en:groceries,) \n",
  725. "358242 () \n",
  726. "358254 (en:beverages, en:non-sugared-beverages, en:pl... \n",
  727. "358255 (en:beverages, en:fruit-based-beverages, en:pl... \n",
  728. "358279 (en:desserts, en:puddings) \n",
  729. "358282 (en:beverages, en:plant-based-foods-and-bevera... \n",
  730. "358283 () \n",
  731. "358293 (en:fats, en:plant-based-foods, en:plant-based... \n",
  732. "358306 (en:beverages, en:fruit-based-beverages, en:fr... \n",
  733. "358325 (en:canned-fishes, en:canned-foods, en:canned-... \n",
  734. "358335 (en:groceries, en:salad-dressings, en:sauces) \n",
  735. "358343 (en:candies, en:confectioneries, en:sugary-sna... \n",
  736. "358347 (en:chocolates, en:dark-chocolates, en:dessert... \n",
  737. "358351 (en:beverages, en:non-sugared-beverages, en:wa... \n",
  738. "358372 () \n",
  739. "358389 (en:alcoholic-beverages, en:amber-beers, en:be... \n",
  740. "358399 (en:plant-based-foods, en:plant-based-foods-an... \n",
  741. "358400 (en:confectioneries, en:sugary-snacks) \n",
  742. "358426 (en:bacon, en:meats, en:pork, en:sliced-bacon) \n",
  743. "358428 (en:breads, en:cereals-and-potatoes, en:crispb... \n",
  744. "358438 (en:alcoholic-beverages, en:beverages, en:fren... \n",
  745. "358446 () \n",
  746. "\n",
  747. "[38381 rows x 3 columns]"
  748. ]
  749. },
  750. "execution_count": 394,
  751. "metadata": {},
  752. "output_type": "execute_result"
  753. }
  754. ],
  755. "source": [
  756. "testing_dataframe = pandas.DataFrame({\n",
  757. " 'product_name': X_test,\n",
  758. " 'original_labels': Y_test,\n",
  759. " 'guessed_labels': all_labels\n",
  760. "}, columns=['product_name', 'original_labels', 'guessed_labels'])\n",
  761. "testing_dataframe.to_csv('testing.csv', index=False)\n",
  762. "testing_dataframe"
  763. ]
  764. },
  765. {
  766. "cell_type": "code",
  767. "execution_count": 30,
  768. "metadata": {},
  769. "outputs": [
  770. {
  771. "data": {
  772. "text/plain": [
  773. "['offClassifier.pkl']"
  774. ]
  775. },
  776. "execution_count": 30,
  777. "metadata": {},
  778. "output_type": "execute_result"
  779. }
  780. ],
  781. "source": [
  782. "# Dump the classifier\n",
  783. "joblib.dump((mlb, classifier), 'offClassifier.pkl')"
  784. ]
  785. },
  786. {
  787. "cell_type": "markdown",
  788. "metadata": {},
  789. "source": [
  790. "## Predict!"
  791. ]
  792. },
  793. {
  794. "cell_type": "code",
  795. "execution_count": 15,
  796. "metadata": {},
  797. "outputs": [],
  798. "source": [
  799. "def batch(iterable, size):\n",
  800. " \"\"\"\n",
  801. " Get items from a sequence a batch at a time.\n",
  802. "\n",
  803. " :param iterable: The iterable to get the items from.\n",
  804. " :param size: The size of the batches.\n",
  805. " :return: A new iterable.\n",
  806. " \"\"\"\n",
  807. " sourceiter = iter(iterable)\n",
  808. " while True:\n",
  809. " batchiter = itertools.islice(sourceiter, size)\n",
  810. " yield itertools.chain([next(batchiter)], batchiter)"
  811. ]
  812. },
  813. {
  814. "cell_type": "code",
  815. "execution_count": 31,
  816. "metadata": {},
  817. "outputs": [],
  818. "source": [
  819. "# Load the classifier\n",
  820. "mlb, classifier = joblib.load('offClassifier.pkl')"
  821. ]
  822. },
  823. {
  824. "cell_type": "code",
  825. "execution_count": 32,
  826. "metadata": {},
  827. "outputs": [
  828. {
  829. "name": "stderr",
  830. "output_type": "stream",
  831. "text": [
  832. "/home/phyks/.local/share/virtualenvs/machine_learning/lib/python3.6/site-packages/ipykernel_launcher.py:5: DeprecationWarning: generator 'batch' raised StopIteration\n",
  833. " \"\"\"\n"
  834. ]
  835. }
  836. ],
  837. "source": [
  838. "X_predicted = products_without_categories['product_name'].values.astype('U')\n",
  839. "\n",
  840. "all_labels = []\n",
  841. "\n",
  842. "for i in batch(X_predicted, 30000):\n",
  843. " predicted = classifier.predict(list(i))\n",
  844. " all_labels.extend(mlb.inverse_transform(predicted))"
  845. ]
  846. },
  847. {
  848. "cell_type": "code",
  849. "execution_count": 33,
  850. "metadata": {},
  851. "outputs": [
  852. {
  853. "data": {
  854. "text/html": [
  855. "<div>\n",
  856. "<style>\n",
  857. " .dataframe thead tr:only-child th {\n",
  858. " text-align: right;\n",
  859. " }\n",
  860. "\n",
  861. " .dataframe thead th {\n",
  862. " text-align: left;\n",
  863. " }\n",
  864. "\n",
  865. " .dataframe tbody tr th {\n",
  866. " vertical-align: top;\n",
  867. " }\n",
  868. "</style>\n",
  869. "<table border=\"1\" class=\"dataframe\">\n",
  870. " <thead>\n",
  871. " <tr style=\"text-align: right;\">\n",
  872. " <th></th>\n",
  873. " <th>product_name</th>\n",
  874. " <th>guessed_labels</th>\n",
  875. " </tr>\n",
  876. " </thead>\n",
  877. " <tbody>\n",
  878. " <tr>\n",
  879. " <th>0</th>\n",
  880. " <td>Farine de blé noir</td>\n",
  881. " <td>(en:cereal-flours, en:cereals-and-potatoes, en...</td>\n",
  882. " </tr>\n",
  883. " <tr>\n",
  884. " <th>1</th>\n",
  885. " <td>Banana Chips Sweetened (Whole)</td>\n",
  886. " <td>()</td>\n",
  887. " </tr>\n",
  888. " <tr>\n",
  889. " <th>2</th>\n",
  890. " <td>Peanuts</td>\n",
  891. " <td>(en:legumes, en:legumes-and-their-products, en...</td>\n",
  892. " </tr>\n",
  893. " <tr>\n",
  894. " <th>3</th>\n",
  895. " <td>Organic Salted Nut Mix</td>\n",
  896. " <td>()</td>\n",
  897. " </tr>\n",
  898. " <tr>\n",
  899. " <th>4</th>\n",
  900. " <td>Organic Polenta</td>\n",
  901. " <td>(en:cereals-and-potatoes, en:cereals-and-their...</td>\n",
  902. " </tr>\n",
  903. " <tr>\n",
  904. " <th>5</th>\n",
  905. " <td>Breadshop Honey Gone Nuts Granola</td>\n",
  906. " <td>(en:breakfasts, en:sugary-snacks)</td>\n",
  907. " </tr>\n",
  908. " <tr>\n",
  909. " <th>6</th>\n",
  910. " <td>Organic Long Grain White Rice</td>\n",
  911. " <td>(en:cereal-grains, en:cereals-and-potatoes, en...</td>\n",
  912. " </tr>\n",
  913. " <tr>\n",
  914. " <th>7</th>\n",
  915. " <td>Organic Muesli</td>\n",
  916. " <td>(en:breakfast-cereals, en:breakfasts, en:cerea...</td>\n",
  917. " </tr>\n",
  918. " <tr>\n",
  919. " <th>8</th>\n",
  920. " <td>Organic Dark Chocolate Minis</td>\n",
  921. " <td>(en:chocolates, en:dark-chocolates, en:sugary-...</td>\n",
  922. " </tr>\n",
  923. " <tr>\n",
  924. " <th>9</th>\n",
  925. " <td>Organic Sunflower Oil</td>\n",
  926. " <td>(en:fats, en:plant-based-foods, en:plant-based...</td>\n",
  927. " </tr>\n",
  928. " <tr>\n",
  929. " <th>10</th>\n",
  930. " <td>Organic Adzuki Beans</td>\n",
  931. " <td>(en:legumes-and-their-products, en:plant-based...</td>\n",
  932. " </tr>\n",
  933. " <tr>\n",
  934. " <th>11</th>\n",
  935. " <td>Organic Penne Pasta</td>\n",
  936. " <td>(en:cereals-and-potatoes, en:cereals-and-their...</td>\n",
  937. " </tr>\n",
  938. " <tr>\n",
  939. " <th>12</th>\n",
  940. " <td>Zen Party Mix</td>\n",
  941. " <td>()</td>\n",
  942. " </tr>\n",
  943. " <tr>\n",
  944. " <th>13</th>\n",
  945. " <td>Organic Golden Flax Seeds</td>\n",
  946. " <td>(en:plant-based-foods, en:plant-based-foods-an...</td>\n",
  947. " </tr>\n",
  948. " <tr>\n",
  949. " <th>14</th>\n",
  950. " <td>Organic Spicy Punks</td>\n",
  951. " <td>()</td>\n",
  952. " </tr>\n",
  953. " <tr>\n",
  954. " <th>15</th>\n",
  955. " <td>Cinnamon Nut Granola</td>\n",
  956. " <td>(en:breakfast-cereals, en:breakfasts, en:cerea...</td>\n",
  957. " </tr>\n",
  958. " <tr>\n",
  959. " <th>16</th>\n",
  960. " <td>Organic Hazelnuts</td>\n",
  961. " <td>()</td>\n",
  962. " </tr>\n",
  963. " <tr>\n",
  964. " <th>17</th>\n",
  965. " <td>Organic Sweetened Banana Chips</td>\n",
  966. " <td>()</td>\n",
  967. " </tr>\n",
  968. " <tr>\n",
  969. " <th>18</th>\n",
  970. " <td>Lotus Organic Brown Jasmine Rice</td>\n",
  971. " <td>(en:cereal-grains, en:cereals-and-their-produc...</td>\n",
  972. " </tr>\n",
  973. " <tr>\n",
  974. " <th>19</th>\n",
  975. " <td>Organic Oat Groats</td>\n",
  976. " <td>()</td>\n",
  977. " </tr>\n",
  978. " <tr>\n",
  979. " <th>20</th>\n",
  980. " <td>Energy Power Mix</td>\n",
  981. " <td>()</td>\n",
  982. " </tr>\n",
  983. " <tr>\n",
  984. " <th>21</th>\n",
  985. " <td>Antioxidant Mix - Berries &amp; Chocolate</td>\n",
  986. " <td>(en:plant-based-foods-and-beverages,)</td>\n",
  987. " </tr>\n",
  988. " <tr>\n",
  989. " <th>22</th>\n",
  990. " <td>Organic Quinoa Coconut Granola With Mango</td>\n",
  991. " <td>(en:plant-based-foods, en:plant-based-foods-an...</td>\n",
  992. " </tr>\n",
  993. " <tr>\n",
  994. " <th>23</th>\n",
  995. " <td>Fire Roasted Hatch Green Chile Almonds</td>\n",
  996. " <td>()</td>\n",
  997. " </tr>\n",
  998. " <tr>\n",
  999. " <th>24</th>\n",
  1000. " <td>Peanut Butter Power Chews</td>\n",
  1001. " <td>(en:plant-based-foods,)</td>\n",
  1002. " </tr>\n",
  1003. " <tr>\n",
  1004. " <th>25</th>\n",
  1005. " <td>Real Salt Granular</td>\n",
  1006. " <td>(en:chips-and-fries, en:crisps, en:groceries, ...</td>\n",
  1007. " </tr>\n",
  1008. " <tr>\n",
  1009. " <th>26</th>\n",
  1010. " <td>Organic Unswt Berry Coconut Granola</td>\n",
  1011. " <td>(en:plant-based-foods, en:plant-based-foods-an...</td>\n",
  1012. " </tr>\n",
  1013. " <tr>\n",
  1014. " <th>27</th>\n",
  1015. " <td>Roasted Salted Black Pepper Cashews</td>\n",
  1016. " <td>(en:cashew-nuts, en:nuts, en:plant-based-foods...</td>\n",
  1017. " </tr>\n",
  1018. " <tr>\n",
  1019. " <th>28</th>\n",
  1020. " <td>Thai Curry Roasted Cashews</td>\n",
  1021. " <td>(en:cashew-nuts, en:plant-based-foods, en:plan...</td>\n",
  1022. " </tr>\n",
  1023. " <tr>\n",
  1024. " <th>29</th>\n",
  1025. " <td>Wasabi Tamari Almonds</td>\n",
  1026. " <td>(en:condiments, en:groceries, en:plant-based-f...</td>\n",
  1027. " </tr>\n",
  1028. " <tr>\n",
  1029. " <th>...</th>\n",
  1030. " <td>...</td>\n",
  1031. " <td>...</td>\n",
  1032. " </tr>\n",
  1033. " <tr>\n",
  1034. " <th>254346</th>\n",
  1035. " <td>Fairy Tail</td>\n",
  1036. " <td>()</td>\n",
  1037. " </tr>\n",
  1038. " <tr>\n",
  1039. " <th>254347</th>\n",
  1040. " <td>Biscuits aux céréales, aux pépites de chocolat...</td>\n",
  1041. " <td>(en:biscuits, en:biscuits-and-cakes, en:sugary...</td>\n",
  1042. " </tr>\n",
  1043. " <tr>\n",
  1044. " <th>254348</th>\n",
  1045. " <td>Neszt Cochon Con</td>\n",
  1046. " <td>()</td>\n",
  1047. " </tr>\n",
  1048. " <tr>\n",
  1049. " <th>254349</th>\n",
  1050. " <td>nan</td>\n",
  1051. " <td>()</td>\n",
  1052. " </tr>\n",
  1053. " <tr>\n",
  1054. " <th>254350</th>\n",
  1055. " <td>Drid apricot the queen</td>\n",
  1056. " <td>(en:beverages,)</td>\n",
  1057. " </tr>\n",
  1058. " <tr>\n",
  1059. " <th>254351</th>\n",
  1060. " <td>Natural Cassava</td>\n",
  1061. " <td>(en:plant-based-foods-and-beverages,)</td>\n",
  1062. " </tr>\n",
  1063. " <tr>\n",
  1064. " <th>254352</th>\n",
  1065. " <td>nan</td>\n",
  1066. " <td>()</td>\n",
  1067. " </tr>\n",
  1068. " <tr>\n",
  1069. " <th>254353</th>\n",
  1070. " <td>nan</td>\n",
  1071. " <td>()</td>\n",
  1072. " </tr>\n",
  1073. " <tr>\n",
  1074. " <th>254354</th>\n",
  1075. " <td>Soda 1</td>\n",
  1076. " <td>(en:beverages, en:carbonated-drinks, en:sodas,...</td>\n",
  1077. " </tr>\n",
  1078. " <tr>\n",
  1079. " <th>254355</th>\n",
  1080. " <td>Merci 1</td>\n",
  1081. " <td>(en:bonbons, en:candies, en:chocolates, en:cho...</td>\n",
  1082. " </tr>\n",
  1083. " <tr>\n",
  1084. " <th>254356</th>\n",
  1085. " <td>Merci2</td>\n",
  1086. " <td>()</td>\n",
  1087. " </tr>\n",
  1088. " <tr>\n",
  1089. " <th>254357</th>\n",
  1090. " <td>Merci3</td>\n",
  1091. " <td>()</td>\n",
  1092. " </tr>\n",
  1093. " <tr>\n",
  1094. " <th>254358</th>\n",
  1095. " <td>Libro parachute3</td>\n",
  1096. " <td>()</td>\n",
  1097. " </tr>\n",
  1098. " <tr>\n",
  1099. " <th>254359</th>\n",
  1100. " <td>nan</td>\n",
  1101. " <td>()</td>\n",
  1102. " </tr>\n",
  1103. " <tr>\n",
  1104. " <th>254360</th>\n",
  1105. " <td>Vegan easy</td>\n",
  1106. " <td>(en:plant-based-foods, en:plant-based-foods-an...</td>\n",
  1107. " </tr>\n",
  1108. " <tr>\n",
  1109. " <th>254361</th>\n",
  1110. " <td>Tarifs djoghrafia</td>\n",
  1111. " <td>()</td>\n",
  1112. " </tr>\n",
  1113. " <tr>\n",
  1114. " <th>254362</th>\n",
  1115. " <td>nan</td>\n",
  1116. " <td>()</td>\n",
  1117. " </tr>\n",
  1118. " <tr>\n",
  1119. " <th>254363</th>\n",
  1120. " <td>Ferrero Rocher</td>\n",
  1121. " <td>(en:chocolates, en:sugary-snacks)</td>\n",
  1122. " </tr>\n",
  1123. " <tr>\n",
  1124. " <th>254364</th>\n",
  1125. " <td>nan</td>\n",
  1126. " <td>()</td>\n",
  1127. " </tr>\n",
  1128. " <tr>\n",
  1129. " <th>254365</th>\n",
  1130. " <td>Raspados Ice Bars</td>\n",
  1131. " <td>(en:bars, en:cereal-bars, en:sugary-snacks)</td>\n",
  1132. " </tr>\n",
  1133. " <tr>\n",
  1134. " <th>254366</th>\n",
  1135. " <td>nf test</td>\n",
  1136. " <td>(en:beverages,)</td>\n",
  1137. " </tr>\n",
  1138. " <tr>\n",
  1139. " <th>254367</th>\n",
  1140. " <td>Amandes</td>\n",
  1141. " <td>(en:almonds, en:chocolates-with-almonds, en:nu...</td>\n",
  1142. " </tr>\n",
  1143. " <tr>\n",
  1144. " <th>254368</th>\n",
  1145. " <td>Mleko wiejskie</td>\n",
  1146. " <td>(en:dairies, en:milks)</td>\n",
  1147. " </tr>\n",
  1148. " <tr>\n",
  1149. " <th>254369</th>\n",
  1150. " <td>Poireaux</td>\n",
  1151. " <td>(en:fruits-and-vegetables-based-foods, en:leek...</td>\n",
  1152. " </tr>\n",
  1153. " <tr>\n",
  1154. " <th>254370</th>\n",
  1155. " <td>Cheese cake thé vert, yuzu</td>\n",
  1156. " <td>()</td>\n",
  1157. " </tr>\n",
  1158. " <tr>\n",
  1159. " <th>254371</th>\n",
  1160. " <td>Tomato &amp; ricotta</td>\n",
  1161. " <td>()</td>\n",
  1162. " </tr>\n",
  1163. " <tr>\n",
  1164. " <th>254372</th>\n",
  1165. " <td>Mint Melange Tea A Blend Of Peppermint, Lemon ...</td>\n",
  1166. " <td>(en:beverages, en:non-sugared-beverages, en:su...</td>\n",
  1167. " </tr>\n",
  1168. " <tr>\n",
  1169. " <th>254373</th>\n",
  1170. " <td>Biscottes bio</td>\n",
  1171. " <td>(en:breads, en:cereals-and-potatoes, en:plant-...</td>\n",
  1172. " </tr>\n",
  1173. " <tr>\n",
  1174. " <th>254374</th>\n",
  1175. " <td>Tomates aux Vermicelles</td>\n",
  1176. " <td>(en:fruits-and-vegetables-based-foods, en:meal...</td>\n",
  1177. " </tr>\n",
  1178. " <tr>\n",
  1179. " <th>254375</th>\n",
  1180. " <td>Sugar Free Drink Mix, Peach Tea</td>\n",
  1181. " <td>(en:artificially-sweetened-beverages, en:bever...</td>\n",
  1182. " </tr>\n",
  1183. " </tbody>\n",
  1184. "</table>\n",
  1185. "<p>254376 rows × 2 columns</p>\n",
  1186. "</div>"
  1187. ],
  1188. "text/plain": [
  1189. " product_name \\\n",
  1190. "0 Farine de blé noir \n",
  1191. "1 Banana Chips Sweetened (Whole) \n",
  1192. "2 Peanuts \n",
  1193. "3 Organic Salted Nut Mix \n",
  1194. "4 Organic Polenta \n",
  1195. "5 Breadshop Honey Gone Nuts Granola \n",
  1196. "6 Organic Long Grain White Rice \n",
  1197. "7 Organic Muesli \n",
  1198. "8 Organic Dark Chocolate Minis \n",
  1199. "9 Organic Sunflower Oil \n",
  1200. "10 Organic Adzuki Beans \n",
  1201. "11 Organic Penne Pasta \n",
  1202. "12 Zen Party Mix \n",
  1203. "13 Organic Golden Flax Seeds \n",
  1204. "14 Organic Spicy Punks \n",
  1205. "15 Cinnamon Nut Granola \n",
  1206. "16 Organic Hazelnuts \n",
  1207. "17 Organic Sweetened Banana Chips \n",
  1208. "18 Lotus Organic Brown Jasmine Rice \n",
  1209. "19 Organic Oat Groats \n",
  1210. "20 Energy Power Mix \n",
  1211. "21 Antioxidant Mix - Berries & Chocolate \n",
  1212. "22 Organic Quinoa Coconut Granola With Mango \n",
  1213. "23 Fire Roasted Hatch Green Chile Almonds \n",
  1214. "24 Peanut Butter Power Chews \n",
  1215. "25 Real Salt Granular \n",
  1216. "26 Organic Unswt Berry Coconut Granola \n",
  1217. "27 Roasted Salted Black Pepper Cashews \n",
  1218. "28 Thai Curry Roasted Cashews \n",
  1219. "29 Wasabi Tamari Almonds \n",
  1220. "... ... \n",
  1221. "254346 Fairy Tail \n",
  1222. "254347 Biscuits aux céréales, aux pépites de chocolat... \n",
  1223. "254348 Neszt Cochon Con \n",
  1224. "254349 nan \n",
  1225. "254350 Drid apricot the queen \n",
  1226. "254351 Natural Cassava \n",
  1227. "254352 nan \n",
  1228. "254353 nan \n",
  1229. "254354 Soda 1 \n",
  1230. "254355 Merci 1 \n",
  1231. "254356 Merci2 \n",
  1232. "254357 Merci3 \n",
  1233. "254358 Libro parachute3 \n",
  1234. "254359 nan \n",
  1235. "254360 Vegan easy \n",
  1236. "254361 Tarifs djoghrafia \n",
  1237. "254362 nan \n",
  1238. "254363 Ferrero Rocher \n",
  1239. "254364 nan \n",
  1240. "254365 Raspados Ice Bars \n",
  1241. "254366 nf test \n",
  1242. "254367 Amandes \n",
  1243. "254368 Mleko wiejskie \n",
  1244. "254369 Poireaux \n",
  1245. "254370 Cheese cake thé vert, yuzu \n",
  1246. "254371 Tomato & ricotta \n",
  1247. "254372 Mint Melange Tea A Blend Of Peppermint, Lemon ... \n",
  1248. "254373 Biscottes bio \n",
  1249. "254374 Tomates aux Vermicelles \n",
  1250. "254375 Sugar Free Drink Mix, Peach Tea \n",
  1251. "\n",
  1252. " guessed_labels \n",
  1253. "0 (en:cereal-flours, en:cereals-and-potatoes, en... \n",
  1254. "1 () \n",
  1255. "2 (en:legumes, en:legumes-and-their-products, en... \n",
  1256. "3 () \n",
  1257. "4 (en:cereals-and-potatoes, en:cereals-and-their... \n",
  1258. "5 (en:breakfasts, en:sugary-snacks) \n",
  1259. "6 (en:cereal-grains, en:cereals-and-potatoes, en... \n",
  1260. "7 (en:breakfast-cereals, en:breakfasts, en:cerea... \n",
  1261. "8 (en:chocolates, en:dark-chocolates, en:sugary-... \n",
  1262. "9 (en:fats, en:plant-based-foods, en:plant-based... \n",
  1263. "10 (en:legumes-and-their-products, en:plant-based... \n",
  1264. "11 (en:cereals-and-potatoes, en:cereals-and-their... \n",
  1265. "12 () \n",
  1266. "13 (en:plant-based-foods, en:plant-based-foods-an... \n",
  1267. "14 () \n",
  1268. "15 (en:breakfast-cereals, en:breakfasts, en:cerea... \n",
  1269. "16 () \n",
  1270. "17 () \n",
  1271. "18 (en:cereal-grains, en:cereals-and-their-produc... \n",
  1272. "19 () \n",
  1273. "20 () \n",
  1274. "21 (en:plant-based-foods-and-beverages,) \n",
  1275. "22 (en:plant-based-foods, en:plant-based-foods-an... \n",
  1276. "23 () \n",
  1277. "24 (en:plant-based-foods,) \n",
  1278. "25 (en:chips-and-fries, en:crisps, en:groceries, ... \n",
  1279. "26 (en:plant-based-foods, en:plant-based-foods-an... \n",
  1280. "27 (en:cashew-nuts, en:nuts, en:plant-based-foods... \n",
  1281. "28 (en:cashew-nuts, en:plant-based-foods, en:plan... \n",
  1282. "29 (en:condiments, en:groceries, en:plant-based-f... \n",
  1283. "... ... \n",
  1284. "254346 () \n",
  1285. "254347 (en:biscuits, en:biscuits-and-cakes, en:sugary... \n",
  1286. "254348 () \n",
  1287. "254349 () \n",
  1288. "254350 (en:beverages,) \n",
  1289. "254351 (en:plant-based-foods-and-beverages,) \n",
  1290. "254352 () \n",
  1291. "254353 () \n",
  1292. "254354 (en:beverages, en:carbonated-drinks, en:sodas,... \n",
  1293. "254355 (en:bonbons, en:candies, en:chocolates, en:cho... \n",
  1294. "254356 () \n",
  1295. "254357 () \n",
  1296. "254358 () \n",
  1297. "254359 () \n",
  1298. "254360 (en:plant-based-foods, en:plant-based-foods-an... \n",
  1299. "254361 () \n",
  1300. "254362 () \n",
  1301. "254363 (en:chocolates, en:sugary-snacks) \n",
  1302. "254364 () \n",
  1303. "254365 (en:bars, en:cereal-bars, en:sugary-snacks) \n",
  1304. "254366 (en:beverages,) \n",
  1305. "254367 (en:almonds, en:chocolates-with-almonds, en:nu... \n",
  1306. "254368 (en:dairies, en:milks) \n",
  1307. "254369 (en:fruits-and-vegetables-based-foods, en:leek... \n",
  1308. "254370 () \n",
  1309. "254371 () \n",
  1310. "254372 (en:beverages, en:non-sugared-beverages, en:su... \n",
  1311. "254373 (en:breads, en:cereals-and-potatoes, en:plant-... \n",
  1312. "254374 (en:fruits-and-vegetables-based-foods, en:meal... \n",
  1313. "254375 (en:artificially-sweetened-beverages, en:bever... \n",
  1314. "\n",
  1315. "[254376 rows x 2 columns]"
  1316. ]
  1317. },
  1318. "execution_count": 33,
  1319. "metadata": {},
  1320. "output_type": "execute_result"
  1321. }
  1322. ],
  1323. "source": [
  1324. "prediction_dataframe = pandas.DataFrame({\n",
  1325. " 'product_name': products_without_categories['product_name'].values.astype('U'),\n",
  1326. " 'guessed_labels': all_labels\n",
  1327. "}, columns=['product_name', 'guessed_labels'])\n",
  1328. "prediction_dataframe.to_csv('prediction.csv', index=False)\n",
  1329. "prediction_dataframe"
  1330. ]
  1331. },
  1332. {
  1333. "cell_type": "markdown",
  1334. "metadata": {},
  1335. "source": [
  1336. "## Port to JS"
  1337. ]
  1338. },
  1339. {
  1340. "cell_type": "code",
  1341. "execution_count": 3,
  1342. "metadata": {},
  1343. "outputs": [],
  1344. "source": [
  1345. "from sklearn_porter import Porter"
  1346. ]
  1347. },
  1348. {
  1349. "cell_type": "code",
  1350. "execution_count": 4,
  1351. "metadata": {},
  1352. "outputs": [],
  1353. "source": [
  1354. "# Load the classifier\n",
  1355. "mlb, classifier = joblib.load('offClassifier.pkl')"
  1356. ]
  1357. },
  1358. {
  1359. "cell_type": "code",
  1360. "execution_count": 5,
  1361. "metadata": {},
  1362. "outputs": [
  1363. {
  1364. "ename": "ValueError",
  1365. "evalue": "The given model 'Pipeline(memory=None,\n steps=[('vectorizer', CountVectorizer(analyzer='word', binary=False, decode_error='strict',\n dtype=<class 'numpy.int64'>, encoding='utf-8', input='content',\n lowercase=True, max_df=1.0, max_features=None, min_df=1,\n ngram_range=(1, 1), preprocessor=None, stop_words=None,\n ...lti_class='ovr', penalty='l2', random_state=None, tol=0.0001,\n verbose=0),\n n_jobs=1))])' isn't supported.",
  1366. "output_type": "error",
  1367. "traceback": [
  1368. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  1369. "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
  1370. "\u001b[0;32m<ipython-input-5-4f2b5247caa7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mporter\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mPorter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mclassifier\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlanguage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'javascript'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mporter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexport\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1371. "\u001b[0;32m~/.local/share/virtualenvs/machine_learning/lib/python3.6/site-packages/sklearn_porter/Porter.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, model, language, method, **kwargs)\u001b[0m\n\u001b[1;32m 75\u001b[0m \u001b[0merror\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"The given model '{model}' isn't\"\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0;34m\" supported.\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__dict__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 77\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merror\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 78\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;31m# Import model class:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  1372. "\u001b[0;31mValueError\u001b[0m: The given model 'Pipeline(memory=None,\n steps=[('vectorizer', CountVectorizer(analyzer='word', binary=False, decode_error='strict',\n dtype=<class 'numpy.int64'>, encoding='utf-8', input='content',\n lowercase=True, max_df=1.0, max_features=None, min_df=1,\n ngram_range=(1, 1), preprocessor=None, stop_words=None,\n ...lti_class='ovr', penalty='l2', random_state=None, tol=0.0001,\n verbose=0),\n n_jobs=1))])' isn't supported."
  1373. ]
  1374. }
  1375. ],
  1376. "source": [
  1377. "porter = Porter(classifier, language='javascript')\n",
  1378. "output = porter.export()"
  1379. ]
  1380. },
  1381. {
  1382. "cell_type": "code",
  1383. "execution_count": 8,
  1384. "metadata": {},
  1385. "outputs": [
  1386. {
  1387. "name": "stdout",
  1388. "output_type": "stream",
  1389. "text": [
  1390. "Pipeline\n"
  1391. ]
  1392. }
  1393. ],
  1394. "source": [
  1395. "algorithm_name = str(type(classifier).__name__)\n",
  1396. "print(algorithm_name)"
  1397. ]
  1398. },
  1399. {
  1400. "cell_type": "code",
  1401. "execution_count": null,
  1402. "metadata": {},
  1403. "outputs": [],
  1404. "source": []
  1405. }
  1406. ],
  1407. "metadata": {
  1408. "kernelspec": {
  1409. "display_name": "Python 3",
  1410. "language": "python",
  1411. "name": "python3"
  1412. },
  1413. "language_info": {
  1414. "codemirror_mode": {
  1415. "name": "ipython",
  1416. "version": 3
  1417. },
  1418. "file_extension": ".py",
  1419. "mimetype": "text/x-python",
  1420. "name": "python",
  1421. "nbconvert_exporter": "python",
  1422. "pygments_lexer": "ipython3",
  1423. "version": "3.6.1"
  1424. }
  1425. },
  1426. "nbformat": 4,
  1427. "nbformat_minor": 2
  1428. }