Kaggle competition: Santander Customer Transaction Prediction
questions_df = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/questions.csv',
usecols=[0, 3],
dtype={'question_id': 'int16',
'part': 'int8'}
)<load_from_csv>
gc.enable()
lectures_df = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/lectures.csv' )<categorify>
df_train = pd.read_csv('.. /input/train.csv' )
lectures_df['type_of'] = lectures_df['type_of'].replace('solving question', 'solving_question')
 lectures_df = pd.get_dummies(lectures_df, columns=['part', 'type_of'])
 part_lectures_columns = [column for column in lectures_df.columns if column.startswith('part')]
types_of_lectures_columns = [column for column in lectures_df.columns if column.startswith('type_of_')]<merge>
df_test = pd.read_csv('.. /input/test.csv' )
train_lectures = train[train.content_type_id == True].merge(lectures_df, left_on='content_id', right_on='lecture_id', how='left' )<groupby>
df_sub = pd.read_csv('.. /input/sample_submission.csv' )
user_lecture_stats_part = train_lectures.groupby('user_id')[part_lectures_columns + types_of_lectures_columns].sum()<data_type_conversions>
total = df_train.isnull().sum().sort_values(ascending=False)
 percent =(df_train.isnull().sum() /df_train.isnull().count() ).sort_values(ascending=False)
 missing_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
 missing_data.head()
for column in user_lecture_stats_part.columns:
bool_column = column + '_boolean'
user_lecture_stats_part[bool_column] =(user_lecture_stats_part[column] > 0 ).astype(int )<drop_column>
def featureEngineering(df,cols,col_name):
df[col_name] = 0
for c in cols:
df[col_name] += df[c]
return df
del(train_lectures )<sort_values>
df_test = featureEngineering(df_test,cols, 'posCols' )
train = train[train.content_type_id == False].sort_values('timestamp' ).reset_index(drop = True )<count_unique_values>
val = np.zeros(df_train.shape[0])
 pred = np.zeros(df_test.shape[0])
 x = df_train.drop(['ID_code','target'],axis=1 ).values
y = df_train['target'].values
folds = StratifiedKFold(n_splits=3, shuffle=True, random_state=1234 )
train[(train.content_type_id == False)].task_container_id.nunique()<groupby>
model_xgb = xgb.XGBClassifier(max_depth=2,
colsample_bytree=0.7,
n_estimators=20000,
scale_pos_weight = 9,
learning_rate=0.02,
objective='binary:logistic',
verbosity =1,
eval_metric = 'auc',
tree_method='gpu_hist',
n_jobs=-1 )
group1 = train.loc[(train.content_type_id == False), ['task_container_id', 'user_id']].groupby(['task_container_id'] ).agg(['count'])
 group1.columns = ['avg_questions']
group2 = train.loc[(train.content_type_id == False), ['task_container_id', 'user_id']].groupby(['task_container_id'] ).agg(['nunique'])
 group2.columns = ['avg_questions']
group3 = group1 / group2<groupby>
for fold_index,(train_index,val_index)in enumerate(folds.split(x,y)) :
print('Batch {} started...'.format(fold_index))
gc.collect()
bst = model_xgb.fit(x[train_index],y[train_index],
eval_set = [(x[val_index],y[val_index])],
early_stopping_rounds=200,
verbose= 200,
eval_metric ='auc' 
)
 val[val_index] = model_xgb.predict_proba(x[val_index])[:,1]
print('auc of this val set is {}'.format(roc_auc_score(y[val_index],val[val_index])))
 pred += model_xgb.predict_proba(df_test.drop(['ID_code'],axis=1 ).values)[:,1]/folds.n_splits
group3['avg_questions_seen'] = group3.avg_questions.cumsum()<set_options>
df_sub.target = pred
<groupby><EOS> 
df_sub.to_csv('r_prob.csv',index=False )