Kaggle competition: Home Credit Default Risk
<SOS> metric: AUC Kaggle data source: home-credit-default-risk<train_model>
pd.set_option("display.max_columns",100)
 %matplotlib inline
py.init_notebook_mode(connected=True)
 print(os.listdir(".. /input"))
<train_model>
df_train = pd.read_csv('.. /input/application_train.csv')
 df_train.head()
sn_ce = SigmoidNeuronMy()
sn_ce.fit(X_scaled_train, Y_train, epochs=800, learning_rate=0.00005, loss_fn="ce", display_loss=True)
<predict_on_test>
df_test = pd.read_csv('.. /input/application_test.csv')
def print_accuracy(sn):
Y_pred_train = sn.predict(X_scaled_train)
 Y_pred_binarised_train =(Y_pred_train >= 0.5 ).astype("int" ).ravel()
accuracy_train = accuracy_score(Y_pred_binarised_train, Y_train)
 print("Train Accuracy : ", accuracy_train)
 print("-"*50 )<compute_test_metric>
y = df_train['TARGET']
X = df_train.drop(['TARGET'], axis=1)
 X.head()
print_accuracy(sn_ce )<save_to_csv>
print(X.shape)
 X = pd.concat([X, df_test], axis=0)
 X.shape
Y_pred_test = sn_ce.predict(X_scaled_test)
 Y_pred_binarised_test =(Y_pred_test >= 0.5 ).astype("int" ).ravel()
submission = {}
submission['ImageId'] = ID_test
submission['Class'] = Y_pred_binarised_test
submission = pd.DataFrame(submission)
 submission = submission[['ImageId', 'Class']]
submission = submission.sort_values(['ImageId'])
 submission.to_csv("submisision.csv", index=False )<set_options>
cat_X = X.drop(['SK_ID_CURR'], axis=1)
 cat_X = [col for col in X.columns if X[col].dtype == 'object']
SK_ID = X['SK_ID_CURR']
cat_X = X[cat_X]
cat_X.head()
np.random.seed(100)
 LEVEL = 'level_4b'
warnings.filterwarnings("ignore" )<compute_test_metric>
ncat_X = ncat_X.fillna(0)
class SigmoidNeuron:
def __init__(self):
self.w = None
self.b = None
def perceptron(self, x):
return np.dot(x, self.w.T)+ self.b
def sigmoid(self, x):
return 1.0/(1.0 + np.exp(-x))
def grad_w_mse(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
return(y_pred - y)* y_pred *(1 - y_pred)* x
def grad_b_mse(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
return(y_pred - y)* y_pred *(1 - y_pred)
 def grad_w_ce(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
if y == 0:
return y_pred * x
elif y == 1:
return -1 *(1 - y_pred)* x
else:
raise ValueError("y should be 0 or 1")
 def grad_b_ce(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
if y == 0:
return y_pred
elif y == 1:
return -1 *(1 - y_pred)
 else:
raise ValueError("y should be 0 or 1")
 def fit(self, X, Y, epochs=1, learning_rate=1, initialise=True, loss_fn="mse", display_loss=False):
if initialise or self.w is None:
self.w = np.random.randn(1, X.shape[1])
 self.b = 0
if display_loss:
loss = {}
for i in tqdm_notebook(range(epochs), total=epochs, unit="epoch"):
dw = 0
db = 0
for x, y in zip(X, Y):
if loss_fn == "mse":
dw += self.grad_w_mse(x, y)
 db += self.grad_b_mse(x, y)
 elif loss_fn == "ce":
dw += self.grad_w_ce(x, y)
 db += self.grad_b_ce(x, y)
 self.w -= learning_rate * dw
self.b -= learning_rate * db
if display_loss:
Y_pred = self.sigmoid(self.perceptron(X))
if loss_fn == "mse":
loss[i] = mean_squared_error(Y, Y_pred)
 elif loss_fn == "ce":
loss[i] = log_loss(Y, Y_pred)
 if display_loss:
plt.plot(loss.values())
 plt.xlabel('Epochs')
 if loss_fn == "mse":
plt.ylabel('Mean Squared Error')
 elif loss_fn == "ce":
plt.ylabel('Log Loss')
 plt.show()
def predict(self, X):
Y_pred = []
for x in X:
y_pred = self.sigmoid(self.perceptron(x))
Y_pred.append(y_pred)
 return np.array(Y_pred )<import_modules>
ncat_X = pd.DataFrame(ncat_X, columns=cols_ncat_X)
 ncat_X['SK_ID_CURR'] = SK_ID.values
ncat_X.head(10 )
<load_pretrained>
ncat_X['PERC_INCOME'] = ncat_X.AMT_CREDIT/ncat_X.AMT_INCOME_TOTAL
ncat_X.head()
languages = ['ta', 'hi', 'en']
images_train = read_all(".. /input/level_4b_train/"+LEVEL+"/"+"background", key_prefix='bgr_')
 for language in languages:
images_train.update(read_all(".. /input/level_4b_train/"+LEVEL+"/"+language, key_prefix=language+"_"))
print(len(images_train))
images_test = read_all(".. /input/level_4b_test/kaggle_"+LEVEL, key_prefix='')
 print(len(images_test))<normalization>
ncat_X['GOODS_BIGGER_CREDIT'] = np.where(ncat_X.AMT_GOODS_PRICE > ncat_X.AMT_CREDIT, 1, 0)
 ncat_X['AMOUNT_NOT_CREDIT'] = ncat_X.AMT_CREDIT - ncat_X.AMT_GOODS_PRICE
ncat_X.head(20 )
scaler = StandardScaler()
X_scaled_train = scaler.fit_transform(X_train)
 X_scaled_test = scaler.transform(X_test )<choose_model_class>
ncat_X['AMT_INCOME_TOTAL'] = np.log(ncat_X.AMT_INCOME_TOTAL )
kfold = KFold(5, True, 10)
<find_best_model_class>
ncat_X['AMT_CREDIT'] = np.log(ncat_X.AMT_CREDIT )
sn_ce = SigmoidNeuron()
for train, test in kfold.split(X_scaled_train,Y_train):
sn_ce.fit(X_scaled_train[train], Y_train[train], epochs=500, learning_rate=0.00002, loss_fn="ce", display_loss=True,initialise=False)
 Y_pred_train = sn_ce.predict(X_scaled_train[test])
 Y_pred_binarised_train =(Y_pred_train >= 0.5 ).astype("int" ).ravel()
accuracy_train = accuracy_score(Y_pred_binarised_train, Y_train[test])
 print("Train Accuracy : ", accuracy_train)
 print("-"*50)
<predict_on_test>
ncat_X['AMT_ANNUITY'] = np.log(ncat_X.AMT_ANNUITY )
def print_accuracy(sn):
Y_pred_train = sn.predict(X_scaled_train)
 Y_pred_binarised_train =(Y_pred_train >= 0.5 ).astype("int" ).ravel()
accuracy_train = accuracy_score(Y_pred_binarised_train, Y_train)
 print("Train Accuracy : ", accuracy_train)
 print("-"*50 )<compute_test_metric>
ncat_X['AMT_GOODS_PRICE'] = np.log(ncat_X.AMT_GOODS_PRICE )
print_accuracy(sn_ce )<save_to_csv>
ncat_X['DAYS_BIRTH'] = ncat_X.DAYS_BIRTH.apply(lambda x: x/-365)
 ncat_X['DAYS_EMPLOYED'] = ncat_X.DAYS_EMPLOYED.apply(lambda x: x/-365)
 ncat_X['DAYS_REGISTRATION'] = ncat_X.DAYS_REGISTRATION.apply(lambda x: x/-365)
 ncat_X['DAYS_ID_PUBLISH'] = ncat_X.DAYS_ID_PUBLISH.apply(lambda x: x/-365)
 ncat_X['DAYS_LAST_PHONE_CHANGE'] = ncat_X.DAYS_LAST_PHONE_CHANGE.apply(lambda x: x/-365)
 ncat_X.head()
Y_pred_test = sn_ce.predict(X_scaled_test)
 Y_pred_binarised_test =(Y_pred_test >= 0.5 ).astype("int" ).ravel()
submission = {}
submission['ImageId'] = ID_test
submission['Class'] = Y_pred_binarised_test
submission = pd.DataFrame(submission)
 submission = submission[['ImageId', 'Class']]
submission = submission.sort_values(['ImageId'])
 submission.to_csv("submisision.csv", index=False )<set_options>

 for x in cat_X.columns.values:
print(x)
 keys = cat_X[x].unique()
dicts = dict(zip(keys, range(len(keys))))
cat_X[x] = cat_X[x].map(dicts ).astype(int)
 cat_X.head()
warnings.simplefilter("ignore")
 np.random.seed(100)
 LEVEL = 'level_4b'<compute_test_metric>
cat_X = pd.concat([SK_ID, cat_X], axis=1 )
class SigmoidNeuron:
def __init__(self):
self.w = None
self.b = None
def perceptron(self, x):
return np.dot(x, self.w.T)+ self.b
def sigmoid(self, x):
return 1.0/(1.0 + np.exp(-x))
def grad_w_mse(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
return(y_pred - y)* y_pred *(1 - y_pred)* x
def grad_b_mse(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
return(y_pred - y)* y_pred *(1 - y_pred)
 def grad_w_ce(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
if y == 0:
return y_pred * x
elif y == 1:
return -1 *(1 - y_pred)* x
else:
raise ValueError("y should be 0 or 1")
 def grad_b_ce(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
if y == 0:
return y_pred
elif y == 1:
return -1 *(1 - y_pred)
 else:
raise ValueError("y should be 0 or 1")
 def fit(self, X, Y, epochs=1, learning_rate=1, initialise=True, loss_fn="mse", display_loss=False):
if initialise:
self.w = X.mean(axis=0)
 self.b = 0
if display_loss:
loss = {}
for i in tqdm_notebook(range(epochs), total=epochs, unit="epoch"):
dw = 0
db = 0
for x, y in zip(X, Y):
if loss_fn == "mse":
dw += self.grad_w_mse(x, y)
 db += self.grad_b_mse(x, y)
 self.w -= learning_rate * dw
self.b -= learning_rate * db
elif loss_fn == "ce":
dw += self.grad_w_ce(x, y)
 db += self.grad_b_ce(x, y)
 self.w -= learning_rate * dw
self.b -= learning_rate * db
if display_loss:
Y_pred = self.sigmoid(self.perceptron(X))
if loss_fn == "mse":
loss[i] = mean_squared_error(Y, Y_pred)
 flag = loss[i]
elif loss_fn == "ce":
loss[i] = log_loss(Y, Y_pred)
 flag = loss[i]
if display_loss:
plt.plot(loss.values())
 plt.xlabel('Epochs')
 if loss_fn == "mse":
plt.ylabel('Mean Squared Error')
 elif loss_fn == "ce":
plt.ylabel('Log Loss')
 plt.show()
min_key = min(loss, key=loss.get)
 print(min_key)
 print(loss.get(min_key))
print(i)
 def predict(self, X):
Y_pred = []
for x in X:
y_pred = self.sigmoid(self.perceptron(x))
Y_pred.append(y_pred)
 return np.array(Y_pred )<load_pretrained>
X = ncat_X.merge(cat_X, how='left', on='SK_ID_CURR' )
languages = ['en','ta', 'hi']
images_train = read_all(".. /input/"+LEVEL+"_train/"+LEVEL+"/"+"background", key_prefix='bgr_')
 for language in languages:
images_train.update(read_all(".. /input/"+LEVEL+"_train/"+LEVEL+"/"+language, key_prefix=language+"_"))
print(len(images_train))
images_test = read_all(".. /input/"+LEVEL+"_test/kaggle_"+LEVEL, key_prefix='')
 print(len(images_test))<define_variables>
gc.enable()
del ncat_X
del cat_X
gc.collect()
X_train = []
Y_train = []
ID_train = []
for key, value in images_train.items() :
X_train.append(value)
 ID_train.append(key)
 if key[:4] == "bgr_":
Y_train.append(0)
 else:
Y_train.append(1)
 ID_test = []
X_test = []
for key, value in images_test.items() :
ID_test.append(int(key))
X_test.append(value)
 X_train = np.array(X_train)
 Y_train = np.array(Y_train)
 X_test = np.array(X_test)
 print(X_train.shape, Y_train.shape)
 print(X_test.shape )<normalization>
credit_card_balance = pd.read_csv('.. /input/credit_card_balance.csv')
 credit_card_balance.head()
scaler = StandardScaler()
X_scaled_train = scaler.fit_transform(X_train)
 X_scaled_test = scaler.transform(X_test )<train_model>
credit_card_balance['NAME_CONTRACT_STATUS'] = pd.get_dummies(credit_card_balance['NAME_CONTRACT_STATUS'])
 credit_card_balance = credit_card_balance.fillna(0)
 credit_card_balance.head(10 )
sn_ce = SigmoidNeuron()
sn_ce.fit(X_scaled_train, Y_train, epochs=100, learning_rate=1,initialise=True,loss_fn="ce",display_loss=True)
 sn_ce.fit(X_scaled_train, Y_train, epochs=200, learning_rate=0.1,initialise=False,loss_fn="ce",display_loss=True)
 sn_ce.fit(X_scaled_train, Y_train, epochs=200, learning_rate=0.01,initialise=False,loss_fn="ce" ,display_loss=True)
 sn_ce.fit(X_scaled_train, Y_train, epochs=300, learning_rate=0.001,initialise=False,loss_fn="ce",display_loss=True)
 sn_ce.fit(X_scaled_train, Y_train, epochs=500, learning_rate=0.0001,initialise=False,loss_fn="ce",display_loss=True)
 sn_ce.fit(X_scaled_train, Y_train, epochs=800, learning_rate=0.00001,initialise=False,loss_fn="ce",display_loss=True)
 sn_ce.fit(X_scaled_train, Y_train, epochs=1000, learning_rate=0.000005,initialise=False,loss_fn="ce",display_loss=True )<predict_on_test>
ID_PREV = credit_card_balance[['SK_ID_CURR', 'SK_ID_PREV']].groupby('SK_ID_CURR' ).count()
credit_card_balance['SK_ID_PREV'] = credit_card_balance['SK_ID_CURR'].map(ID_PREV['SK_ID_PREV'] )
def print_accuracy(sn):
Y_pred_train = sn.predict(X_scaled_train)
 Y_pred_binarised_train =(Y_pred_train >= 0.5 ).astype("int" ).ravel()
accuracy_train = accuracy_score(Y_pred_binarised_train, Y_train)
 print("Train Accuracy : ", accuracy_train)
 print("-"*50)
 mismatch_name = []
for x,y,z in zip(Y_pred_binarised_train, Y_train, ID_train):
if(x!=y):
mismatch_name.append(z)
 print(mismatch_name )<compute_test_metric>
credit_card_mean = credit_card_balance.groupby('SK_ID_CURR' ).mean()
credit_card_mean.columns = ['cc_' + col for col in credit_card_mean.columns]
credit_card_mean = credit_card_mean.reset_index()
credit_card_mean.head()
print_accuracy(sn_ce )<save_to_csv>
X = X.merge(right=credit_card_mean, how='left', on='SK_ID_CURR')
 X.head(10 )
Y_pred_test = sn_ce.predict(X_scaled_test)
 Y_pred_binarised_test =(Y_pred_test >= 0.5 ).astype("int" ).ravel()
submission = {}
submission['ImageId'] = ID_test
submission['Class'] = Y_pred_binarised_test
submission = pd.DataFrame(submission)
 submission = submission[['ImageId', 'Class']]
submission = submission.sort_values(['ImageId'])
 submission.to_csv("submisision.csv", index=False )<compute_test_metric>
gc.enable()
del credit_card_balance
del credit_card_mean
gc.collect()
class SigmoidNeuron:
def __init__(self):
self.w = None
self.b = None
self.best_epoch = 0
def perceptron(self, x):
return np.dot(x, self.w.T)+ self.b
def sigmoid(self, x):
return 1.0/(1.0 + np.exp(-x))
def grad_w_mse(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
return(y_pred - y)* y_pred *(1 - y_pred)* x
def grad_b_mse(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
return(y_pred - y)* y_pred *(1 - y_pred)
 def grad_w_ce(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
if y == 0:
return y_pred * x
elif y == 1:
return -1 *(1 - y_pred)* x
else:
raise ValueError("y should be 0 or 1")
 def grad_b_ce(self, x, y):
y_pred = self.sigmoid(self.perceptron(x))
if y == 0:
return y_pred
elif y == 1:
return -1 *(1 - y_pred)
 else:
raise ValueError("y should be 0 or 1")
 def fit(self, X, Y, epochs=1, learning_rate=1, initialise=True, loss_fn="mse", display_loss=False):
if initialise:
self.w = np.random.randn(1, X.shape[1])
 self.b = 0
loss = {}
best_w = self.w.copy()
best_b = 0
best_loss = 999
best_epoch = 1
for i in tqdm_notebook(range(epochs), total=epochs, unit="epoch"):
dw = 0
db = 0
for x, y in zip(X, Y):
if loss_fn == "mse":
dw += self.grad_w_mse(x, y)
 db += self.grad_b_mse(x, y)
 elif loss_fn == "ce":
dw += self.grad_w_ce(x, y)
 db += self.grad_b_ce(x, y)
 self.w -= learning_rate * dw
self.b -= learning_rate * db
Y_pred = self.sigmoid(self.perceptron(X))
if loss_fn == "mse":
loss[i] = mean_squared_error(Y, Y_pred)
 elif loss_fn == "ce":
loss[i] = log_loss(Y, Y_pred)
 if best_loss == 999:
best_loss = loss[i]
best_w = self.w.copy()
best_b = self.b
best_epoch = i
elif loss[i] < best_loss:
best_loss = loss[i]
best_w = self.w.copy()
best_b = self.b
best_epoch = i
self.w = best_w.copy()
self.b = best_b
self.best_epoch = best_epoch
if display_loss:
plt.plot(loss.values())
 plt.xlabel('Epochs')
 if loss_fn == "mse":
plt.ylabel('Mean Squared Error')
 elif loss_fn == "ce":
plt.ylabel('Log Loss')
 plt.show()
def predict(self, X):
Y_pred = []
for x in X:
y_pred = self.sigmoid(self.perceptron(x))
Y_pred.append(y_pred)
 return np.array(Y_pred )<define_search_space>
POS_CASH_balance = pd.read_csv('.. /input/POS_CASH_balance.csv')
 POS_CASH_balance.head()
a = np.array([1,2,3])
 c = list(a)
 print(a)
 print(c)
 b = [(lambda x: 0 if x < 2 else 255 )(x)for x in c]
print(b )<load_pretrained>
POS_CASH_balance['NAME_CONTRACT_STATUS'] = pd.get_dummies(POS_CASH_balance['NAME_CONTRACT_STATUS'])
 POS_CASH_balance = POS_CASH_balance.fillna(0 )
languages = ['ta', 'hi', 'en']
images_train = read_all(".. /input/level_4b_train/level_4b/" + "background/", key_prefix='bgr_')
 for language in languages:
images_train.update(read_all(".. /input/level_4b_train/level_4b/"+language, key_prefix=language+"_"))
print(len(images_train))
images_test = read_all(".. /input/level_4b_test/kaggle_level_4b/", key_prefix='')
 print(len(images_test))<categorify>
pcb_count = POS_CASH_balance[['SK_ID_CURR', 'SK_ID_PREV']].groupby('SK_ID_CURR' ).count()
POS_CASH_balance['SK_ID_PREV'] = POS_CASH_balance['SK_ID_CURR'].map(pcb_count['SK_ID_PREV'] )
a = np.array(( [1,2],[3,4]), dtype = int)
 print(a)
 b = a.flatten()
print(b)
 c = b.reshape(2,-1)
 print(c)
<normalization>
pos_cash_mean = POS_CASH_balance.groupby('SK_ID_CURR' ).mean()
pos_cash_mean.columns = ['pc_' + col for col in pos_cash_mean.columns]
pos_cash_mean = pos_cash_mean.reset_index()
pos_cash_mean.head()
scaler = StandardScaler()
X_scaled_train = scaler.fit_transform(X_train)
 X_scaled_test = scaler.transform(X_test)
<train_model>
X = X.merge(right=pos_cash_mean, how='left', on='SK_ID_CURR')
 X.shape
sn_mse = SigmoidNeuron()
sn_mse.fit(X_scaled_train, Y_train, epochs=100, learning_rate=0.015, loss_fn="mse", display_loss=True )<train_model>
gc.enable()
del POS_CASH_balance
del pos_cash_mean
gc.collect()
sn_ce = SigmoidNeuron()
sn_ce.fit(X_scaled_train, Y_train, epochs=10000, learning_rate=0.000005, loss_fn="ce", display_loss=True )<predict_on_test>
bureau = pd.read_csv('.. /input/bureau.csv')
 bureau.head()
def print_accuracy(sn):
Y_pred_train = sn.predict(X_scaled_train)
 Y_pred_binarised_train =(Y_pred_train >= 0.5 ).astype("int" ).ravel()
accuracy_train = accuracy_score(Y_pred_binarised_train, Y_train)
 print("Train Accuracy : ", accuracy_train)
 print("-"*50 )<compute_test_metric>
bureau_mean = bureau.groupby('SK_ID_CURR' ).mean()
bureau_mean['buro_count'] = bureau[['SK_ID_CURR', 'SK_ID_BUREAU']].groupby('SK_ID_CURR' ).count() ['SK_ID_BUREAU']
bureau_mean.columns = ['b_' + col for col in bureau_mean.columns]
X = X.merge(right=bureau_mean.reset_index() , how='left', on='SK_ID_CURR')
 X.shape
print_accuracy(sn_ce )<create_dataframe>
gc.enable()
del bureau
del bureau_mean
gc.collect()
<save_to_csv>
previous_application = pd.read_csv('.. /input/previous_application.csv')
 previous_application.head()
Y_pred_test = sn_ce.predict(X_scaled_test)
 Y_pred_binarised_test =(Y_pred_test >= 0.5 ).astype("int" ).ravel()
submission = {}
submission['ImageId'] = ID_test
submission['Class'] = Y_pred_binarised_test
submission = pd.DataFrame(submission)
 submission = submission[['ImageId', 'Class']]
submission = submission.sort_values(['ImageId'])
 submission.to_csv("submisision.csv", index=False )<load_from_csv>
previous_app_mean = previous_application.groupby('SK_ID_CURR' ).mean()
previous_app_mean['SK_ID_PREV'] = previous_application[['SK_ID_CURR', 'SK_ID_PREV']].groupby('SK_ID_CURR' ).count() ['SK_ID_PREV']
previous_app_mean.columns = ['pa_' + col for col in previous_app_mean.columns]
previous_app_mean.head()
train = pd.read_csv('.. /input/csm6420-workshop/train.csv')
 test = pd.read_csv('.. /input/csm6420-workshop/test.csv',index_col=0)
 print(train.head())
 print(test.head())
<prepare_x_and_y>
X = X.merge(right=previous_app_mean.reset_index() , how='left', on='SK_ID_CURR')
 X.shape
X = train.drop('Class', axis=1)
 y = train['Class']
print(y )<find_best_model_class>
gc.enable()
del previous_app_mean
del previous_application
gc.collect()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)
 model = GaussianNB()
y_pred = model.fit(X_train, y_train ).predict(X_test)
 print("Number of mislabeled points out of a total %d points : %d" %(X_test.shape[0],(y_test != y_pred ).sum()))<load_from_csv>
installments_payments = pd.read_csv('.. /input/installments_payments.csv')
 installments_payments.head()
sample = pd.read_csv('.. /input/csm6420-workshop/sampleSubmission.csv')
 print(sample.head() )<save_to_csv>
install_pay_mean = installments_payments.groupby('SK_ID_CURR' ).mean()
install_pay_mean['SK_ID_PREV'] = installments_payments[['SK_ID_CURR','SK_ID_PREV']].groupby('SK_ID_CURR' ).count() ['SK_ID_PREV']
install_pay_mean.columns = ['ip_' + col for col in install_pay_mean.columns]
X = X.merge(right=install_pay_mean.reset_index() , how='left', on='SK_ID_CURR' )
y_pred = model.predict(test.values)
 results = pd.DataFrame()
results["TestId"] = test.index.values
results["PredictedScore"]= y_pred
results.to_csv("submission.csv", index=False )<import_modules>
gc.enable()
del installments_payments
del install_pay_mean
gc.collect()
from fastai.vision import *<load_from_csv>
X_train, X_test, y_train, y_test = train_test_split(df_train, y, test_size=0.2, random_state=123 )
path = Path(".. /input")
 train_path = path/"train/train"
test_path = path/"test/test"
sub_df = pd.read_csv(f"{path}/sample_submission.csv")
 test_df = pd.read_csv(f"{path}/sample_submission.csv" )<feature_engineering>
lgb_train = lgb.Dataset(data=X_train, label=y_train)
 lgb_test = lgb.Dataset(data=X_test, label=y_test )
train = get_image_files(train_path)
 test = get_image_files(test_path )<load_pretrained>
params = {'task': 'train', 'boosting_type': 'gbdt', 'objective': 'binary', 'metric': 'auc',
'learning_rate': 0.01, 'num_leaves': 48, 'num_iteration': 5000, 'verbose': 0 ,
'colsample_bytree':.8, 'subsample':.9, 'max_depth':7, 'reg_alpha':.1, 'reg_lambda':.1,
'min_split_gain':.01, 'min_child_weight':1}
model = lgb.train(params, lgb_train, valid_sets=lgb_test, early_stopping_rounds=150, verbose_eval=200 )
data= ImageDataBunch.from_folder(train_path,valid_pct = 0.2,test = test_path,ds_tfms = get_transforms() ,size = 224 ).normalize()
data.add_test(ImageList.from_df(test_df, path, folder="test/test"))<define_variables>
lgb_preds = model.predict(df_test )
data.show_batch()<choose_model_class>
df_test['TARGET'] = lgb_preds
<find_best_params><EOS> 
lgb_pred = df_test[['SK_ID_CURR', 'TARGET']].to_csv('LGB_prediction2.csv', index=False )