Kaggle competition: SIIM-ISIC Melanoma Classification
c.iloc[:,3:] = Imputer(strategy="most_frequent" ).fit_transform(c.iloc[:,3:])
 dep = c[c["is_test"] == False].loc[:, ["Survived"]]
indep = c[c["is_test"] == False].iloc[:, 3:]
res = c[c["is_test"] == True].iloc[:, 3:]
res_index = c[c["is_test"] == True].loc[:, "PassengerId"]
indep.iloc[:,3:] = StandardScaler().fit_transform(indep.iloc[:,3:])
 res.iloc[:,3:] = StandardScaler().fit_transform(res.iloc[:,3:])
 indep_train, indep_test, dep_train, dep_test = train_test_split(indep, dep, test_size=0.40, random_state=47 )<choose_model_class>
LABELS = ["target"]
all_files = glob.glob(".. /input/pseudolabelmodels/*.csv" )
with tf.device('/device:CPU:0'):
gs1 = Sequential()
gs1.add(Dense(45 ,activation='linear', input_dim=45))
gs1.add(BatchNormalization())
 gs1.add(Dense(9,activation='linear'))
gs1.add(BatchNormalization())
 gs1.add(Dropout(0.4))
gs1.add(Dense(5,activation='linear'))
gs1.add(BatchNormalization())
 gs1.add(Dropout(0.2))
gs1.add(Dense(1,activation='relu',))
gs1.compile(optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0), loss='binary_crossentropy', metrics=['accuracy'])
 gs1.fit(indep_train, dep_train, epochs=500, batch_size=30, validation_data=(indep_test,dep_test), verbose=False)
 g=gs1.predict_classes(res)[:,0]
print(accuracy_score(dep_test, gs1.predict_classes(indep_test)) , accuracy_score(dep_train, gs1.predict_classes(indep_train)) )<prepare_x_and_y>
outs = [pd.read_csv(f, index_col=0)for f in all_files]
concat_sub = pd.concat(outs, axis=1)
 cols = list(map(lambda x: "m" + str(x), range(len(concat_sub.columns))))
concat_sub.columns = cols
concat_sub.reset_index(inplace=True )
cvscores = []
data = pd.DataFrame()
i=1
with tf.device('/device:CPU:0'):
for train, test in StratifiedKFold(n_splits=5, shuffle=True, random_state=1 ).split(indep, dep.iloc[:,0]):
X = indep.reindex().iloc[train,:]
Y = dep.reindex().iloc[train,0]
Xv = indep.reindex().iloc[test,:]
Yv = dep.reindex().iloc[test,0]
gs1 = Sequential()
gs1.add(Dense(45 ,activation='linear', input_dim=45))
gs1.add(BatchNormalization())
 gs1.add(Dense(9,activation='linear'))
gs1.add(BatchNormalization())
 gs1.add(Dropout(0.4))
gs1.add(Dense(5,activation='linear'))
gs1.add(BatchNormalization())
 gs1.add(Dropout(0.2))
gs1.add(Dense(1,activation='relu',))
gs1.compile(optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0), loss='binary_crossentropy', metrics=['accuracy'])
 gs1.fit(X, Y, epochs=500, batch_size=30, validation_data=(Xv, Yv), verbose=False)
 data[i] = gs1.predict_classes(res)[:,0]
scores = gs1.evaluate(Xv, Yv, verbose=0)
 print(gs1.metrics_names[1], scores[1])
 cvscores.append(scores[1])
 i+=1
mlp_mean = np.mean(cvscores)
 mlp_stdev = np.std(cvscores)
 print(mlp_mean, mlp_stdev)
 g = np.round(data.mean(axis=1))<train_on_grid>
warnings.filterwarnings("ignore")
 rank = np.tril(concat_sub.iloc[:,1:].corr().values,-1)
 m =(rank>0 ).sum()
m_gmean, s = 0, 0
for n in range(min(rank.shape[0],m)) :
mx = np.unravel_index(rank.argmin() , rank.shape)
 w =(m-n)/(m+n/10)
 m_gmean += w*(np.log(concat_sub.iloc[:,mx[0]+1])+np.log(concat_sub.iloc[:,mx[1]+1])) /2
s += w
rank[mx] = 1
m_gmean = np.exp(m_gmean/s ).clip(0.0,1.0 )
;<split>
predict_list = []
predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9350-pseudo-rohit.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9351-pseudo-rohit.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9373-pseudo-vova.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9376-pseudo-rohit.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9379-pseudo-rohit.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9432-pseudo-vova.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9474-pseudo-rohit.csv')[LABELS].values)
 predict_list_2 = []
predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9477-pseudo-ashish.csv')[LABELS].values)
 predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9491-pseudo-rohit.csv')[LABELS].values)
 predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-94981-pseudo-ashish.csv')[LABELS].values)
 predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-94982-pseudo-ashish.csv')[LABELS].values)
 predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9508-pseudo-rohit.csv')[LABELS].values)
 predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9513-pseudo-ashish.csv')[LABELS].values)
 predict_list_2.append(pd.read_csv('.. /input/pseudolabelmodels/submission-9547-pseudo-rohit.csv')[LABELS].values )
indep_train, indep_test, dep_train, dep_test = train_test_split(indep, dep, test_size=0.40, random_state=47)
 gs1 = lgb.LGBMClassifier(max_depth = 7,
lambda_l1 = 0.1,
lambda_l2 = 0.01,
learning_rate = 0.01,
n_estimators = 500, reg_alpha = 1.1, colsample_bytree = 0.9, subsample = 0.9,
n_jobs = 5)
 gs1.fit(indep_train, dep_train, eval_set=[(indep_test, dep_test)], eval_metric='accuracy', verbose=False, early_stopping_rounds=50);
g = gs1.predict(res)
 a = accuracy_score(dep_test, gs1.predict(indep_test))
b = accuracy_score(dep_train, gs1.predict(indep_train))
print(a, b )<split>
warnings.filterwarnings("ignore")
 print("Rank averaging on ", len(predict_list), " files")
 predictions = np.zeros_like(predict_list[0])
 for predict in predict_list:
for i in range(1):
predictions[:, i] = np.add(predictions[:, i], rankdata(predict[:, i])/predictions.shape[0])
 predictions = predictions /len(predict_list )
model = []
cvscores = []
for i in range(0,90):
indep_train, indep_test, dep_train, dep_test = train_test_split(indep, dep, test_size=0.40, random_state=i)
 gs1 = lgb.LGBMClassifier(max_depth = 7,
lambda_l1 = 0.1,
lambda_l2 = 0.01,
learning_rate = 0.01, num_iterations=20000,
n_estimators = 5000, reg_alpha = 1.1, colsample_bytree = 0.9, subsample = 0.9,
n_jobs = 5, boosting='dart')
 gs1.fit(indep_train, dep_train, eval_set=[(indep_test, dep_test)], eval_metric='accuracy', verbose=False, early_stopping_rounds=50);
model.append(gs1)
 cvscores.append(accuracy_score(dep_test, gs1.predict(indep_test)))
 data = pd.DataFrame()
te = pd.DataFrame()
for i in range(0,90):
data[i] = model[i].predict(res)
 te[i] = model[i].predict(indep_test)
 g = np.round(data.mean(axis=1))
t = np.round(te.mean(axis=1))
lgb_mean = np.mean(cvscores)
 lgb_stdev = np.std(cvscores)
 print(lgb_mean, lgb_stdev )<save_to_csv>
warnings.filterwarnings("ignore")
 print("Rank averaging on ", len(predict_list_2), " files")
 predictions_2 = np.zeros_like(predict_list_2[0])
 for predict_2 in predict_list_2:
for i in range(1):
predictions_2[:, i] = np.add(predictions_2[:, i], rankdata(predict_2[:, i])/predictions_2.shape[0])
 predictions_2 = predictions_2 /len(predict_list_2 )
<find_best_model_class><EOS> 
submission_1 = pd.read_csv('.. /input/siim-isic-melanoma-classification/sample_submission.csv')
 submission_1[LABELS] = predictions
submission_2 = pd.read_csv('.. /input/siim-isic-melanoma-classification/sample_submission.csv')
 submission_2[LABELS] = predictions_2
submission = pd.read_csv('.. /input/siim-isic-melanoma-classification/sample_submission.csv')
 submission[LABELS] = submission_2[LABELS]*.55 + submission_1[LABELS]*.45
submission.to_csv('submission.csv', index=False )