Kaggle competition: SIIM-ISIC Melanoma Classification
<SOS> metric: MCAUC Kaggle data source: siim-isic-melanoma-classification<categorify>
train = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/train.csv')
 test = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/test.csv')
 sub = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/sample_submission.csv')
data['DeckCode'] =(data['Cabin'] 
.str.slice(0,1)
.map({
'C':1,
'E':2,
'G':3,
'D':4,
'A':5,
'B':6,
'F':7,
})
.fillna(0)
.astype(int))
data[['DeckCode', 'Survived']].groupby(['DeckCode'] ).agg(['count','mean'] )<categorify>
models = [ "getting-started-with-tfrecords", "melanoma-efficientnetb6-with-attention-mechanism", "triple-stratified-kfold-with-tfrecords"]
models = ["384-E6-with-2018","512-E6","768-E2","512-E5","effb3-fulldata-upsample","effb2-fulldata-upsample"]
models = ["effb0-fulldata-upsample","effb1-fulldata-upsample","effb2-512-fulldata-upsample","effb3-fulldata-upsample","effb4-fulldata-upsample","effb5-fulldata-upsample"]
models = ["effb1-fulldata-upsample",
"melanoma-efficientnetb6-with-attention-mechanism",
"effb2-fulldata-upsample",
"effb4-fulldata-upsample",
"384-E6-with-2018",
"effb0-fulldata-upsample"]
models = ["384-E6-with-2018","512-E6","768-E2","512-E5","effb2-512-fulldata-upsample",
"effb1-fulldata-upsample"]
for model in models:
dirname = "/kaggle/input/siim3reorg/" + model
_oof = pd.read_csv(os.path.join(dirname, "oof.csv"))
score = metrics.roc_auc_score(_oof['target'], _oof['pred'])
 print(f"{model}: OOF auc:{score:.4}")
 _oof = _oof.rename(columns={"pred":model} ).drop(["target"],axis=1)
 if "fold" in _oof.columns:
_oof = _oof.drop(["fold"],axis=1)
 train = train.merge(_oof, on="image_name")
 _sub = pd.read_csv(os.path.join(dirname, "submission.csv"))
_sub.columns = ["image_name",model]
test = test.merge(_sub, on="image_name")
data['Room'] =(data['Cabin'] 
.str.slice(1,5 ).str.extract('([0-9]+)', expand=False)
.fillna(0)
.astype(int))
data['RoomBand'] = 0
data.loc[(data.Room > 0)&(data.Room <= 20), 'RoomBand'] = 1
data.loc[(data.Room > 20)&(data.Room <= 40), 'RoomBand'] = 2
data.loc[(data.Room > 40)&(data.Room <= 80), 'RoomBand'] = 3
data.loc[data.Room > 80, 'RoomBand'] = 4
data[['RoomBand', 'Survived']].groupby(['RoomBand'] ).agg(['count','mean'] )<feature_engineering>
train["pred_rank"] = 0
train["pred_power"] = 0
train["pred_avg"] = 0
for c in models:
train["pred_rank"] += train[c].rank() / train[c].rank().max()
train["pred_power"] += np.power(train[c],2)/np.power(train[c],2 ).max()
train["pred_avg"] += train [c]/train [c].max()
train["pred_rank"] = train["pred_rank"]/len(models)
 train["pred_power"] = train["pred_power"]/len(models)
 train["pred_avg"] = train["pred_avg"]/len(models)
 score = metrics.roc_auc_score(train['target'], train["pred_avg"])
 print(f'OOF avg_auc:{score}')
 score = metrics.roc_auc_score(train['target'], train["pred_rank"])
 print(f'OOF rank_auc:{score}')
 score = metrics.roc_auc_score(train['target'], train["pred_power"])
 print(f'OOF pow_auc:{score}' )
data.loc[data.Ticket=='LINE', 'Ticket'] = 'LINE1'<data_type_conversions>
test["target"] = 0.0
for c in models:
test["target"] += test[c].rank() / test[c].rank().max()
test["target"] = test["target"]/len(models)
 sub = test[["image_name","target"]]
sub.to_csv("submission_rank.csv",index=False)
 sub.head()
data['Odd'] =(data['Ticket'] 
.str.slice(-1)
.astype(int)
.map(lambda x: x % 2 == 0)
.astype(int)
)
 data[['Odd', 'Survived']].groupby(['Odd'] ).agg(['count','mean'] )<data_type_conversions>
test["target"] = 0.0
for c in models:
test["target"] += np.power(test[c],2)/np.power(test[c],2 ).max()
test["target"] = test["target"]/len(models)
 sub = test[["image_name","target"]]
sub.to_csv("submission_pow.csv",index=False)
 sub.head()
data['FamilySize'] =(data['SibSp'] + data['Parch'] ).astype(int)
 data[['FamilySize', 'Survived']].groupby(['FamilySize'] ).agg(['count','mean'] )<groupby>
test["target"] = 0.0
for c in models:
test["target"] += test[c]/test[c].max()
test["target"] = test["target"]/len(models)
 sub = test[["image_name","target"]]
sub.to_csv("submission_avg.csv",index=False)
 sub.head()
data[['Sex', 'Survived']].groupby(['Sex'] ).agg(['count','mean'] )<feature_engineering>
def dim_optimizer(df_oof, features, init_points = 20, n_iter = 30):
pbounds = {'c0':(0.0, 1.0), 'c1':(0.0, 1.0), 'c2':(0.0, 1.0),'c3':(0.0, 1.0),'c4':(0.0, 1.0),'c5':(0.0, 1.0)}
features = features
def dim_opt(df_oof, c0,c1,c2,c3,c4,c5):
x = c0*df_oof[ features[0] ] + c1*df_oof[ features[1]] + c2*df_oof[ features[2]] + c3*df_oof[ features[3]] + c4*df_oof[ features[4]] + c5*df_oof[ features[5]]
return metrics.roc_auc_score(df_oof['target'], x)
 def q(c0, c1,c2,c3,c4,c5):
return dim_opt(df_oof, c0, c1,c2,c3,c4,c5)
 optimizer = BayesianOptimization(
 f=q,
pbounds=pbounds,
random_state=42, 
)
 optimizer.maximize(
 init_points=init_points,
n_iter=n_iter, 
)
 c0 = optimizer.max["params"]["c0"]
c1 = optimizer.max["params"]["c1"]
c2= optimizer.max["params"]["c2"]
c3= optimizer.max["params"]["c3"]
c4= optimizer.max["params"]["c4"]
c5= optimizer.max["params"]["c5"]
t = optimizer.max["target"]
print(f'bo auc:{t}, c0:{c0}, c1:{c1}, c2:{c2},c3:{c3},c4:{c4},c5:{c5}')
 return c0, c1, c2,c3,c4,c5
c0, c1, c2,c3,c4,c5 = dim_optimizer(train, models, init_points = 40, n_iter = 40)
 print(models[0],c0)
 print(models[1],c1)
 print(models[2],c2)
 print(models[3],c3)
 print(models[4],c4)
 print(models[5],c5)
data['FamilySizeBand'] = 0
data.loc[(data.FamilySize == 1), 'FamilySizeBand'] = 1
data.loc[(data.FamilySize == 2), 'FamilySizeBand'] = 2
data.loc[(data.FamilySize == 3), 'FamilySizeBand'] = 2
data.loc[data.FamilySize > 3, 'FamilySizeBand'] = 2
data[['FamilySizeBand', 'Survived']].groupby(['FamilySizeBand'] ).agg(['count','mean'] )<categorify>
def bo_pred(df):
x = c0*df[ models[0] ] + c1*df[ models[1]] + c2*df[ models[2]] + c3*df[ models[3]] + c4*df[ models[4]] + c5*df[ models[5]]
return x
train["pred"] = bo_pred(train)
 score = metrics.roc_auc_score(train['target'], train['pred'])
 print(f"auc bo:{score}")
data['IsAlone'] =(data['SibSp'] + data['Parch'] == 0 ).astype(int)
 data[['IsAlone', 'Survived']].groupby(['IsAlone'] ).agg(['count','mean'] )<categorify>
test["target"] = bo_pred(test)
 sub = test[["image_name","target"]]
sub.to_csv("submission_bo.csv",index=False)
 sub.head()