Kaggle competition: Oxford Fast AI Week 2
<SOS> metric: categorizationaccuracy Kaggle data source: oxford-fast-ai-week-2<merge>
%reload_ext autoreload
%autoreload 2
%matplotlib inline
train_new = train_new.merge(group, on=["date_block_num"])
 train_new.fillna(0, inplace=True )<concatenate>
PATH = ".. /input/"
TMP_PATH = "/tmp/tmp"
MODEL_PATH = "/tmp/model/"
sz=224
train_new = lag_feature(train_new, [1], "date_block_item_cnt_mean")
 train_new.fillna(0, inplace=True )<drop_column>
torch.cuda.is_available()
train_new.drop("date_block_item_cnt_mean", axis=1, inplace=True )<merge>
torch.backends.cudnn.enabled
group = train_new.groupby(["date_block_num","shop_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","shop_id", "shop_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "shop_id"])
 train_new = lag_feature(train_new, lags, "shop_item_cnt_mean")
 train_new.fillna(0, inplace=True )<drop_column>
fnames = np.array([f'train/{f}' for f in sorted(os.listdir(f'{PATH}train')) ])
 labels = np.array([(0 if 'cat' in fname else 1)for fname in fnames] )
train_new.drop("shop_item_cnt_mean", axis=1, inplace=True )<merge>
arch=resnet34
data=ImageClassifierData.from_paths(path=PATH,val_name='valid',test_name='test',tfms=tfms_from_model(arch, sz))
group = train_new.groupby(["date_block_num","item_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","item_id", "item_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "item_id"])
 train_new = lag_feature(train_new, [1], "item_item_cnt_mean")
 train_new.drop("item_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
learn = ConvLearner.pretrained(arch, data, precompute=True, tmp_name=TMP_PATH, models_name=MODEL_PATH )
group = train_new.groupby(["date_block_num","item_category_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","item_category_id", "item_category_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "item_category_id"])
 train_new = lag_feature(train_new, [1], "item_category_item_cnt_mean")
 train_new.drop("item_category_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
learn.fit(0.01, 2 )
group = train_new.groupby(["date_block_num","city_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","city_id", "city_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "city_id"])
 train_new = lag_feature(train_new, [1], "city_item_cnt_mean")
 train_new.drop("city_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
log_preds = learn.predict(is_test=True )
group = train_new.groupby(["date_block_num","big_category_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","big_category_id", "big_category_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "big_category_id"])
 train_new = lag_feature(train_new, [1], "big_category_item_cnt_mean")
 train_new.drop("big_category_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
lps = np.argmax(log_preds,axis=1 )
group = train_new.groupby(["date_block_num","sub_category_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","sub_category_id", "sub_category_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "sub_category_id"])
 train_new = lag_feature(train_new, [1], "sub_category_item_cnt_mean")
 train_new.drop("sub_category_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
preds_classes = [data.classes[i] for i in lps]
group = train_new.groupby(["date_block_num","item_category_id", "item_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num","item_category_id", "item_id", "item_category_item_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num","item_category_id", "item_id"])
 train_new = lag_feature(train_new, lags, "item_category_item_item_cnt_mean")
 train_new.drop("item_category_item_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
sub_frame = pd.read_csv('.. /input/Sample_Sub.csv')
 sub_frame['Category'] = preds_classes
group = train_new.groupby(["date_block_num", "shop_id", "item_category_id"] ).agg({"item_cnt_month": ["mean"]} ).reset_index()
group.columns = ["date_block_num", "shop_id", "item_category_id", "shop_item_category_item_cnt_mean"]
train_new = train_new.merge(group, on=["date_block_num", "shop_id", "item_category_id"])
 train_new = lag_feature(train_new, lags, "shop_item_category_item_cnt_mean")
 train_new.drop("shop_item_category_item_cnt_mean", axis=1, inplace=True)
 train_new.fillna(0, inplace=True )<merge>
sub_frame.to_csv('Submission.csv',index=False )