Kaggle competition: Give Me Some Credit
kfold = StratifiedKFold(n_splits=20 )<choose_model_class>
train_df = pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-training.csv')
 test_df = pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-test.csv' )
loss_func = nn.BCELoss()<randomize_order>
train_df.isnull().sum()
ra = np.arange(3,train_df.shape[1])
 np.random.shuffle(ra)
 train_df[:,3:] = train_df[:,ra]
test_df[:,3:] = test_df[:,ra]<define_variables>
test_df.isnull().sum()
cat_col = [0,1] 
<split>
train_df.loc[train_df['age'] < 18]
seed_everything(1006)
 submission.iloc[:,1:]=0
for train,test in kfold.split(train_df,np.zeros(len(train_df))):
batch_size=512
sparse_constant = 0
model = TabNetWithEmbed(train_df.shape[1]-1,train_tar.shape[1],n_d=128,n_a=16,n_shared=1,n_ind=4,n_steps=3,relax=1.5,vbs=64)
 model.to(device)
 torch.cuda.empty_cache()
optimizer = optim.Adam(model.parameters() ,lr=0.007809719000164987,weight_decay=0.00001)
 sched = optim.lr_scheduler.ReduceLROnPlateau(optimizer,factor=0.1,patience=3,verbose=True)
 train_dataset = DrugData(train_df[train],train_tar[train])
 valid_dataset = DrugData(train_df[test],train_tar[test],False)
 train_loader = DataLoader(train_dataset,batch_size=batch_size,num_workers=4,shuffle=True)
 valid_loader = DataLoader(valid_dataset,batch_size=batch_size,num_workers=4,shuffle=True)
 losses=[]
norm = []
t = time.time()
for x in range(24):
train_loss=0.
 grad_norm_sum = 0.
 for inp,tar in train_loader:
model.zero_grad()
out,l = model(inp[:,cat_col].long() ,inp[:,3:])
 loss = loss_func(out,tar.to(device))
loss.backward()
optimizer.step()
train_loss+=loss.item() *tar.size(0)
 valid_loss=0.
 v=0
for inp,tar in valid_loader:
v+=1
out,_ = model(inp[:,cat_col].long() ,inp[:,3:])
 loss = loss_func(out,tar.to(device))
valid_loss+= loss.item() *tar.size(0)
 losses.append(valid_loss/len(valid_dataset))
print('%d epoch, %.8f valid_loss, %.8f training_loss %fsec time'%(x+1,losses[-1],train_loss/len(train_dataset),(time.time() -t)))
 sched.step(losses[-1])
 t = time.time()
print("completed training one fold -------------- ")
 model.eval()
submission.iloc[:,1:] += model(torch.from_numpy(test_df[:,cat_col] ).long() ,torch.from_numpy(test_df[:,3:] ).float())[0].data.cpu().numpy()<define_variables>
train_df.drop_duplicates(inplace=True )
<define_variables>
train_df.rename(columns={'Unnamed: 0':'ID'}, inplace=True)
 test_df.rename(columns={'Unnamed: 0':'ID'}, inplace=True )
<feature_engineering>
train_df = train_df[train_df['NumberOfTime30-59DaysPastDueNotWorse'] < 90]
train_df = train_df[train_df['NumberOfTimes90DaysLate'] < 90]
train_df = train_df[train_df['NumberOfTime60-89DaysPastDueNotWorse'] < 90]
submission.iloc[:,1:] = submission.iloc[:,1:]/20<create_dataframe>
k = 0
for i in train_df['NumberOfDependents']:
if i>8:
train_df['NumberOfDependents'].values[k]=8
k +=1
k = 0
for i in test_df['NumberOfDependents']:
if i>8:
test_df['NumberOfDependents'].values[k]=8
k +=1
submission = submission.copy()<save_to_csv>
train_df.loc[train_df['age'] < 18, 'age'] = train_df['age'].median()
submission.to_csv('submission.csv',index=False )<set_options>
train_df['MonthlyIncome'] = train_df['MonthlyIncome'].replace(np.nan,train_df['MonthlyIncome'].mean())
 test_df['MonthlyIncome'] = test_df['MonthlyIncome'].replace(np.nan,test_df['MonthlyIncome'].mean())
 train_df['NumberOfDependents'] = train_df['NumberOfDependents'].replace(np.nan,train_df['NumberOfDependents'].median())
 test_df['NumberOfDependents'] = test_df['NumberOfDependents'].replace(np.nan,test_df['NumberOfDependents'].median() )
sys.path.append('.. /input/iterative-stratification/iterative-stratification-master')
 warnings.filterwarnings('ignore')
<load_from_csv>
x = train_df.drop(['SeriousDlqin2yrs', 'ID'],axis=1)
 y= train_df['SeriousDlqin2yrs']
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=42 )
<categorify><EOS> 
test_df = test_df.drop(['SeriousDlqin2yrs', 'ID'],axis=1)
 gbc_clf_proba = gbm1.predict_proba(test_df)[:,1]
ids = np.arange(1,101504)
 submission = pd.DataFrame({'Id': ids, 'Probability': gbc_clf_proba})
 submission.to_csv("submision.csv", index=False )