Kaggle competition: Tabular Playground Series - Feb 2021
questions_df.drop(columns=['tags'], inplace=True )<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' )
questions_df['part_bundle_id']=questions_df['part']*100000+questions_df['bundle_id']
questions_df.part_bundle_id=questions_df.part_bundle_id.astype('int32')
<load_from_csv>
target = train['target'].values
<rename_columns>
for feature in cat_features:
le = LabelEncoder()
le.fit(train[feature])
 train[feature] = le.transform(train[feature])
 test[feature] = le.transform(test[feature] )
questions_df.rename(columns={'question_id':'content_id'}, inplace=True )<merge>
train_oof = np.zeros(( 300000,))
test_preds = 0
train_oof.shape
questions_df = pd.merge(questions_df, content_explation_agg, on='content_id', how='left',right_index=True)
<drop_column>
params = {'reg_alpha': 6.147694913504962,
'reg_lambda': 0.002457826062076097,
'colsample_bytree': 0.3,
'subsample': 0.8,
'learning_rate': 0.0005,
'max_depth': 20,
'num_leaves': 111,
'min_child_samples': 285,
'random_state': 48,
'n_estimators': 320000,
'metric': 'rmse',
'cat_smooth': 39}
del content_explation_agg<data_type_conversions>
NUM_FOLDS = 10
kf = KFold(n_splits=NUM_FOLDS, shuffle=True, random_state=0)
 for f,(train_ind, val_ind)in tqdm(enumerate(kf.split(train, target))):
train_df, val_df = train.iloc[train_ind][columns], train.iloc[val_ind][columns]
train_target, val_target = target[train_ind], target[val_ind]
model = LGBMRegressor(**params)
 model.fit(train_df, train_target, eval_set=[(val_df,val_target)],early_stopping_rounds=1600,verbose=False)
 temp_oof = model.predict(val_df)
 temp_test = model.predict(test[columns])
 train_oof[val_ind] = temp_oof
test_preds += temp_test/NUM_FOLDS
print(mean_squared_error(temp_oof, val_target, squared=False))
questions_df['content_correctness'] = questions_df['content_id'].map(content_agg['sum'] / content_agg['count'])
 questions_df.content_correctness=questions_df.content_correctness.astype('float16')
 questions_df['content_correctness_std'] = questions_df['content_id'].map(content_agg['var'])
 questions_df.content_correctness_std=questions_df.content_correctness_std.astype('float16')
 questions_df['content_uncorrect_count'] = questions_df['content_id'].map(content_agg['count']-content_agg['sum'] ).astype('int32')
 questions_df['content_correct_count'] = questions_df['content_id'].map(content_agg['sum'] ).astype('int32' )<data_type_conversions>
mean_squared_error(train_oof, target, squared=False)
questions_df['content_elapsed_time_mean'] = questions_df['content_id'].map(content_elapsed_time_agg['mean'])
 questions_df.content_elapsed_time_mean=questions_df.content_elapsed_time_mean.astype('float16')
 questions_df['content_had_explanation_mean'] = questions_df['content_id'].map(content_had_explanation_agg['mean'])
 questions_df.content_had_explanation_mean=questions_df.content_had_explanation_mean.astype('float16' )<drop_column>
np.save('train_oof', train_oof)
 np.save('test_preds', test_preds )
<categorify><EOS> 
sub['target'] = test_preds
sub.to_csv('submission.csv', index=False )