Kaggle competition: Tabular Playground Series - Feb 2021
train_df['timestamp']=train_df['timestamp']/(1000*3600)
 train_df.timestamp=train_df.timestamp.astype('int16')
<data_type_conversions>
train = pd.read_csv('.. /input/tabular-playground-series-feb-2021/train.csv')
 test = pd.read_csv('.. /input/tabular-playground-series-feb-2021/test.csv')
 sub = pd.read_csv('.. /input/tabular-playground-series-feb-2021/sample_submission.csv' )
train_df['lag'] = train_df.groupby('user_id')[target].shift()
cum = train_df.groupby('user_id')['lag'].agg(['cumsum', 'cumcount'])
 train_df['user_correctness'] = cum['cumsum'] / cum['cumcount']
train_df['user_correct_cumsum'] = cum['cumsum']
train_df['user_correct_cumcount'] = cum['cumcount']
train_df.drop(columns=['lag'], inplace=True)
 train_df['user_correct_cumsum'].fillna(0, inplace=True)
 train_df.user_correctness=train_df.user_correctness.astype('float16')
 train_df.user_correct_cumcount=train_df.user_correct_cumcount.astype('int16')
 train_df.user_correct_cumsum=train_df.user_correct_cumsum.astype('int16' )<data_type_conversions>
target = train['target'].values
train_df.prior_question_had_explanation=train_df.prior_question_had_explanation.astype('int8')
 train_df['lag'] = train_df.groupby('user_id')['prior_question_had_explanation'].shift()<data_type_conversions>
train_oof_lgb = np.load('.. /input/tps-feb-2021-with-lgbmregressor/train_oof.npy')
 test_preds_lgb = np.load('.. /input/tps-feb-2021-with-lgbmregressor/test_preds.npy')
 train_oof_xgb = np.load('.. /input/tps-02-21-feature-importance-with-xgboost-and-shap/train_oof.npy')
 test_preds_xgb = np.load('.. /input/tps-02-21-feature-importance-with-xgboost-and-shap/test_preds.npy')
 lgbm_goes_brrr = pd.read_csv('.. /input/lgbm-goes-brrr/submission.csv' )
cum = train_df.groupby('user_id')['lag'].agg(['cumsum', 'cumcount'])
 train_df['explanation_mean'] = cum['cumsum'] / cum['cumcount']
train_df['explanation_cumsum'] = cum['cumsum']
train_df.drop(columns=['lag'], inplace=True)
 train_df['explanation_mean'].fillna(0, inplace=True)
 train_df['explanation_cumsum'].fillna(0, inplace=True)
 train_df.explanation_mean=train_df.explanation_mean.astype('float16')
 train_df.explanation_cumsum=train_df.explanation_cumsum.astype('int16' )<set_options>
print(mean_squared_error(train_oof_lgb, target, squared=False))
print(mean_squared_error(train_oof_xgb, target, squared=False))
del cum
gc.collect()<data_type_conversions>
print(mean_squared_error(0.75*train_oof_lgb+0.25*train_oof_xgb, target, squared=False))
train_df["attempt_no"] = 1
train_df.attempt_no=train_df.attempt_no.astype('int8')
 train_df["attempt_no"] = train_df[["user_id","content_id",'attempt_no']].groupby(["user_id","content_id"])["attempt_no"].cumsum()<data_type_conversions>
sub['target'] = 0.75*test_preds_lgb+0.25*test_preds_xgb
sub.to_csv('submission.csv', index=False)
 sub.head()
explanation_agg = train_df.groupby('user_id')['prior_question_had_explanation'].agg(['sum', 'count'])
 explanation_agg=explanation_agg.astype('int16')
<groupby>
sub['target'] = 0.675*test_preds_lgb+0.225*test_preds_xgb+0.1*lgbm_goes_brrr['target'].values
sub.to_csv('submission_2.csv', index=False)
 sub.head()
user_agg = train_df.groupby('user_id')[target].agg(['sum', 'count'])
 content_agg = train_df.groupby('content_id')[target].agg(['sum', 'count','var'])
 task_container_agg = train_df.groupby('task_container_id')[target].agg(['sum', 'count','var'])
<data_type_conversions>
sub['target'] = 0.6*test_preds_lgb+0.2*test_preds_xgb+0.2*lgbm_goes_brrr['target'].values
sub.to_csv('submission_3.csv', index=False)
 sub.head()
<categorify><EOS> 
sub['target'] = 0.525*test_preds_lgb+0.175*test_preds_xgb+0.3*lgbm_goes_brrr['target'].values
sub.to_csv('submission_4.csv', index=False)
 sub.head()