Kaggle competition: SIIM-ISIC Melanoma Classification
<SOS> metric: MCAUC Kaggle data source: siim-isic-melanoma-classification<choose_model_class>
f = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/sample_submission.csv')[['image_name']]
n = f.shape[0]
cols = {}
files = [os.path.join('/kaggle/input/melanoma', file)for file in os.listdir('/kaggle/input/melanoma')] + [os.path.join('/kaggle/input/melanoma-public', file)for file in os.listdir('/kaggle/input/melanoma-public')]
for i, filename in enumerate(files):
cols[filename] = f'target_{i}'
ff = pd.read_csv(filename)
 ff.columns = ['image_name', f'target_{i}']
ff[f'target_{i}'] = rankdata(ff[f'target_{i}'].values.tolist())
 ff[f'target_{i}'] = ff[f'target_{i}'].apply(lambda x:(x-1)/(n-1))
f = f.merge(ff, on='image_name' )
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0 )<choose_model_class>
f['target'] = f[cols.values() ].mean(axis=1)
 f[['image_name', 'target']].head()
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )<choose_model_class>
f[['image_name', 'target']].to_csv('submission.csv', index=False )
learning_rate_reduction = ReduceLROnPlateau(monitor='val_accuracy',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001 )<define_variables>
def calculate_mse(y, df):
for col in cols.values() :
df[col] =(df[col]-y)**2
return df.sum(axis=1)
 dic_errors = {}
for file, col in cols.items() :
y = f[col]
error = calculate_mse(y,f[cols.values() ])
 dic_errors[file] = error
epochs = 100
batch_size = 86<train_model>
err_df = pd.DataFrame(dic_errors ).transpose().sum(axis=1 ).sort_values(ascending=False)
 err_df
<init_hyperparams>
N=4
datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.1,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=False,
vertical_flip=False)
 datagen.fit(X_train )<train_model>
biggest_error = err_df.index.tolist() [:N]
history = model.fit_generator(datagen.flow(X_train,Y_train, batch_size=batch_size),
epochs = epochs, validation_data =(X_val,Y_val),
verbose = 1, steps_per_epoch=X_train.shape[0] // batch_size
, callbacks=[learning_rate_reduction] )<predict_on_test>
f[f'target_wo_{N}'] = f[[c for k,c in cols.items() if k not in biggest_error]].mean(axis=1)
 f[['image_name', f'target_wo_{N}']].to_csv(f'sub_wo_{N}.csv', index=False, header=['image_name', 'target'])
 name_col = f'target_wo_{N}'
results = model.predict(test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label" )<save_to_csv>
min_dist = pd.DataFrame(dic_errors ).idxmin(axis=1)
 min_vals = []
for i, sub in min_dist.iteritems() :
min_vals.append(f.loc[i,cols[sub]] )
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("cnn_mnist_datagen_MMA.csv",index=False )<load_from_csv>
f['target_arg_min'] = min_vals
train= pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 test= pd.read_csv('/kaggle/input/digit-recognizer/test.csv' )<data_type_conversions>
f[['image_name', 'target_arg_min']].to_csv('sub_argmin.csv', index=False, header=['image_name', 'target'] )
Ytrain= train['label'].astype('float32')
<drop_column>
vals = []
for i, row in pd.DataFrame(dic_errors ).iterrows() :
vals.append(f.loc[i,[cols[sub] for sub in row.sort_values(ascending=False ).index.tolist() [N+1:]]].mean())
 f['target_mean_min'] = vals
f[['image_name', 'target_mean_min']].to_csv('sub_mean_min.csv', index=False, header=['image_name', 'target'] )
<data_type_conversions><EOS> 
f['global_sub']= f[[name_col, 'target_mean_min']].mean(axis=1)
 f[['image_name', 'global_sub']].to_csv('global_sub.csv', index=False, header=['image_name', 'target'] )