{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":31254,"databundleVersionId":3103714,"sourceType":"competition"}],"dockerImageVersionId":31239,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-01-09T14:52:04.146646Z","iopub.execute_input":"2026-01-09T14:52:04.146869Z","iopub.status.idle":"2026-01-09T14:52:06.563295Z","shell.execute_reply.started":"2026-01-09T14:52:04.146849Z","shell.execute_reply":"2026-01-09T14:52:06.562194Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"trans_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\nitem_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')\nuser_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T15:46:23.903721Z","iopub.execute_input":"2026-01-09T15:46:23.904041Z","iopub.status.idle":"2026-01-09T15:47:20.387223Z","shell.execute_reply.started":"2026-01-09T15:46:23.904017Z","shell.execute_reply":"2026-01-09T15:47:20.384945Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Chuyển cột ngày sang datetime\ntrans_df['t_dat'] = pd.to_datetime(trans_df['t_dat'])\n\n# Lọc dữ liệu năm 2019\ntrans_df['year'] = trans_df['t_dat'].dt.year\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:20:33.697069Z","iopub.execute_input":"2026-01-09T16:20:33.697798Z","iopub.status.idle":"2026-01-09T16:20:38.265804Z","shell.execute_reply.started":"2026-01-09T16:20:33.697764Z","shell.execute_reply":"2026-01-09T16:20:38.264765Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"FEMALE_GROUPS = [\n    'Womens Everyday Basics', 'Womens Lingerie',\n    'Womens Nightwear, Socks & Tigh', 'Mama',\n    'Womens Small accessories', 'Womens Big accessories',\n    'Womens Swimwear, beachwear', 'Womens Everyday Collection',\n    'H&M+', 'Ladies Denim', 'Womens Trend',\n    'Young Girl', 'Womens Shoes', 'Womens Tailoring',\n    'Womens Jackets', 'Womens Casual', 'Ladies H&M Sport',\n    'Baby Girl', 'Kids Girl', 'Womens Premium',\n    'Ladies Other', 'Girls Underwear & Basics'\n]\n\nMALE_GROUPS = [\n    'Men Underwear', 'Men H&M Sport', 'Kids Boy',\n    'Mens Outerwear', 'Men Accessories', 'Men Suits & Tailoring',\n    'Men Shoes', 'Young Boy', 'Denim Men',\n    'Men Other', 'Men Other 2', 'Baby Boy',\n    'Men Project', 'Men Edition', 'Kids Boy', 'Boys Underwear & Basics'\n]\n\nFEMALE_ONLY_ITEMS = {\n    'Vest top', 'Bra', 'Underwear Tights', 'Leggings/Tights',\n    'Top', 'Pyjama jumpsuit/playsuit', 'Bodysuit',\n    'Bikini top', 'Swimwear bottom', 'Swimsuit',\n    'Skirt', 'Dress', 'Cardigan', 'Jumpsuit/Playsuit',\n    'Robe', 'Blouse', 'Underwear body', 'Swimwear set',\n    'Swimwear top', 'Wedge', 'Pumps', 'Heeled sandals',\n    'Nipple covers', 'Underwear corset', 'Bra extender',\n    'Underdress', 'Underwear set', 'Sarong', 'Leg warmers',\n    'Ballerinas', 'Flat shoe'\n}\n\nFEMALE_DOMINANT_ACCESSORIES = {\n    'Earring', 'Earrings', 'Necklace',\n    'Hair clip', 'Hair string', 'Hair/alice band',\n    'Hair ties', 'Hairband', 'Headband'\n}\n\nMALE_ONLY_ITEMS = {\n    'Shirt', 'Polo shirt', 'Tie', 'Tailored Waistcoat',\n    'Braces', 'Outdoor Waistcoat', 'Long John', 'Blazer'\n}\n\ndef set_gender_flg(x):\n    x[\"article_gender\"] = 0  # * 0 for not divided, 1 for male, 2 for female\n    if x['index_group_name'] == 'Ladieswear' or x[\"section_name\"] in FEMALE_GROUPS:\n        x[\"article_gender\"] = 2\n    elif x['index_group_name'] == 'Menswear' or x[\"section_name\"] in MALE_GROUPS:\n        x[\"article_gender\"] = 1\n    elif x[\"product_type_name\"] in FEMALE_ONLY_ITEMS:\n        x[\"article_gender\"] = 2\n    elif x[\"product_type_name\"] in FEMALE_DOMINANT_ACCESSORIES:\n        x[\"article_gender\"] = 2 \n    elif x[\"product_type_name\"] in MALE_ONLY_ITEMS:\n        x[\"article_gender\"] = 1\n    return x","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T15:57:02.530358Z","iopub.execute_input":"2026-01-09T15:57:02.530823Z","iopub.status.idle":"2026-01-09T15:57:02.542687Z","shell.execute_reply.started":"2026-01-09T15:57:02.530787Z","shell.execute_reply":"2026-01-09T15:57:02.541588Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_df.columns.tolist()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T15:57:05.304783Z","iopub.execute_input":"2026-01-09T15:57:05.305264Z","iopub.status.idle":"2026-01-09T15:57:05.313215Z","shell.execute_reply.started":"2026-01-09T15:57:05.305231Z","shell.execute_reply":"2026-01-09T15:57:05.312311Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_df['article_gender'] = 0  # 0: unisex / not divided\n\n# Female\nfemale_mask = (\n    (item_df['index_group_name'] == 'Ladieswear') |\n    (item_df['section_name'].isin(item_df)) |\n    (item_df['product_type_name'].isin(item_df))\n)\n\n# Male\nmale_mask = (\n    (item_df['index_group_name'] == 'Menswear') |\n    (item_df['section_name'].isin(MALE_GROUPS)) |\n    (item_df['product_type_name'].isin(MALE_ONLY_ITEMS))\n)\n\nitem_df.loc[female_mask, 'article_gender'] = 2\nitem_df.loc[male_mask, 'article_gender'] = 1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T15:57:09.241866Z","iopub.execute_input":"2026-01-09T15:57:09.242186Z","iopub.status.idle":"2026-01-09T15:57:09.291960Z","shell.execute_reply.started":"2026-01-09T15:57:09.242159Z","shell.execute_reply":"2026-01-09T15:57:09.290689Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Count gender distribution\ngender_counts = item_df['article_gender'].value_counts().sort_index()\n\n# Plot\nplt.figure()\nplt.bar(gender_counts.index.astype(str), gender_counts.values)\nplt.xlabel(\"Article Gender (0: Unisex, 1: Male, 2: Female)\")\nplt.ylabel(\"Number of Articles\")\nplt.title(\"Distribution of Article Gender\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T15:57:13.573259Z","iopub.execute_input":"2026-01-09T15:57:13.574736Z","iopub.status.idle":"2026-01-09T15:57:13.770117Z","shell.execute_reply.started":"2026-01-09T15:57:13.574681Z","shell.execute_reply":"2026-01-09T15:57:13.769004Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"trans_gender = trans_df.merge(item_df[['article_id', 'article_gender']], on='article_id', how='left')\ngender_counts_trans = trans_gender['article_gender'].value_counts().sort_index()\n\n# Plot\nplt.figure()\nplt.bar(gender_counts_trans.index.astype(str), gender_counts.values)\nplt.xlabel(\"Article Gender (0: Unisex, 1: Male, 2: Female)\")\nplt.ylabel(\"Number of Articles\")\nplt.title(\"Distribution of Article Gender\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T15:57:21.123028Z","iopub.execute_input":"2026-01-09T15:57:21.125151Z","iopub.status.idle":"2026-01-09T15:57:30.077127Z","shell.execute_reply.started":"2026-01-09T15:57:21.125112Z","shell.execute_reply":"2026-01-09T15:57:30.075702Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"user_gender_cnt = (\n    trans_gender\n    .groupby(['customer_id', 'article_gender'])\n    .size()\n    .unstack(fill_value=0)\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:07:38.284694Z","iopub.execute_input":"2026-01-09T16:07:38.285662Z","iopub.status.idle":"2026-01-09T16:07:54.624021Z","shell.execute_reply.started":"2026-01-09T16:07:38.285625Z","shell.execute_reply":"2026-01-09T16:07:54.622921Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"user_gender_cnt['male_female_ratio'] = (\n    user_gender_cnt.get(1, 0) /\n    (user_gender_cnt.get(2, 0) + 1e-6)\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:08:27.213789Z","iopub.execute_input":"2026-01-09T16:08:27.214079Z","iopub.status.idle":"2026-01-09T16:08:27.227866Z","shell.execute_reply.started":"2026-01-09T16:08:27.214058Z","shell.execute_reply":"2026-01-09T16:08:27.226949Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"total_gender_items = (\n    user_gender_cnt.get(1, 0) +\n    user_gender_cnt.get(2, 0)\n)\n\nuser_gender_cnt['male_ratio'] = (\n    user_gender_cnt.get(1, 0) / (total_gender_items + 1e-6)\n)\n\nuser_gender_cnt['female_ratio'] = (\n    user_gender_cnt.get(2, 0) / (total_gender_items + 1e-6)\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:08:35.845225Z","iopub.execute_input":"2026-01-09T16:08:35.845588Z","iopub.status.idle":"2026-01-09T16:08:35.871010Z","shell.execute_reply.started":"2026-01-09T16:08:35.845560Z","shell.execute_reply":"2026-01-09T16:08:35.869635Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def user_gender_type(row):\n    if row['male_ratio'] > 0.7:\n        return 1\n    elif row['female_ratio'] > 0.7:\n        return 2\n    else:\n        return 0\n\nuser_gender_cnt['user_gender_type'] = user_gender_cnt.apply(\n    user_gender_type, axis=1\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:08:49.882296Z","iopub.execute_input":"2026-01-09T16:08:49.882683Z","iopub.status.idle":"2026-01-09T16:09:00.080381Z","shell.execute_reply.started":"2026-01-09T16:08:49.882657Z","shell.execute_reply":"2026-01-09T16:09:00.079605Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure()\nplt.hist(user_gender_cnt['male_ratio'], bins=50)\nplt.xlabel('Male Purchase Ratio')\nplt.ylabel('Number of Users')\nplt.title('Distribution of Male Purchase Ratio per User')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:09:00.081950Z","iopub.execute_input":"2026-01-09T16:09:00.082265Z","iopub.status.idle":"2026-01-09T16:09:00.374047Z","shell.execute_reply.started":"2026-01-09T16:09:00.082235Z","shell.execute_reply":"2026-01-09T16:09:00.372998Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"trans_2019 = trans_df[trans_df['t_dat'].dt.year == 2019]\n\nitem_avg_price_2019 = (\n    trans_2019\n    .groupby('article_id')['price']\n    .mean()\n    .reset_index()\n    .rename(columns={'price': 'avg_price_2019'})\n)\n\nitem_df = item_df.merge(\n    item_avg_price_2019,\n    on='article_id',\n    how='left'\n)\n\ndef get_season(month):\n    if month in [3, 4, 5]:\n        return 'spring'\n    elif month in [6, 7, 8]:\n        return 'summer'\n    elif month in [9, 10, 11]:\n        return 'fall'\n    else:\n        return 'winter'\n\ntrans_2019['season'] = trans_2019['t_dat'].dt.month.apply(get_season)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:20:57.081648Z","iopub.execute_input":"2026-01-09T16:20:57.081989Z","iopub.status.idle":"2026-01-09T16:21:04.323911Z","shell.execute_reply.started":"2026-01-09T16:20:57.081962Z","shell.execute_reply":"2026-01-09T16:21:04.322966Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_year_cnt = (\n    trans_2019\n    .groupby('article_id')\n    .size()\n    .reset_index(name='year_cnt')\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:24:10.610406Z","iopub.execute_input":"2026-01-09T16:24:10.610792Z","iopub.status.idle":"2026-01-09T16:24:11.191889Z","shell.execute_reply.started":"2026-01-09T16:24:10.610764Z","shell.execute_reply":"2026-01-09T16:24:11.190726Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_season_cnt = (\n    trans_2019\n    .groupby(['article_id', 'season'])\n    .size()\n    .reset_index(name='season_cnt')\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:24:50.314982Z","iopub.execute_input":"2026-01-09T16:24:50.315362Z","iopub.status.idle":"2026-01-09T16:24:52.663277Z","shell.execute_reply.started":"2026-01-09T16:24:50.315315Z","shell.execute_reply":"2026-01-09T16:24:52.662275Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_year_cnt['avg_season_cnt'] = item_year_cnt['year_cnt'] / 4\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:25:02.131034Z","iopub.execute_input":"2026-01-09T16:25:02.131365Z","iopub.status.idle":"2026-01-09T16:25:02.137841Z","shell.execute_reply.started":"2026-01-09T16:25:02.131315Z","shell.execute_reply":"2026-01-09T16:25:02.136822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_season_freq = item_season_cnt.merge(\n    item_year_cnt[['article_id', 'avg_season_cnt']],\n    on='article_id',\n    how='left'\n)\n\nitem_season_freq['season_freq_ratio'] = (\n    item_season_freq['season_cnt'] /\n    (item_season_freq['avg_season_cnt'] + 1e-6)\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:25:03.627649Z","iopub.execute_input":"2026-01-09T16:25:03.627961Z","iopub.status.idle":"2026-01-09T16:25:03.677251Z","shell.execute_reply.started":"2026-01-09T16:25:03.627936Z","shell.execute_reply":"2026-01-09T16:25:03.676431Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"item_season_ratio_pivot = (\n    item_season_freq\n    .pivot(index='article_id', columns='season', values='season_freq_ratio')\n    .add_prefix('season_ratio_')\n    .reset_index()\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:25:05.826055Z","iopub.execute_input":"2026-01-09T16:25:05.826389Z","iopub.status.idle":"2026-01-09T16:25:05.877986Z","shell.execute_reply.started":"2026-01-09T16:25:05.826365Z","shell.execute_reply":"2026-01-09T16:25:05.877171Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Assume item_season_freq already exists with column 'season_freq_ratio'\nseasons = item_season_freq['season'].unique()\n\nfor season in seasons:\n    data = item_season_freq.loc[\n        item_season_freq['season'] == season, 'season_freq_ratio'\n    ]\n\n    plt.figure()\n    plt.hist(data, bins=50)\n    plt.xlabel('Season Frequency Ratio')\n    plt.ylabel('Number of Items')\n    plt.title(f'Distribution of Season Frequency Ratio - {season.capitalize()}')\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:25:31.147633Z","iopub.execute_input":"2026-01-09T16:25:31.148029Z","iopub.status.idle":"2026-01-09T16:25:32.187730Z","shell.execute_reply.started":"2026-01-09T16:25:31.148001Z","shell.execute_reply":"2026-01-09T16:25:32.186838Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"winter_strong_items = item_season_freq.loc[\n    (item_season_freq['season'] == 'winter') &\n    (item_season_freq['season_freq_ratio'] > 1.2),\n    'article_id'\n].unique()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:29:50.932432Z","iopub.execute_input":"2026-01-09T16:29:50.933537Z","iopub.status.idle":"2026-01-09T16:29:50.958356Z","shell.execute_reply.started":"2026-01-09T16:29:50.933497Z","shell.execute_reply":"2026-01-09T16:29:50.957238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"winter_items_trans = trans_2019[\n    trans_2019['article_id'].isin(winter_strong_items)\n]\n\nwinter_item_season_cnt = (\n    winter_items_trans\n    .groupby(['article_id', 'season'])\n    .size()\n    .reset_index(name='season_cnt')\n)\n\nwinter_item_year_cnt = (\n    winter_items_trans\n    .groupby('article_id')\n    .size()\n    .reset_index(name='year_cnt')\n)\n\nwinter_item_season_ratio = winter_item_season_cnt.merge(\n    winter_item_year_cnt,\n    on='article_id',\n    how='left'\n)\n\nwinter_item_season_ratio['season_purchase_ratio'] = (\n    winter_item_season_ratio['season_cnt'] /\n    winter_item_season_ratio['year_cnt']\n)\n\navg_ratio_other_seasons = (\n    winter_item_season_ratio\n    .groupby('season')['season_purchase_ratio']\n    .mean()\n    .reset_index()\n)\n\nwinter_item_ratio_pivot = (\n    winter_item_season_ratio\n    .pivot_table(\n        index='article_id',\n        columns='season',\n        values='season_purchase_ratio'\n    )\n    .reset_index()\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:29:52.812950Z","iopub.execute_input":"2026-01-09T16:29:52.813233Z","iopub.status.idle":"2026-01-09T16:29:54.461173Z","shell.execute_reply.started":"2026-01-09T16:29:52.813213Z","shell.execute_reply":"2026-01-09T16:29:54.460273Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nfor season in ['fall', 'spring', 'summer']:\n    data = winter_item_season_ratio.loc[\n        winter_item_season_ratio['season'] == season,\n        'season_purchase_ratio'\n    ]\n\n    plt.figure()\n    plt.hist(data, bins=40)\n    plt.xlabel('Season Purchase Ratio')\n    plt.ylabel('Number of Items')\n    plt.title(\n        f'Purchase Ratio Distribution in {season.capitalize()} '\n        '(Winter-Strong Items)'\n    )\n    plt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:30:47.213186Z","iopub.execute_input":"2026-01-09T16:30:47.213521Z","iopub.status.idle":"2026-01-09T16:30:47.875992Z","shell.execute_reply.started":"2026-01-09T16:30:47.213495Z","shell.execute_reply":"2026-01-09T16:30:47.874884Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\ndef plot_other_seasons_distribution(\n    item_season_freq,\n    trans_2019,\n    target_season,\n    ratio_threshold=1.2,\n    min_year_cnt=10\n):\n    \"\"\"\n    Plot distribution of purchase ratios in other seasons\n    for items strong in a target season.\n    Output: one histogram per other season.\n    \"\"\"\n\n    # 1. Select strong items in target season\n    strong_items = item_season_freq.loc[\n        (item_season_freq['season'] == target_season) &\n        (item_season_freq['season_freq_ratio'] > ratio_threshold),\n        'article_id'\n    ].unique()\n\n    # 2. Filter transactions\n    strong_trans = trans_2019[\n        trans_2019['article_id'].isin(strong_items)\n    ]\n\n    # 3. Count purchases per item x season\n    item_season_cnt = (\n        strong_trans\n        .groupby(['article_id', 'season'])\n        .size()\n        .reset_index(name='season_cnt')\n    )\n\n    # 4. Count yearly purchases per item\n    item_year_cnt = (\n        strong_trans\n        .groupby('article_id')\n        .size()\n        .reset_index(name='year_cnt')\n    )\n\n    # 5. Filter low-frequency items\n    item_year_cnt = item_year_cnt[\n        item_year_cnt['year_cnt'] >= min_year_cnt\n    ]\n\n    item_season_cnt = item_season_cnt.merge(\n        item_year_cnt,\n        on='article_id',\n        how='inner'\n    )\n\n    # 6. Compute season purchase ratio\n    item_season_cnt['season_purchase_ratio'] = (\n        item_season_cnt['season_cnt'] /\n        item_season_cnt['year_cnt']\n    )\n\n    # 7. Plot distributions for other seasons\n    other_seasons = [\n        s for s in item_season_cnt['season'].unique()\n        if s != target_season\n    ]\n\n    for season in other_seasons:\n        data = item_season_cnt.loc[\n            item_season_cnt['season'] == season,\n            'season_purchase_ratio'\n        ]\n\n        plt.figure()\n        plt.hist(data, bins=40)\n        plt.xlabel('Season Purchase Ratio')\n        plt.ylabel('Number of Items')\n        plt.title(\n            f'{season.capitalize()} Distribution '\n            f'(Items strong in {target_season.capitalize()})'\n        )\n        plt.show()\n\n\n# Example usage:\nplot_other_seasons_distribution(\n    item_season_freq,\n    trans_2019,\n    target_season='winter',\n    ratio_threshold=1.2\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:38:40.177067Z","iopub.execute_input":"2026-01-09T16:38:40.177423Z","iopub.status.idle":"2026-01-09T16:38:42.704100Z","shell.execute_reply.started":"2026-01-09T16:38:40.177394Z","shell.execute_reply":"2026-01-09T16:38:42.703299Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plot_other_seasons_distribution(\n    item_season_freq,\n    trans_2019,\n    target_season='summer',\n    ratio_threshold=1.2\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:38:59.800274Z","iopub.execute_input":"2026-01-09T16:38:59.800710Z","iopub.status.idle":"2026-01-09T16:39:02.854547Z","shell.execute_reply.started":"2026-01-09T16:38:59.800682Z","shell.execute_reply":"2026-01-09T16:39:02.853634Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plot_other_seasons_distribution(\n    item_season_freq,\n    trans_2019,\n    target_season='spring',\n    ratio_threshold=1.2\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:39:18.660819Z","iopub.execute_input":"2026-01-09T16:39:18.661157Z","iopub.status.idle":"2026-01-09T16:39:21.451875Z","shell.execute_reply.started":"2026-01-09T16:39:18.661131Z","shell.execute_reply":"2026-01-09T16:39:21.450886Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plot_other_seasons_distribution(\n    item_season_freq,\n    trans_2019,\n    target_season='fall',\n    ratio_threshold=1.2\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-09T16:40:05.063243Z","iopub.execute_input":"2026-01-09T16:40:05.063594Z","iopub.status.idle":"2026-01-09T16:40:07.247759Z","shell.execute_reply.started":"2026-01-09T16:40:05.063571Z","shell.execute_reply":"2026-01-09T16:40:07.246765Z"}},"outputs":[],"execution_count":null}]}