Kaggle competition: SIIM-ISIC Melanoma Classification
<SOS> metric: MCAUC Kaggle data source: siim-isic-melanoma-classification<categorify>
dir = '.. /input/e6-oof-prediction//'
np.random.seed(42)
 oof_one = pd.read_csv(dir + 'oof_e6_exp1_seed_42.csv')
 test_one = pd.read_csv(dir + 's_e6_exp1_seed_42.csv')
 oof_one = oof_one.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 test_one = test_one.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 oof_two = pd.read_csv(dir + 'oof_e6_exp2_seed_42.csv')
 test_two = pd.read_csv(dir + 's_e6_exp2_seed_42.csv')
 oof_two = oof_two.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 test_two = test_two.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 oof_three = pd.read_csv(dir + 'oof_e6_exp3_seed_42.csv')
 test_three = pd.read_csv(dir + 's_e6_exp3_seed_42.csv')
 oof_three = oof_three.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 test_three = test_three.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 oof_four = pd.read_csv(dir + 'oof_e6_exp4_seed_42.csv')
 test_four = pd.read_csv(dir + 's_e6_exp4_seed_42.csv')
 oof_four = oof_four.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True)
 test_four = test_four.sort_values(by=['image_name'],
ascending=True ).reset_index(drop=True )
train=pd.get_dummies(train,columns=["Fare_bin","Age_bin"])
 test=pd.get_dummies(test,columns=["Fare_bin","Age_bin"])
 train.head()<drop_column>
oof_one.fold.value_counts()
train.drop(["Age","Fare","Ticket"],axis=1,inplace=True)
 test.drop(["Age","Fare","Ticket"],axis=1,inplace=True)
 train.head()<data_type_conversions>
blend_train = []
blend_test = []
blend_train.append(oof_one.pred)
 blend_train.append(oof_two.pred)
 blend_train.append(oof_three.pred)
 blend_train.append(oof_four.pred)
 blend_train = np.array(blend_train)
 blend_test.append(test_one.target)
 blend_test.append(test_two.target)
 blend_test.append(test_three.target)
 blend_test.append(test_four.target)
 blend_test = np.array(blend_test )
print(train["Cabin"].values.tolist() )<feature_engineering>
def roc_min_func(weights):
final_prediction = 0
for weight, prediction in zip(weights, blend_train):
final_prediction += weight * prediction
return roc_auc_score(np.array(oof_one.target), final_prediction)
 print('
Finding Blending Weights...')
 res_list = []
weights_list = []
for k in range(100):
starting_values = np.random.uniform(size=len(blend_train))
bounds = [(0, 1)] * len(blend_train)
 res = minimize(roc_min_func,
starting_values,
method='L-BFGS-B',
bounds=bounds,
options={'disp': False,
'maxiter': 100000})
 res_list.append(res['fun'])
 weights_list.append(res['x'])
 print('{iter}\tScore: {score}\tWeights: {weights}'.format(
 iter=(k + 1),
score=res['fun'],
weights='\t'.join([str(item)for item in res['x']])))
 bestSC = np.max(res_list)
 bestWght = weights_list[np.argmax(res_list)]
weights = bestWght
blend_score = round(bestSC, 6 )
train["Cabin_encoding"]=train["Pclass"]
for i in range(len(train)) :
if(train["Cabin"].loc[i]=="NC"):
train["Cabin_encoding"].loc[i]=1000
else:
if(len(train["Cabin"].loc[i])>4):
train["Cabin_encoding"].loc[i]=500
elif(len(train["Cabin"].loc[i])>1):
temp=train["Cabin"].loc[i]
train["Cabin_encoding"].loc[i]=(ord(temp[0])-ord('A')) *125+int(temp[1:])
 else:
temp=train["Cabin"].loc[i]
train["Cabin_encoding"].loc[i]=min(( ord(temp[0])-ord('A')) *125,1000)
 train[["Cabin","Cabin_encoding"]].head()<feature_engineering>
print('
Ensemble Score: {best_score}'.format(best_score=bestSC))
print('
Best Weights: {weights}'.format(weights=bestWght))
train_prices = np.zeros(len(blend_train[0]))
test_prices = np.zeros(len(blend_test[0]))
print('
Your final model:')
 for k in range(len(blend_test)) :
print(' %.6f * model-%d' %(weights[k],(k + 1)))
 test_prices += blend_test[k] * weights[k]
for k in range(len(blend_train)) :
train_prices += blend_train[k] * weights[k]
test["Cabin_encoding"]=test["Pclass"]
for i in range(len(test)) :
if(test["Cabin"].loc[i]=="NC"):
test["Cabin_encoding"].loc[i]=1000
else:
if(len(test["Cabin"].loc[i])>4):
test["Cabin_encoding"].loc[i]=500
elif(len(test["Cabin"].loc[i])>1):
temp=test["Cabin"].loc[i]
test["Cabin_encoding"].loc[i]=(ord(temp[0])-ord('A')) *125+int(temp[1:])
 else:
temp=test["Cabin"].loc[i]
test["Cabin_encoding"].loc[i]=min(( ord(temp[0])-ord('A')) *125,1000 )<drop_column>
test_one.target =(test_one.target.values*bestWght[0] +
test_two.target.values*bestWght[1] +
test_three.target.values*bestWght[2]+
test_four.target.values*bestWght[3])/max(bestWght )
train.drop("Cabin",axis=1,inplace=True)
 train.head()<drop_column>
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' )
test.drop("Cabin",axis=1,inplace=True)
 test.head()<feature_engineering>
dirname = '/kaggle/input/e6-oof-prediction'
prefix = ['exp1', 'exp2', 'exp3', 'exp4', ]
for model in range(4):
_oof = pd.read_csv(os.path.join(dirname, f"oof_e6_{prefix[model]}_seed_42.csv"))
score = roc_auc_score(_oof['target'], _oof['pred'])
 print(f"{prefix[model]}: OOF auc:{score:.4}")
 _oof = _oof.rename(columns={"pred":prefix[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, f"s_e6_{prefix[model]}_seed_42.csv"))
_sub.columns = ["image_name", prefix[model]]
test = test.merge(_sub, on="image_name" )
<feature_engineering><EOS> 
def bo_pred(df):
x =(c0*df[ prefix[0] ] +
c1*df[ prefix[1] ] +
c2*df[ prefix[2] ] +
c3*df[ prefix[3] ])
 return x
train["pred"] = bo_pred(train)
 score = roc_auc_score(train['target'], train['pred'])
 print(f"auc bo:{score}" )