Kaggle competition: MLClass Dubai by ODS, Lecture 6 HW
<SOS> metric: meanfscore Kaggle data source: mlclass-dubai-by-ods,-lecture-6-hw<data_type_conversions>
!pip install iterative-stratification
!pip install tensorflow_addons
ts = time.time()
all_pairs['date_block_num'] = all_pairs['date_block_num'].astype(np.int8)
 all_pairs['city_label'] = all_pairs['city_label'].astype(np.int8)
 all_pairs['item_cnt_month'] = all_pairs['item_cnt_month'].astype(np.int8)
 all_pairs['item_category_id'] = all_pairs['item_category_id'].astype(np.int8)
 all_pairs['main_category_label'] = all_pairs['main_category_label'].astype(np.int8)
 all_pairs['secondary_category_label'] = all_pairs['secondary_category_label'].astype(np.int8)
 def calculate_lag(df, lag, column):
ancilla = df[['date_block_num','shop_id','item_id',column]]
for l in lag:
shift_ancilla = ancilla.copy()
shift_ancilla.columns = ['date_block_num','shop_id','item_id', column+'_lag_'+str(l)]
shift_ancilla['date_block_num'] += l
df = pd.merge(df, shift_ancilla, on=['date_block_num','shop_id','item_id'], how='left')
 return df
def prepare_lag_columns(df, lag, column_list, name):
ancilla = df.groupby(column_list ).agg({'item_cnt_month':['mean']})
 ancilla.columns = [name]
ancilla.reset_index(inplace=True)
 df = pd.merge(df, ancilla, on=column_list, how='left')
 df[name] = df[name].astype(np.float16)
 df = calculate_lag(df, lag, name)
 df.drop([name], axis=1, inplace=True)
 return df
def prepare_lag_columns_price(df, column_list, name):
ancilla = sales_train.groupby(column_list ).agg({'item_price':['mean']})
 ancilla.columns = [name]
ancilla.reset_index(inplace=True)
 df = pd.merge(df, ancilla, on=column_list, how='left')
 df[name] = df[name].astype(np.float16)
 return df
all_pairs = calculate_lag(all_pairs, [1,2,3,4,5,6,12], 'item_cnt_month')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num', 'item_id'], 'total_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1,2,3,4,5,6,12], ['date_block_num'], 'item_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1,2,3,4,5,6,12], ['date_block_num', 'shop_id'], 'shop_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num','city_label'], 'city_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num','item_id','city_label'], 'item_city_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num', 'item_category_id'], 'category_id_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num', 'main_category_label'], 'main_category_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num', 'secondary_category_label'], 'secondary_category_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num','shop_id','item_category_id'], 'shop_category_id_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num','shop_id','main_category_label'], 'shop_main_category_avg_month_cnt')
 all_pairs = prepare_lag_columns(all_pairs, [1], ['date_block_num','shop_id','secondary_category_label'], 'shop_secondary_category_avg_month_cnt')
 all_pairs = prepare_lag_columns_price(all_pairs, ['item_id'], 'item_avg_price')
 all_pairs = prepare_lag_columns_price(all_pairs, ['date_block_num','item_id'], 'item_avg_price_month')
 all_pairs = calculate_lag(all_pairs, [1,2,3,4,5,6], 'item_avg_price_month')
 for lag in [1,2,3,4,5,6]:
all_pairs['trend_price_lag_'+str(lag)] =(all_pairs['item_avg_price_month_lag_'+str(lag)] - all_pairs['item_avg_price'])/ all_pairs['item_avg_price']
def clean_trend_price_lag(row):
for l in [1,2,3,4,5,6]:
if row['trend_price_lag_'+str(l)]:
return row['trend_price_lag_'+str(l)]
return 0
dummy_1, dummy_2, dummy_3, dummy_4 = [], [], [], []
dummy_1 = pd.DataFrame(dummy_1)
 dummy_2 = pd.DataFrame(dummy_2)
 dummy_3 = pd.DataFrame(dummy_3)
 dummy_4 = pd.DataFrame(dummy_4)
 dummy_1 = all_pairs[:3000000].apply(clean_trend_price_lag, axis=1)
 dummy_2 = all_pairs[3000000:6000000].apply(clean_trend_price_lag, axis=1)
 dummy_3 = all_pairs[6000000:9000000].apply(clean_trend_price_lag, axis=1)
 dummy_4 = all_pairs[9000000:].apply(clean_trend_price_lag, axis=1)
 all_pairs['trend_price_lag'] = pd.concat([dummy_1, dummy_2, dummy_3, dummy_4])
 all_pairs['trend_price_lag'] = all_pairs['trend_price_lag'].astype(np.float16)
 all_pairs['trend_price_lag'].fillna(0, inplace=True)
 for i in [1,2,3,4,5,6]:
all_pairs.drop(['item_avg_price_month_lag_'+str(i), 'trend_price_lag_'+str(i)], axis=1, inplace=True)
 all_pairs.drop('shop_type', axis=1, inplace=True)
 time.time() - ts<merge>
df_target_train = pd.read_csv('/kaggle/input/mlclass-dubai-by-ods-lecture-5-hw/df_target_train.csv')
 print('df_target_train:', df_target_train.shape)
 df_sample_submit = pd.read_csv('/kaggle/input/mlclass-dubai-by-ods-lecture-5-hw/df_sample_submit.csv')
 print('df_sample_submit:', df_sample_submit.shape)
 df_tracks = pd.read_csv('/kaggle/input/mlclass-dubai-by-ods-lecture-5-hw/df_tracks.csv')
 print('df_tracks:', df_tracks.shape)
 df_genres = pd.read_csv('/kaggle/input/mlclass-dubai-by-ods-lecture-5-hw/df_genres.csv')
 print('df_genres:', df_genres.shape)
 df_features = pd.read_csv('/kaggle/input/mlclass-dubai-by-ods-lecture-5-hw/df_features.csv')
 print('df_features:', df_features.shape)
 df_target_train.head()
ts = time.time()
group = sales_train.groupby(['date_block_num','shop_id'] ).agg({'revenue': ['sum']})
 group.columns = ['date_shop_revenue']
group.reset_index(inplace=True)
 all_pairs = pd.merge(all_pairs, group, on=['date_block_num','shop_id'], how='left')
 all_pairs['date_shop_revenue'] = all_pairs['date_shop_revenue'].astype(np.float32)
 group = group.groupby(['shop_id'] ).agg({'date_shop_revenue': ['mean']})
 group.columns = ['shop_avg_revenue']
group.reset_index(inplace=True)
 all_pairs = pd.merge(all_pairs, group, on=['shop_id'], how='left')
 all_pairs['shop_avg_revenue'] = all_pairs['shop_avg_revenue'].astype(np.float32)
 all_pairs['delta_revenue'] =(all_pairs['date_shop_revenue'] - all_pairs['shop_avg_revenue'])/ all_pairs['shop_avg_revenue']
all_pairs['delta_revenue'] = all_pairs['delta_revenue'].astype(np.float16)
 all_pairs = calculate_lag(all_pairs, [1], 'delta_revenue')
 all_pairs.drop(['date_shop_revenue','shop_avg_revenue','delta_revenue'], axis=1, inplace=True)
 all_pairs['item_shop_first_sale'] = all_pairs['date_block_num'] - all_pairs.groupby(['item_id','shop_id'])['date_block_num'].transform('min')
 all_pairs['item_first_sale'] = all_pairs['date_block_num'] - all_pairs.groupby('item_id')['date_block_num'].transform('min')
 time.time() - ts<data_type_conversions>
trainids=df_target_train["track_id"].tolist()
testids=df_sample_submit["track_id"].tolist()
tr_album=df_tracks[(df_tracks["track_id"].isin(trainids)) ]["album:id"].unique()
te_album=df_tracks[(df_tracks["track_id"].isin(testids)) ]["album:id"].unique()
len(tr_album),len(te_album),len([t for t in te_album if t in tr_album]),len([t for t in te_album if t not in tr_album] )
ts = time.time()
all_pairs = all_pairs[all_pairs.date_block_num > 11]
time.time() - ts
ts = time.time()
def fill_na(df):
for col in df.columns:
if('_lag_' in col)&(df[col].isnull().any()):
if('item_cnt' in col):
df[col].fillna(0, inplace=True)
 return df
all_pairs = fill_na(all_pairs)
 all_pairs.fillna(0, inplace=True)
 time.time() - ts<drop_column>
trainids=df_target_train["track_id"].tolist()
testids=df_sample_submit["track_id"].tolist()
tr_album=df_tracks[(df_tracks["track_id"].isin(trainids)) ]["artist:id"].unique()
te_album=df_tracks[(df_tracks["track_id"].isin(testids)) ]["artist:id"].unique()
len(tr_album),len(te_album),len([t for t in te_album if t in tr_album]),len([t for t in te_album if t not in tr_album] )
all_pairs.drop(['item_price_median', 'price_cat', 'item_avg_price', 'item_avg_price_month',
'main_category_avg_month_cnt_lag_1','secondary_category_avg_month_cnt_lag_1',
'shop_main_category_avg_month_cnt_lag_1','shop_secondary_category_avg_month_cnt_lag_1'], inplace=True, axis=1 )<prepare_x_and_y>
trainids=df_target_train["track_id"].tolist()
testids=df_sample_submit["track_id"].tolist()
tr_album=df_tracks[(df_tracks["track_id"].isin(trainids)) ]["track:language_code"].unique()
te_album=df_tracks[(df_tracks["track_id"].isin(testids)) ]["track:language_code"].unique()
len(tr_album),len(te_album),len([t for t in te_album if t in tr_album]),len([t for t in te_album if t not in tr_album]),[t for t in te_album if t not in tr_album]
all_pairs.to_pickle('data.pkl')
 data = pd.read_pickle('data.pkl')
 X_train = data[data.date_block_num < 33].drop(['item_cnt_month'], axis=1)
 Y_train = data[data.date_block_num < 33]['item_cnt_month']
X_valid = data[data.date_block_num == 33].drop(['item_cnt_month'], axis=1)
 Y_valid = data[data.date_block_num == 33]['item_cnt_month']
X_test = data[data.date_block_num == 34].drop(['item_cnt_month'], axis=1)
 gc.collect() ;<train_model>
df_tracks["album:type"].value_counts()
model=lgb.LGBMRegressor(
 n_estimators=10000,
learning_rate=0.3,
min_child_weight=300,
colsample_bytree=0.8,
subsample=0.8,
max_depth=8,
verbose=1,
seed=21)
 model.fit(X_train, Y_train,eval_metric="rmse", eval_set=[(X_train, Y_train),(X_valid, Y_valid)], verbose=1, early_stopping_rounds = 10)
<save_to_csv>
Y_pred = model.predict(X_valid ).clip(0, 20)
 Y_test = model.predict(X_test ).clip(0, 20)
 submission = pd.DataFrame({
"ID": test.index,
"item_cnt_month": Y_test
})
 submission.to_csv('submission.csv', index=False)
 pickle.dump(Y_pred, open('xgb_train.pickle', 'wb'))
pickle.dump(Y_test, open('xgb_test.pickle', 'wb'))<train_model>
all_labels=[]
ys=[]
for i,row in df_target_train.iterrows() :
genres=row["track:genres"].split(" ")
 all_labels.extend(genres)
 all_labels=list(set(all_labels))
ys.append(genres)
 print(len(all_labels))
ys[:5]
<import_modules>
mlb = MultiLabelBinarizer()
y_mlb=mlb.fit_transform(ys)
 y_mlb.shape
SAVED_MODEL_NAME = 'eff620200310.hdf5'
seed = 1234
np.random.seed(seed)
 tf.set_random_seed(seed)
 t_start = time.time()<load_from_csv>
mlb.inverse_transform(y_mlb)[:4]
t_start = time.time()
data_dir = '.. /regular-deepdrid/Regular_DeepDRiD'
train_data = '.. /input/regular-deepdrid/Regular_DeepDRiD/regular_train/'
valid_data = '.. /input/regular-deepdrid/Regular_DeepDRiD/regular_valid/'
test_data = '.. /input/regular-deepdrid/Regular_DeepDRiD/regular-test/'
train_df = pd.read_csv('.. /input/regular-deepdrid/DR_label/DR_label/regular-fundus-training.csv')
 valid_df = pd.read_csv('.. /input/regular-deepdrid/DR_label/DR_label/regular-fundus-validation.csv')
 test_df = pd.read_csv('.. /input/regular-deepdrid/DR_label/DR_label/Challenge1_upload.csv')
 train_df['image_id'] = train_df['image_id'] + ".jpg"
valid_df['image_id'] = valid_df['image_id'] + ".jpg"
test_df["image_id"] = test_df["image_id"].apply(lambda x: x + ".jpg")
 train_df['diagnosis']=None
for i in range(len(train_df)) :
if 'r' in train_df['image_id'][i]:
train_df['diagnosis'][i]=train_df['right_eye_DR_Level'][i]
else:
train_df['diagnosis'][i]=train_df['left_eye_DR_Level'][i]
valid_df['diagnosis']=None
for i in range(len(valid_df)) :
if 'r' in train_df['image_id'][i]:
valid_df['diagnosis'][i]=valid_df['right_eye_DR_Level'][i]
else:
valid_df['diagnosis'][i]=valid_df['left_eye_DR_Level'][i]
display(train_df.head())
 display(valid_df.head())
 display(test_df.head())
 print('Number of train samples: ', train_df.shape[0])
 print('Number of valid samples: ', valid_df.shape[0])
 print('Number of test samples: ', test_df.shape[0] )<count_missing_values>
print(df_target_train.shape,df_features.shape)
 train_X=df_target_train[["track_id"]].merge(df_features,how='inner',on='track_id')
 train_X=df_tracks[["track_id","track:bit_rate","track:duration","track:listens","track:comments","track:interest","album:tracks","artist:favorites"]].merge(train_X,how='inner',on="track_id" ).drop('track_id',axis=1)
 print(train_X.shape)
 print(df_sample_submit.shape)
 test_X=df_sample_submit[["track_id"]].merge(df_features,how='inner',on='track_id')
 test_X=df_tracks[["track_id","track:bit_rate","track:duration","track:listens","track:comments","track:interest","album:tracks","artist:favorites"]].merge(test_X,how='inner',on="track_id" ).drop('track_id',axis=1)
 print(test_X.shape)
train_df['diagnosis'].isnull().any()<count_values>
def build_model() :
num_input = layers.Input(shape=(train_X.shape[1],))
x = layers.Dense(300 )(num_input)
 x = BatchNormalization()(x)
 x = Dropout(0.1 )(x)
 x = Dense(300, activation="relu" )(x)
 x = Dropout(0.1 )(x)
 x = BatchNormalization()(x)
 x = Dense(64, activation="relu" )(x)
 x = Dropout(0.1 )(x)
 x = BatchNormalization()(x)
 y = Dense(y_mlb.shape[1], activation="sigmoid" )(x)
 model = Model(inputs=num_input, outputs=y)
 model.compile(loss='binary_crossentropy', optimizer='adam',metrics=[tfa.metrics.F1Score(num_classes=161,average="macro")])
 return model
model=build_model()
model.summary()
train_df['diagnosis'].value_counts()<count_values>
def decode(y_pred):
inverse=mlb.inverse_transform(y_pred.round())
 maxes=np.max(y_pred,axis=1)
 for i in range(len(inverse)) :
if(inverse[i]):
pass
else:
args=np.argpartition(y_pred[i], -4)[-4:]
k=y_pred[i]
k[args]=1
y_pred[i]=k
inverse2=mlb.inverse_transform(y_pred.round())
 return inverse2
valid_df['diagnosis'].value_counts()<define_variables>
NFOLDS=8
sc=StandardScaler()
sc.fit(pd.concat([train_X,test_X],axis=0 ).values)
 X=sc.transform(train_X.values)
 X_test=sc.transform(test_X.values)
 y=y_mlb
mskf=MultilabelStratifiedKFold(n_splits=NFOLDS)
 validationdf=pd.DataFrame({"track_id":df_target_train["track_id"]})
 predictiondf=pd.DataFrame({"track_id":df_sample_submit["track_id"]})
 scores=[]
predictions=np.zeros(( X_test.shape[0],y.shape[1]))
for fold,(trn_,val_)in enumerate(mskf.split(X,y)) :
print(fold)
 X_train, X_val = X[trn_], X[val_]
y_train, y_val = y[trn_], y[val_]
model=build_model()
rlr=ReduceLROnPlateau(monitor='val_f1_score',factor=0.1,patience=2, min_lr=1e-12, mode='max', verbose=1)
 es = EarlyStopping(monitor='val_f1_score',mode='max',min_delta=0.00001, patience=5,verbose=1, baseline=None,restore_best_weights=True)
 history= model.fit(
 x=X_train,
y=y_train,
validation_data=(X_val,y_val),
epochs=100,
batch_size=80,
callbacks=[es,rlr],
verbose=1 
)
 predictions+=model.predict(X_test)
 predictions=predictions/NFOLDS
IMG_WIDTH = 528
IMG_HEIGHT = 528
CHANNELS = 3<predict_on_test>
predictions_decoded=decode(predictions)
 predictions_decoded[:2]
def get_preds_and_labels(model, generator):

 preds = []
labels = []
for _ in range(int(np.ceil(generator.samples / BATCH_SIZE))):
x, y = next(generator)
 preds.append(model.predict(x))
labels.append(y)
 return np.concatenate(preds ).ravel() , np.concatenate(labels ).ravel()<train_model>
def format_output(x):
return " ".join(list(x))
df_sample_submit["track:genres"]=predictions_decoded
df_sample_submit["track:genres"]=df_sample_submit["track:genres"].apply(format_output)
 df_sample_submit.head()
class Metrics(Callback):

 def on_train_begin(self, logs={}):

 self.val_kappas = []
def on_epoch_end(self, epoch, logs={}):

 y_pred, labels = get_preds_and_labels(model, val_generator)
 y_pred = np.rint(y_pred ).astype(np.uint8 ).clip(0, 4)
 _val_kappa = cohen_kappa_score(labels.astype(np.uint8), y_pred, weights='quadratic')
 self.val_kappas.append(_val_kappa)
 print(f"val_kappa: {round(_val_kappa, 4)}")
 if _val_kappa == max(self.val_kappas):
print("Validation Kappa has improved.Saving model.")
 self.model.save(SAVED_MODEL_NAME)
 return 
<prepare_x_and_y>
trainids=df_target_train["track_id"].tolist()
testids=df_sample_submit["track_id"].tolist()
tr_album=df_tracks[(df_tracks["track_id"].isin(trainids)) ]["album:id"].unique()
te_album=df_tracks[(df_tracks["track_id"].isin(testids)) ]["album:id"].unique()
print(len(tr_album),len(te_album),len([t for t in te_album if t in tr_album]),len([t for t in te_album if t not in tr_album]))
matching_albums=[t for t in te_album if t in tr_album and t!=-1]
print(len(matching_albums))
y_labels = train_df['diagnosis'].values<choose_model_class>
t=df_tracks[["track_id","album:id"]].merge(df_target_train,how='inner',on=["track_id"] ).drop("track_id",axis=1)
 t.head()
albs_genres={}
for alb, grp in t.groupby("album:id"):
if(alb not in matching_albums):
continue
albs_genres[alb]=format_output(mlb.inverse_transform(np.max(mlb.transform(grp["track:genres"].apply(lambda x: x.split(" ")).tolist()),axis=0 ).reshape(1,-1)) [0])
 len(list(albs_genres))
BATCH_SIZE = 4
train_datagen = ImageDataGenerator(
 rotation_range=360,
horizontal_flip=True,
vertical_flip=True,
preprocessing_function=preprocess_image,
rescale=1./128 
)
 train_generator = train_datagen.flow_from_dataframe(train_df,
x_col='image_id',
y_col='diagnosis',
directory = train_data,
target_size=(IMG_WIDTH, IMG_HEIGHT),
batch_size=BATCH_SIZE,
class_mode='other', 
)
 val_generator = train_datagen.flow_from_dataframe(valid_df,
x_col='image_id',
y_col='diagnosis',
directory = valid_data,
target_size=(IMG_WIDTH, IMG_HEIGHT),
batch_size=BATCH_SIZE,
class_mode='other',
)<choose_model_class>
df_sample_submit=df_sample_submit.merge(df_tracks[["track_id","album:id"]],on="track_id",how='inner')
 df_sample_submit["track:genres"]=df_sample_submit.apply(lambda x: albs_genres[x["album:id"]] if int(x["album:id"])in albs_genres else x["track:genres"],axis=1)
 df_sample_submit.head(10 )
class RAdam(keras.optimizers.Optimizer):

 def __init__(self, lr=0.001, beta_1=0.9, beta_2=0.999,
epsilon=None, decay=0., weight_decay=0., amsgrad=False,
total_steps=0, warmup_proportion=0.1, min_lr=0., **kwargs):
super(RAdam, self ).__init__(**kwargs)
 with K.name_scope(self.__class__.__name__):
self.iterations = K.variable(0, dtype='int64', name='iterations')
 self.lr = K.variable(lr, name='lr')
 self.beta_1 = K.variable(beta_1, name='beta_1')
 self.beta_2 = K.variable(beta_2, name='beta_2')
 self.decay = K.variable(decay, name='decay')
 self.weight_decay = K.variable(weight_decay, name='weight_decay')
 self.total_steps = K.variable(total_steps, name='total_steps')
 self.warmup_proportion = K.variable(warmup_proportion, name='warmup_proportion')
 self.min_lr = K.variable(lr, name='min_lr')
 if epsilon is None:
epsilon = K.epsilon()
self.epsilon = epsilon
self.initial_decay = decay
self.initial_weight_decay = weight_decay
self.initial_total_steps = total_steps
self.amsgrad = amsgrad
def get_updates(self, loss, params):
grads = self.get_gradients(loss, params)
 self.updates = [K.update_add(self.iterations, 1)]
lr = self.lr
if self.initial_decay > 0:
lr = lr *(1./(1.+ self.decay * K.cast(self.iterations, K.dtype(self.decay))))
t = K.cast(self.iterations, K.floatx())+ 1
if self.initial_total_steps > 0:
warmup_steps = self.total_steps * self.warmup_proportion
decay_steps = self.total_steps - warmup_steps
lr = K.switch(
 t <= warmup_steps,
lr *(t / warmup_steps),
lr *(1.0 - K.minimum(t, decay_steps)/ decay_steps), 
)
 ms = [K.zeros(K.int_shape(p), dtype=K.dtype(p), name='m_' + str(i)) for(i, p)in enumerate(params)]
vs = [K.zeros(K.int_shape(p), dtype=K.dtype(p), name='v_' + str(i)) for(i, p)in enumerate(params)]
if self.amsgrad:
vhats = [K.zeros(K.int_shape(p), dtype=K.dtype(p), name='vhat_' + str(i)) for(i, p)in enumerate(params)]
else:
vhats = [K.zeros(1, name='vhat_' + str(i)) for i in range(len(params)) ]
self.weights = [self.iterations] + ms + vs + vhats
beta_1_t = K.pow(self.beta_1, t)
 beta_2_t = K.pow(self.beta_2, t)
 sma_inf = 2.0 /(1.0 - self.beta_2)- 1.0
sma_t = sma_inf - 2.0 * t * beta_2_t /(1.0 - beta_2_t)
 for p, g, m, v, vhat in zip(params, grads, ms, vs, vhats):
m_t =(self.beta_1 * m)+(1.- self.beta_1)* g
v_t =(self.beta_2 * v)+(1.- self.beta_2)* K.square(g)
 m_corr_t = m_t /(1.0 - beta_1_t)
 if self.amsgrad:
vhat_t = K.maximum(vhat, v_t)
 v_corr_t = K.sqrt(vhat_t /(1.0 - beta_2_t)+ self.epsilon)
 self.updates.append(K.update(vhat, vhat_t))
else:
v_corr_t = K.sqrt(v_t /(1.0 - beta_2_t)+ self.epsilon)
 r_t = K.sqrt(( sma_t - 4.0)/(sma_inf - 4.0)* 
(sma_t - 2.0)/(sma_inf - 2.0)*
sma_inf / sma_t)
 p_t = K.switch(sma_t > 5, r_t * m_corr_t / v_corr_t, m_corr_t)
 if self.initial_weight_decay > 0:
p_t += self.weight_decay * p
p_t = p - lr * p_t
self.updates.append(K.update(m, m_t))
self.updates.append(K.update(v, v_t))
new_p = p_t
if getattr(p, 'constraint', None)is not None:
new_p = p.constraint(new_p)
 self.updates.append(K.update(p, new_p))
return self.updates
def get_config(self):
config = {
'lr': float(K.get_value(self.lr)) ,
'beta_1': float(K.get_value(self.beta_1)) ,
'beta_2': float(K.get_value(self.beta_2)) ,
'decay': float(K.get_value(self.decay)) ,
'weight_decay': float(K.get_value(self.weight_decay)) ,
'epsilon': self.epsilon,
'amsgrad': self.amsgrad,
'total_steps': float(K.get_value(self.total_steps)) ,
'warmup_proportion': float(K.get_value(self.warmup_proportion)) ,
'min_lr': float(K.get_value(self.min_lr)) ,
}
base_config = super(RAdam, self ).get_config()
return dict(list(base_config.items())+ list(config.items()))<choose_model_class>
<train_model><EOS> 
df_sample_submit[["track_id","track:genres"]].to_csv("submission.csv",index=None)
 df_sample_submit[["track_id","track:genres"]]