{
  "id": 308751,
  "title": "visualize prediction article",
  "url": "/competitions/h-and-m-personalized-fashion-recommendations/discussion/308751",
  "author_name": "shigeeeru",
  "post_date": "2022-02-20T05:39:30.092000",
  "votes": 5,
  "comment_count": 0,
  "views": 0,
  "content": "<p>Before submit Prediction, I create List like this .<br>\n`</p>\n<blockquote>\n  <p>article_list = ['0924243002',<br>\n   '0751471001',<br>\n   '0448509014',<br>\n   '0918522001',<br>\n   '0866731001',<br>\n   '0714790020',<br>\n   '0788575004',<br>\n   '0915529005',<br>\n   '0573085028',<br>\n   '0918292001',<br>\n   '0850917001',<br>\n   '0928206001']</p>\n</blockquote>\n<p>And convert Prediction format.<br>\n<code>\" \".join(article_list)</code></p>\n<p>But it is not useful to analyze prediction results.</p>\n<p>So I create Visualizing prediction article Code.</p>\n<h1>prepare image_DataFrame</h1>\n<pre><code>images_names = []\nfor _, _, files in tqdm(os.walk('/kaggle/input/h-and-m-personalized-fashion-recommendations/')):\n    for _files in files:\n        if len(_files.split(\".jpg\"))==2:\n            images_names.append(_files.split(\".jpg\")[0])\nimage_name_df = pd.DataFrame(images_names, columns = [\"image_name\"])\nimage_name_df[\"article_id\"] = image_name_df[\"image_name\"].apply(lambda x: int(x[1:]))\n</code></pre>\n<h1>Visualizing Code</h1>\n<pre><code>def plot_image_art_list(art_list, cols=4, rows=3):\n    image_path = \"/kaggle/input/h-and-m-personalized-fashion-recommendations/images/\"\n    plt.figure(figsize=(2 + 3 * cols, 2 + 4 * rows))\n    for i, article_id in enumerate(art_list):\n        _id = image_article_df.loc[image_article_df.image_name==article_id]\n        _id = list(_id.index)[0]\n        product_group_name = image_article_df.iat[_id, 2]\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{product_group_name} {article_id[:3]}\\n{article_id}.jpg\")\n        try:\n            image = Image.open(f\"{image_path}{article_id[:3]}/{article_id}.jpg\")\n        except FileNotFoundError:\n            print('!!! FileNotFoundError !!!')\n            continue\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{article_id[:3]}\\n{article_id}.jpg\")\n        plt.imshow(image)\n</code></pre>",
  "messages": [
    {
      "id": 1698060,
      "postDate": "2022-02-20T05:39:30.093Z",
      "content": "<p>Before submit Prediction, I create List like this .<br>\n`</p>\n<blockquote>\n  <p>article_list = ['0924243002',<br>\n   '0751471001',<br>\n   '0448509014',<br>\n   '0918522001',<br>\n   '0866731001',<br>\n   '0714790020',<br>\n   '0788575004',<br>\n   '0915529005',<br>\n   '0573085028',<br>\n   '0918292001',<br>\n   '0850917001',<br>\n   '0928206001']</p>\n</blockquote>\n<p>And convert Prediction format.<br>\n<code>\" \".join(article_list)</code></p>\n<p>But it is not useful to analyze prediction results.</p>\n<p>So I create Visualizing prediction article Code.</p>\n<h1>prepare image_DataFrame</h1>\n<pre><code>images_names = []\nfor _, _, files in tqdm(os.walk('/kaggle/input/h-and-m-personalized-fashion-recommendations/')):\n    for _files in files:\n        if len(_files.split(\".jpg\"))==2:\n            images_names.append(_files.split(\".jpg\")[0])\nimage_name_df = pd.DataFrame(images_names, columns = [\"image_name\"])\nimage_name_df[\"article_id\"] = image_name_df[\"image_name\"].apply(lambda x: int(x[1:]))\n</code></pre>\n<h1>Visualizing Code</h1>\n<pre><code>def plot_image_art_list(art_list, cols=4, rows=3):\n    image_path = \"/kaggle/input/h-and-m-personalized-fashion-recommendations/images/\"\n    plt.figure(figsize=(2 + 3 * cols, 2 + 4 * rows))\n    for i, article_id in enumerate(art_list):\n        _id = image_article_df.loc[image_article_df.image_name==article_id]\n        _id = list(_id.index)[0]\n        product_group_name = image_article_df.iat[_id, 2]\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{product_group_name} {article_id[:3]}\\n{article_id}.jpg\")\n        try:\n            image = Image.open(f\"{image_path}{article_id[:3]}/{article_id}.jpg\")\n        except FileNotFoundError:\n            print('!!! FileNotFoundError !!!')\n            continue\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{article_id[:3]}\\n{article_id}.jpg\")\n        plt.imshow(image)\n</code></pre>",
      "rawMarkdown": "Before submit Prediction, I create List like this .\n`\n> article_list = ['0924243002',\n '0751471001',\n '0448509014',\n '0918522001',\n '0866731001',\n '0714790020',\n '0788575004',\n '0915529005',\n '0573085028',\n '0918292001',\n '0850917001',\n '0928206001']\n\n\nAnd convert Prediction format.\n`\" \".join(article_list)`\n\nBut it is not useful to analyze prediction results.\n\nSo I create Visualizing prediction article Code.\n\n# prepare image_DataFrame\n```\nimages_names = []\nfor _, _, files in tqdm(os.walk('/kaggle/input/h-and-m-personalized-fashion-recommendations/')):\n    for _files in files:\n        if len(_files.split(\".jpg\"))==2:\n            images_names.append(_files.split(\".jpg\")[0])\nimage_name_df = pd.DataFrame(images_names, columns = [\"image_name\"])\nimage_name_df[\"article_id\"] = image_name_df[\"image_name\"].apply(lambda x: int(x[1:]))\n\n```\n# Visualizing Code\n```\ndef plot_image_art_list(art_list, cols=4, rows=3):\n    image_path = \"/kaggle/input/h-and-m-personalized-fashion-recommendations/images/\"\n    plt.figure(figsize=(2 + 3 * cols, 2 + 4 * rows))\n    for i, article_id in enumerate(art_list):\n        _id = image_article_df.loc[image_article_df.image_name==article_id]\n        _id = list(_id.index)[0]\n        product_group_name = image_article_df.iat[_id, 2]\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{product_group_name} {article_id[:3]}\\n{article_id}.jpg\")\n        try:\n            image = Image.open(f\"{image_path}{article_id[:3]}/{article_id}.jpg\")\n        except FileNotFoundError:\n            print('!!! FileNotFoundError !!!')\n            continue\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{article_id[:3]}\\n{article_id}.jpg\")\n        plt.imshow(image)\n\n```\n",
      "votes": 5
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1698060": "Before submit Prediction, I create List like this .\n`\n> article_list = ['0924243002',\n '0751471001',\n '0448509014',\n '0918522001',\n '0866731001',\n '0714790020',\n '0788575004',\n '0915529005',\n '0573085028',\n '0918292001',\n '0850917001',\n '0928206001']\n\n\nAnd convert Prediction format.\n`\" \".join(article_list)`\n\nBut it is not useful to analyze prediction results.\n\nSo I create Visualizing prediction article Code.\n\n# prepare image_DataFrame\n```\nimages_names = []\nfor _, _, files in tqdm(os.walk('/kaggle/input/h-and-m-personalized-fashion-recommendations/')):\n    for _files in files:\n        if len(_files.split(\".jpg\"))==2:\n            images_names.append(_files.split(\".jpg\")[0])\nimage_name_df = pd.DataFrame(images_names, columns = [\"image_name\"])\nimage_name_df[\"article_id\"] = image_name_df[\"image_name\"].apply(lambda x: int(x[1:]))\n\n```\n# Visualizing Code\n```\ndef plot_image_art_list(art_list, cols=4, rows=3):\n    image_path = \"/kaggle/input/h-and-m-personalized-fashion-recommendations/images/\"\n    plt.figure(figsize=(2 + 3 * cols, 2 + 4 * rows))\n    for i, article_id in enumerate(art_list):\n        _id = image_article_df.loc[image_article_df.image_name==article_id]\n        _id = list(_id.index)[0]\n        product_group_name = image_article_df.iat[_id, 2]\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{product_group_name} {article_id[:3]}\\n{article_id}.jpg\")\n        try:\n            image = Image.open(f\"{image_path}{article_id[:3]}/{article_id}.jpg\")\n        except FileNotFoundError:\n            print('!!! FileNotFoundError !!!')\n            continue\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{article_id[:3]}\\n{article_id}.jpg\")\n        plt.imshow(image)\n\n```\n"
  }
}