<jupyter_start><jupyter_text>import包<jupyter_code>import sys
sys.path.append('../AutoX')
from autox import AutoXRecommend
import pandas as pd
import numpy as np
import os
from tqdm import tqdm<jupyter_output><empty_output><jupyter_text>读取数据<jupyter_code>path = '/home/caihengxing/kaggle/h_and_m/input/'
inter_df = pd.read_csv(path + 'transactions_train.csv', dtype={'article_id': str})
user_df = pd.read_csv(path + 'customers.csv')
item_df = pd.read_csv(path + 'articles.csv', dtype={'article_id': str})
sample_submission = pd.read_csv(path + 'sample_submission.csv')
inter_df.head()<jupyter_output><empty_output><jupyter_text>配置参数<jupyter_code>uid = 'customer_id'
iid = 'article_id'
time_col = 't_dat'
recall_num = 50<jupyter_output><empty_output><jupyter_text>注意时间列需要转成时间格式<jupyter_code>inter_df[time_col] = pd.to_datetime(inter_df[time_col])
inter_df[time_col].min(), inter_df[time_col].max()
inter_df.shape
import datetime
data_used_time = datetime.datetime.strptime('2020-06-22', '%Y-%m-%d')
inter_df = inter_df.loc[inter_df[time_col] > data_used_time]
inter_df[time_col].min(), inter_df[time_col].max()
inter_df.shape<jupyter_output><empty_output><jupyter_text>执行AutoXRecommend<jupyter_code>autoXRecommend = AutoXRecommend()

autoXRecommend.fit(inter_df = inter_df, user_df = user_df, item_df = item_df,
                  uid = uid, iid = iid, time_col = time_col,
                  recall_num = recall_num,
                  debug = True, debug_save_path = './temp_h_and_m')
test_users = list(sample_submission[uid])
res = autoXRecommend.transform(test_users)
res.head()
res['prediction'] = res['prediction'].apply(lambda x: ' '.join(x))
res.to_csv('./AutoX_hm.csv', index = False)
!zip -r AutoX_hm.csv.zip AutoX_hm.csv
res.shape, sample_submission.shape
res.head()
sample_submission.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14012041598248495, 'fraction_numerical': 0.005473453749315818, 'mean_word_length': 6.616666666666666, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '122116', 'license': 'Apache-2.0', 'n_tokens_mistral': 738, 'n_tokens_neox': 725, 'n_words': 100, 'path': 'autox/autox_recommend/demo/HM/HM_AutoX_recall_and_rank.ipynb', 'repo_name': 'OneToolsCollection/4paradigm-AutoX', 'size': '1827'}