{"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"sourceId":31254,"databundleVersionId":3103714,"sourceType":"competition"},{"sourceId":8037037,"sourceType":"datasetVersion","datasetId":4737926}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nimport plotly.express as px\nplt.rcParams['font.family'] = 'sans-serif'\nimport warnings\nwarnings.filterwarnings(\"ignore\")\nfrom wordcloud import WordCloud, STOPWORDS\n","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.status.busy":"2024-04-05T11:03:32.554471Z","iopub.execute_input":"2024-04-05T11:03:32.556206Z","iopub.status.idle":"2024-04-05T11:03:37.517400Z","shell.execute_reply.started":"2024-04-05T11:03:32.556116Z","shell.execute_reply":"2024-04-05T11:03:37.514932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles=pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers=pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv\")\n#sample_submission=pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv\",nrows=1000)\ntransactions_train=pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")\n#display(articles.head(),customers.head(),sample_submission.head(),transactions_train.head())","metadata":{"execution":{"iopub.status.busy":"2024-04-05T11:03:37.520462Z","iopub.execute_input":"2024-04-05T11:03:37.521058Z","iopub.status.idle":"2024-04-05T11:05:15.136952Z","shell.execute_reply.started":"2024-04-05T11:03:37.521020Z","shell.execute_reply":"2024-04-05T11:05:15.135494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# H&M探索性数据分析以及预测\n","metadata":{}},{"cell_type":"markdown","source":"#### articles表包含所有H&M产品的详细信息，如产品类型，颜色，产品组和其他特征。\n    字段解释\n    article_id : 商品id\n    product_code, prod_name : 产品代码与产品名.\n    product_type_no, product_type_name, product_group_name 产品种类编号与名称，产品系列名称\n    graphical_appearance_no, graphical_appearance_name : 图形外观编号与名称\n    colour_group_code, colour_group_name : 色彩群组代码与名称\n    perceived_colour_value_id, perceived_colour_value_name, perceived_colour_master_id, perceived_colour_master_name : 感知颜色信息\n    department_no, department_name: : 部门编号与名称\n    index_code, index_name: : 品类代码与名称\n    index_group_no, index_group_name: : 群组品类编号与名称\n    section_no, section_name: : 分类的编号与名称\n    garment_group_no, garment_group_name: : 服装群组编号与名称\n    detail_desc: : 细节描述","metadata":{}},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:19:57.539812Z","iopub.execute_input":"2024-03-28T02:19:57.540256Z","iopub.status.idle":"2024-03-28T02:19:57.586380Z","shell.execute_reply.started":"2024-03-28T02:19:57.540218Z","shell.execute_reply":"2024-03-28T02:19:57.584921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"集团的主营业务是女装、Divided(潮流子品牌)和男装，占据所有品类的半壁江山","metadata":{}},{"cell_type":"code","source":"plt.rcParams['font.sans-serif']=['Microsoft YaHei']\nf, ax = plt.subplots(figsize=(15, 7))\ndata = articles.index_name.value_counts()\ncolors = sns.color_palette(\"pastel\")\nexplode = [0.3] + [0.02] * (articles.index_name.nunique() - 1)\nplt.title(\"index of garment accounted\")\nplt.pie(data, labels=data.keys(), colors=colors, autopct=\"%0.0f%%\", explode=explode)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:19:57.587951Z","iopub.execute_input":"2024-03-28T02:19:57.588375Z","iopub.status.idle":"2024-03-28T02:19:58.006019Z","shell.execute_reply.started":"2024-03-28T02:19:57.588331Z","shell.execute_reply":"2024-03-28T02:19:58.004280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"jersey Fancy类的服装占服装组的最多，主要为女装和童装","metadata":{}},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 7))\nax =sns.histplot(data=articles, y='garment_group_name', palette=\"pastel\", hue='index_group_name', multiple=\"stack\")\nax.set_xlabel('count by garment group')\nax.set_ylabel('garment group')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:19:58.007998Z","iopub.execute_input":"2024-03-28T02:19:58.008627Z","iopub.status.idle":"2024-03-28T02:19:59.360791Z","shell.execute_reply.started":"2024-03-28T02:19:58.008564Z","shell.execute_reply":"2024-03-28T02:19:59.359507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"童装大类包含婴儿、不同尺寸的小孩等4个小类，女装大类包含女装配件、女装、连裤袜三个小类","metadata":{}},{"cell_type":"code","source":"data = articles.groupby(['index_group_name', 'index_name']).count()['article_id']\nfig = px.treemap(data.reset_index(name=\"Count\"), path=['index_group_name','index_name'], values='Count',color='Count',\n                 range_color = [0, 20000], \n                 color_continuous_scale='Geyser',\n                 title=\"treemap of index_group_name\"\n                )\nfig.show()\ndata","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:19:59.364108Z","iopub.execute_input":"2024-03-28T02:19:59.364578Z","iopub.status.idle":"2024-03-28T02:20:01.839497Z","shell.execute_reply.started":"2024-03-28T02:19:59.364538Z","shell.execute_reply":"2024-03-28T02:20:01.838143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"服装产品的分类表，最多的小类为裤子和裙子","metadata":{}},{"cell_type":"code","source":"pd.options.display.max_rows = None\ndata=articles.groupby(['product_group_name', 'product_type_name']).count()['article_id']\nfig = px.treemap(data.reset_index(name=\"Count\"), path=['product_group_name','product_type_name'], values='Count',color='Count',\n                 color_continuous_scale='orrd',\n                 title=\"treemap of product_group_name\"\n                )\nfig.show()\ndata","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:01.841231Z","iopub.execute_input":"2024-03-28T02:20:01.841692Z","iopub.status.idle":"2024-03-28T02:20:02.229719Z","shell.execute_reply.started":"2024-03-28T02:20:01.841645Z","shell.execute_reply":"2024-03-28T02:20:02.228264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"color_brightness_map = {\n    'Beige_Dark': 'rgb(255, 228, 196)',\n    'Beige_Dusty Light': 'rgb(244, 164, 96)',\n    'Beige_Medium Dusty': 'rgb(205, 170, 125)',\n    'Black_Dark': 'rgb(0, 0, 0)',\n    'Blue_Bright': 'rgb(0, 0, 255)',\n    'Blue_Dark': 'rgb(0, 0, 139)',\n    'Blue_Dusty Light': 'rgb(173, 216, 230)',\n    'Blue_Light': 'rgb(173, 216, 230)',\n    'Blue_Medium': 'rgb(0, 0, 205)',\n    'Blue_Medium Dusty': 'rgb(173, 216, 230)',\n    'Bluish Green_Dusty Light': 'rgb(173, 216, 230)',\n    'Brown_Dark': 'rgb(139, 69, 19)',\n    'Brown_Medium Dusty': 'rgb(205, 133, 63)',\n    'Green_Bright': 'rgb(0, 255, 0)',\n    'Green_Dark': 'rgb(0, 100, 0)',\n    'Green_Dusty Light': 'rgb(173, 216, 230)',\n    'Green_Light': 'rgb(144, 238, 144)',\n    'Green_Medium': 'rgb(0, 128, 0)',\n    'Green_Medium Dusty': 'rgb(173, 216, 230)',\n    'Grey_Dark': 'rgb(169, 169, 169)',\n    'Grey_Dusty Light': 'rgb(192, 192, 192)',\n    'Grey_Medium Dusty': 'rgb(169, 169, 169)',\n    'Khaki green_Dark': 'rgb(75, 83, 32)',\n    'Khaki green_Dusty Light': 'rgb(173, 216, 230)',\n    'Khaki green_Medium Dusty': 'rgb(180, 170, 140)',\n    'Lilac Purple_Bright': 'rgb(200, 162, 200)',\n    'Lilac Purple_Dark': 'rgb(139, 0, 139)',\n    'Lilac Purple_Dusty Light': 'rgb(173, 216, 230)',\n    'Lilac Purple_Light': 'rgb(255, 182, 193)',\n    'Lilac Purple_Medium': 'rgb(147, 112, 219)',\n    'Lilac Purple_Medium Dusty': 'rgb(205, 192, 176)',\n    'Metal_Bright': 'rgb(169, 169, 169)',\n    'Metal_Dark': 'rgb(128, 128, 128)',\n    'Metal_Dusty Light': 'rgb(192, 192, 192)',\n    'Metal_Light': 'rgb(211, 211, 211)',\n    'Metal_Medium': 'rgb(169, 169, 169)',\n    'Metal_Medium Dusty': 'rgb(192, 192, 192)',\n    'Mole_Dark': 'rgb(128, 128, 105)',\n    'Mole_Dusty Light': 'rgb(173, 216, 230)',\n    'Mole_Medium Dusty': 'rgb(139, 121, 94)',\n    'Orange_Bright': 'rgb(255, 165, 0)',\n    'Orange_Dark': 'rgb(255, 140, 0)',\n    'Orange_Dusty Light': 'rgb(255, 228, 196)',\n    'Orange_Light': 'rgb(255, 165, 0)',\n    'Orange_Medium': 'rgb(255, 140, 0)',\n    'Orange_Medium Dusty': 'rgb(205, 133, 63)',\n    'Pink_Bright': 'rgb(255, 182, 193)',\n    'Pink_Dark': 'rgb(255, 20, 147)',\n    'Pink_Dusty Light': 'rgb(255, 182, 190)',\n    'Pink_Light': 'rgb(255, 182, 193)',\n    'Pink_Medium': 'rgb(255, 182, 193)',\n    'Pink_Medium Dusty': 'rgb(205, 192, 176)',\n    'Red_Bright': 'rgb(255, 0, 0)',\n    'Red_Dark': 'rgb(139, 0, 0)',\n    'Red_Medium': 'rgb(255, 0, 0)',\n    'Red_Medium Dusty': 'rgb(139, 0, 0)',\n    'Turquoise_Bright': 'rgb(64, 224, 208)',\n    'Turquoise_Dark': 'rgb(0, 206, 209)',\n    'Turquoise_Dusty Light': 'rgb(173, 216, 230)',\n    'Turquoise_Light': 'rgb(173, 216, 230)',\n    'Turquoise_Medium': 'rgb(0, 206, 209)',\n    'Turquoise_Medium Dusty': 'rgb(173, 216, 230)',\n    'Unknown_Bright': 'rgb(128, 128, 128)',\n    'Unknown_Dark': 'rgb(0, 0, 0)',\n    'Unknown_Dusty Light': 'rgb(192, 192, 192)',\n    'Unknown_Light': 'rgb(255, 255, 255)',\n    'Unknown_Medium Dusty': 'rgb(192, 192, 192)',\n    'Unknown_Unknown': 'rgb(128, 128, 128)',\n    'White_Dusty Light': 'rgb(255, 255, 224)',\n    'White_Light': 'rgb(255, 255, 255)',\n    'Yellow_Bright': 'rgb(255, 255, 0)',\n    'Yellow_Dark': 'rgb(255, 255, 0)',\n    'Yellow_Dusty Light': 'rgb(255, 228, 196)',\n    'Yellow_Light': 'rgb(255, 255, 224)',\n    'Yellow_Medium': 'rgb(255, 255, 0)',\n    'Yellow_Medium Dusty': 'rgb(255, 228, 196)',\n    'Yellowish Green_Bright': 'rgb(173, 255, 47)',\n    'Yellowish Green_Dusty Light': 'rgb(173, 216, 230)',\n    'undefined_Undefined': 'rgb(128, 128, 128)'\n    # 添加更多颜色和亮度映射\n}","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-03-28T02:20:02.231970Z","iopub.execute_input":"2024-03-28T02:20:02.232517Z","iopub.status.idle":"2024-03-28T02:20:02.249997Z","shell.execute_reply.started":"2024-03-28T02:20:02.232435Z","shell.execute_reply":"2024-03-28T02:20:02.248541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"根据色彩树状图显示，公司产品的颜色主要为黑白蓝粉","metadata":{}},{"cell_type":"code","source":"data=articles.groupby(['perceived_colour_master_name', 'perceived_colour_value_name']).count()['article_id']\ndata1=data.reset_index(name=\"Count\")\ndef merge_columns(row):\n    return f\"{row['perceived_colour_master_name']}_{row['perceived_colour_value_name']}\"\ndata1['merged_column'] = data1.apply(merge_columns, axis=1)\ndata1 = data1.drop('perceived_colour_value_name', axis=1)\nfig = px.treemap(data1, path=['perceived_colour_master_name', 'merged_column'], values='Count', color='merged_column',\n                 color_discrete_map=color_brightness_map)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:02.252056Z","iopub.execute_input":"2024-03-28T02:20:02.252521Z","iopub.status.idle":"2024-03-28T02:20:02.560688Z","shell.execute_reply.started":"2024-03-28T02:20:02.252481Z","shell.execute_reply":"2024-03-28T02:20:02.559525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.groupby(['perceived_colour_master_name', 'perceived_colour_value_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:02.562132Z","iopub.execute_input":"2024-03-28T02:20:02.562506Z","iopub.status.idle":"2024-03-28T02:20:02.754626Z","shell.execute_reply.started":"2024-03-28T02:20:02.562457Z","shell.execute_reply":"2024-03-28T02:20:02.753419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"desc=articles.detail_desc.dropna().sample(10000).values\nstopwords = set(STOPWORDS)\nwordcloud = WordCloud(\n                      width = 800, \n                      height = 800,\n                      background_color ='white',\n                      min_font_size = 10,\n                      stopwords = stopwords,).generate(' '.join(desc)) \n\n# plot the WordCloud image                        \nplt.figure(figsize = (8, 8), facecolor = None) \nplt.imshow(wordcloud) \nplt.axis(\"off\") \nplt.tight_layout(pad = 0) \n\nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:02.756318Z","iopub.execute_input":"2024-03-28T02:20:02.757499Z","iopub.status.idle":"2024-03-28T02:20:05.926253Z","shell.execute_reply.started":"2024-03-28T02:20:02.757434Z","shell.execute_reply":"2024-03-28T02:20:05.924833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-03-28T02:20:05.928257Z","iopub.execute_input":"2024-03-28T02:20:05.928695Z","iopub.status.idle":"2024-03-28T02:20:05.947795Z","shell.execute_reply.started":"2024-03-28T02:20:05.928655Z","shell.execute_reply":"2024-03-28T02:20:05.946231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### customers表包含H&M品牌的用户信息\n    字段解释customer_id:用户id, \n    FN:是否顾客收到时尚新闻(Fashion News), Active:活跃状态,\n    club_member_status:会员状态,fashion_news_frequency:接受时尚新闻频率,\n    age:年龄,postal_code:邮政编码","metadata":{}},{"cell_type":"markdown","source":"根据年龄分布图可以看出，顾客存在两个主要年龄群体，以21-26为峰值的年轻人，以50为峰值的中老年人","metadata":{}},{"cell_type":"code","source":"sns.distplot(customers.age,color=\"b\",bins=30,kde=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:05.949613Z","iopub.execute_input":"2024-03-28T02:20:05.950113Z","iopub.status.idle":"2024-03-28T02:20:12.178893Z","shell.execute_reply.started":"2024-03-28T02:20:05.950055Z","shell.execute_reply":"2024-03-28T02:20:12.177676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"H&M会员多数处于活跃状态，还有一些还未创建，几乎无人离会","metadata":{}},{"cell_type":"code","source":"sns.histplot(data=customers, x='club_member_status')","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:12.180574Z","iopub.execute_input":"2024-03-28T02:20:12.181014Z","iopub.status.idle":"2024-03-28T02:20:15.245154Z","shell.execute_reply.started":"2024-03-28T02:20:12.180973Z","shell.execute_reply":"2024-03-28T02:20:15.243654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:15.250648Z","iopub.execute_input":"2024-03-28T02:20:15.251144Z","iopub.status.idle":"2024-03-28T02:20:15.380309Z","shell.execute_reply.started":"2024-03-28T02:20:15.251105Z","shell.execute_reply":"2024-03-28T02:20:15.378680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.loc[~customers['fashion_news_frequency'].isin(['Regularly', 'Monthly']), 'fashion_news_frequency'] = 'None'\ncustomers['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:15.382394Z","iopub.execute_input":"2024-03-28T02:20:15.382889Z","iopub.status.idle":"2024-03-28T02:20:15.632524Z","shell.execute_reply.started":"2024-03-28T02:20:15.382846Z","shell.execute_reply":"2024-03-28T02:20:15.631295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"多数人不喜欢看时尚新闻","metadata":{}},{"cell_type":"code","source":"data=customers.fashion_news_frequency.value_counts()\nplt.pie(data, labels=data.keys(), autopct=\"%0.0f%%\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:15.634184Z","iopub.execute_input":"2024-03-28T02:20:15.634639Z","iopub.status.idle":"2024-03-28T02:20:15.995260Z","shell.execute_reply.started":"2024-03-28T02:20:15.634598Z","shell.execute_reply":"2024-03-28T02:20:15.993499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"年龄与是否喜欢看时尚新闻无相关性","metadata":{}},{"cell_type":"code","source":"from scipy.stats import pearsonr\nfrom sklearn.preprocessing import LabelEncoder\nencoder = LabelEncoder()\ncustomers1=customers.dropna()\nnumbers = encoder.fit_transform(customers1.fashion_news_frequency)\ncorr_coefficient, p_value = pearsonr(numbers,customers1.age)\nprint(\"Pearson 相关系数:\", corr_coefficient)\nprint(\"P 值:\", p_value)","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:15.997679Z","iopub.execute_input":"2024-03-28T02:20:15.999333Z","iopub.status.idle":"2024-03-28T02:20:16.985257Z","shell.execute_reply.started":"2024-03-28T02:20:15.999263Z","shell.execute_reply":"2024-03-28T02:20:16.983509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### transactions_train表包含H&M的交易信息\n    字段解释t_dat：交易时间,customer_id：顾客id,article_id:商品id\n    price:价格,sales_channel_id:销售渠道id","metadata":{}},{"cell_type":"code","source":"transactions_train.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-28T02:20:16.995937Z","iopub.execute_input":"2024-03-28T02:20:17.002527Z","iopub.status.idle":"2024-03-28T02:20:17.039159Z","shell.execute_reply.started":"2024-03-28T02:20:17.002407Z","shell.execute_reply":"2024-03-28T02:20:17.037323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"排行前十的超级顾客","metadata":{}},{"cell_type":"code","source":"transactions_byid = transactions_train.groupby('customer_id').count()\ntransactions_byid.sort_values(by='price', ascending=False)['price'][:10]","metadata":{"execution":{"iopub.status.busy":"2024-04-05T11:44:14.820187Z","iopub.execute_input":"2024-04-05T11:44:14.820840Z","iopub.status.idle":"2024-04-05T11:44:35.107799Z","shell.execute_reply.started":"2024-04-05T11:44:14.820809Z","shell.execute_reply":"2024-04-05T11:44:35.106247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"超级顾客购买的商品","metadata":{}},{"cell_type":"code","source":"super_customer=transactions_byid.sort_values(by='price', ascending=False)['price'][:10]\narticle_info = articles[['article_id', 'product_type_name']]\nresult = pd.merge(transactions_train, article_info, on='article_id', how='left')\nresult[result.customer_id.isin(super_customer.index)].groupby(['customer_id','product_type_name']).count().price[:10]","metadata":{"execution":{"iopub.status.busy":"2024-04-05T11:44:39.052237Z","iopub.execute_input":"2024-04-05T11:44:39.052650Z","iopub.status.idle":"2024-04-05T11:44:49.416092Z","shell.execute_reply.started":"2024-04-05T11:44:39.052621Z","shell.execute_reply":"2024-04-05T11:44:49.414755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"商品定价的概率密度图，出现多个尖峰，都处于0-0.1的低价档，表示具有多个价格模式或群集，可能是由于不同市场、产品类型或客户群体引起的,","metadata":{}},{"cell_type":"code","source":"#sns.plot(transactions_train['price'],shade=True)\nsns.histplot(data=transactions_train[transactions_train.price<0.1],x='price',bins=40,kde=True) ","metadata":{"execution":{"iopub.status.busy":"2024-04-05T11:17:35.370660Z","iopub.execute_input":"2024-04-05T11:17:35.371060Z","iopub.status.idle":"2024-04-05T11:19:58.154818Z","shell.execute_reply.started":"2024-04-05T11:17:35.371030Z","shell.execute_reply":"2024-04-05T11:19:58.153877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**选取三处比较显著的区间进行分析<br>\n[0.15-0.175],[0.25-0.275],[0.3-0.325]**<br>\n找出这些价格段用户的年龄销售渠道分布","metadata":{"execution":{"iopub.status.busy":"2024-03-28T05:12:50.038566Z","iopub.execute_input":"2024-03-28T05:12:50.041337Z","iopub.status.idle":"2024-03-28T05:12:50.056905Z","shell.execute_reply.started":"2024-03-28T05:12:50.041247Z","shell.execute_reply":"2024-03-28T05:12:50.055316Z"}}},{"cell_type":"code","source":"transactions_info1 = transactions_train[(transactions_train['price'] < 0.175) & (transactions_train['price'] > 0.15)][['customer_id','sales_channel_id', 'price','article_id']]\ncustomer_info=customers[['customer_id','age']]\ntemp1 = pd.merge(transactions_info1, customer_info, on='customer_id', how='left')\nresult=pd.merge(temp1, article_info, on='article_id', how='left')\nresult.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-05T11:47:56.507202Z","iopub.execute_input":"2024-04-05T11:47:56.507600Z","iopub.status.idle":"2024-04-05T11:47:57.496022Z","shell.execute_reply.started":"2024-04-05T11:47:56.507572Z","shell.execute_reply":"2024-04-05T11:47:57.494519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[0.15-0.175]价格段消费者的购买商品种类、年龄分布、消费渠道<br>\n可以看出渠道1的用户更年轻些，大致位于25-50之间。大家最喜欢购买大衣","metadata":{}},{"cell_type":"code","source":"display(result.groupby('product_type_name').count().sort_values(by='price', ascending=False)['price'][:10])\nsns.boxplot(data=result,x='sales_channel_id',y='age')","metadata":{"execution":{"iopub.status.busy":"2024-04-05T11:59:59.871952Z","iopub.execute_input":"2024-04-05T11:59:59.872620Z","iopub.status.idle":"2024-04-05T12:00:00.287129Z","shell.execute_reply.started":"2024-04-05T11:59:59.872570Z","shell.execute_reply":"2024-04-05T12:00:00.285620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import Image\nImage(filename='/kaggle/input/doubao-picture/658e9bdf60234b0f9e688d3cd9d056bc.pngtplv-a9rns2rl98-downsize.png')","metadata":{"execution":{"iopub.status.busy":"2024-04-05T12:11:19.798646Z","iopub.execute_input":"2024-04-05T12:11:19.799375Z","iopub.status.idle":"2024-04-05T12:11:19.826384Z","shell.execute_reply.started":"2024-04-05T12:11:19.799338Z","shell.execute_reply":"2024-04-05T12:11:19.825029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[0.25-0.275]价格段消费者的购买商品种类、年龄分布、消费渠道<br>\n可以看出渠道1的用户25-32岁就占据总购买人数的1/4。大家最喜欢购买夹克以及裙子","metadata":{}},{"cell_type":"code","source":"transactions_info1 = transactions_train[(transactions_train['price'] < 0.275) & (transactions_train['price'] > 0.25)][['customer_id','sales_channel_id', 'price','article_id']]\ncustomer_info=customers[['customer_id','age']]\ntemp1 = pd.merge(transactions_info1, customer_info, on='customer_id', how='left')\nresult=pd.merge(temp1, article_info, on='article_id', how='left')\ndisplay(result.groupby('product_type_name').count().sort_values(by='price', ascending=False)['price'][:10])\nsns.boxplot(data=result,x='sales_channel_id',y='age')","metadata":{"execution":{"iopub.status.busy":"2024-04-05T12:02:19.415977Z","iopub.execute_input":"2024-04-05T12:02:19.416559Z","iopub.status.idle":"2024-04-05T12:02:20.840475Z","shell.execute_reply.started":"2024-04-05T12:02:19.416518Z","shell.execute_reply":"2024-04-05T12:02:20.839197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Image(filename='/kaggle/input/doubao-picture/0bf1d8186da14964973bf51a48d71406.pngtplv-a9rns2rl98-downsize.png')","metadata":{"execution":{"iopub.status.busy":"2024-04-05T12:26:49.129424Z","iopub.execute_input":"2024-04-05T12:26:49.129902Z","iopub.status.idle":"2024-04-05T12:26:49.143090Z","shell.execute_reply.started":"2024-04-05T12:26:49.129869Z","shell.execute_reply":"2024-04-05T12:26:49.142095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[0.325-0.35]价格段消费者的购买商品种类、年龄分布、消费渠道<br>\n可以看出用户年龄位于35-55之间。大家仍然最喜欢购买夹克以及裙子","metadata":{"execution":{"iopub.status.busy":"2024-04-05T12:19:21.156858Z","iopub.execute_input":"2024-04-05T12:19:21.157342Z","iopub.status.idle":"2024-04-05T12:19:21.166734Z","shell.execute_reply.started":"2024-04-05T12:19:21.157309Z","shell.execute_reply":"2024-04-05T12:19:21.165094Z"}}},{"cell_type":"code","source":"transactions_info1 = transactions_train[(transactions_train['price'] < 0.325) & (transactions_train['price'] > 0.3)][['customer_id','sales_channel_id', 'price','article_id']]\ncustomer_info=customers[['customer_id','age']]\ntemp1 = pd.merge(transactions_info1, customer_info, on='customer_id', how='left')\nresult=pd.merge(temp1, article_info, on='article_id', how='left')\ndisplay(result.groupby('product_type_name').count().sort_values(by='price', ascending=False)['price'][:10])\nsns.boxplot(data=result,x='sales_channel_id',y='age')","metadata":{"execution":{"iopub.status.busy":"2024-04-05T12:12:30.456791Z","iopub.execute_input":"2024-04-05T12:12:30.457338Z","iopub.status.idle":"2024-04-05T12:12:31.799572Z","shell.execute_reply.started":"2024-04-05T12:12:30.457208Z","shell.execute_reply":"2024-04-05T12:12:31.798045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Image(filename='/kaggle/input/doubao-picture/0076e9a0e6e146489266cf89529360ed.pngtplv-a9rns2rl98-downsize.png')","metadata":{"execution":{"iopub.status.busy":"2024-04-05T12:27:16.255463Z","iopub.execute_input":"2024-04-05T12:27:16.256464Z","iopub.status.idle":"2024-04-05T12:27:16.300988Z","shell.execute_reply.started":"2024-04-05T12:27:16.256418Z","shell.execute_reply":"2024-04-05T12:27:16.298944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}