Kaggle competition: Mechanisms of Action (MoA) Prediction
<SOS> metric: MeanColumnwiseLogLoss Kaggle data source: mechanisms-of-action-(moa)-prediction<prepare_x_and_y>
sys.path.append('.. /input/tabnetdevelop/tabnet-develop(1)/tabnet-develop')
 os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
y1_valid = cut_neg(df_train['ConfirmedCasesValid'].copy())
 y2_valid = cut_neg(df_train['FatalitiesValid'].copy())
 y1_pred = cut_neg(df_test['ConfirmedCases'].copy())
 y2_pred = cut_neg(df_test['Fatalities'].copy() )<compute_test_metric>
data_path = ".. /input/lish-moa/"
test = pd.read_csv(data_path+'test_features.csv')
 test.drop(columns=["sig_id"], inplace=True)
 test["cp_type"] =(test["cp_type"]=="trt_cp")+ 0
test["cp_dose"] =(test["cp_dose"]=="D1")+ 0
X_test = test.values
submission = pd.read_csv(data_path+'sample_submission.csv' )
mse =(mean_squared_log_error(y1_train, y1_valid)+mean_squared_log_error(y2_train, y2_valid)) /2
mse<prepare_output>
mask_type = 'entmax'
n_da = 60
n_steps = 1
gamma = 1.0
lambda_sparse = 2.6743669818463933e-05
n_shared = 1
tabnet_params = dict(n_d=n_da, n_a=n_da, n_steps=n_steps, gamma=gamma,
lambda_sparse=lambda_sparse, optimizer_fn=torch.optim.Adam,
optimizer_params=dict(lr=2e-2, weight_decay=1e-5),
mask_type=mask_type, n_shared=n_shared,
scheduler_params=dict(mode="min",
patience=5,
min_lr=1e-5,
factor=0.9,),
scheduler_fn=torch.optim.lr_scheduler.ReduceLROnPlateau,
verbose=1,
)
submission = pd.DataFrame({'ForecastId': df_test['ForecastId'],'ConfirmedCases': y1_pred,'Fatalities': y2_pred})
 submission.head()<save_to_csv>
test_cv_preds = []
model = TabNetRegressor(**tabnet_params )
submission.to_csv('submission.csv',index = False )<load_from_csv>
dirs = os.listdir('.. /input/tabnetregressor-2-0-3-seed-7-fold')
 dirs.remove('__results__.html')
 dirs.remove('__notebook__.ipynb')
 dirs.remove('custom.css')
 dirs.remove('__output__.json')
 dirs.remove('submission.csv' )
sub1=pd.read_csv('/kaggle/input/rscript-week4/submission.csv')
 sub4=pd.read_csv('/kaggle/input/trmfdata/submission.csv')
 sub4.sort_values("ForecastId", inplace=True)
 sub1.sort_values("ForecastId", inplace=True)
 train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
 dacheckv='2020-04-01'
train['Province_State'].fillna('', inplace=True)
 train['Date'] = pd.to_datetime(train['Date'])
 train['day'] = train.Date.dt.dayofyear
train['geo'] = ['_'.join(x)for x in zip(train['Country_Region'], train['Province_State'])]
train=train[train.Date>dacheckv]
test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
 test['Province_State'].fillna('', inplace=True)
 test['Date'] = pd.to_datetime(test['Date'])
 test['day'] = test.Date.dt.dayofyear
test['geo'] = ['_'.join(x)for x in zip(test['Country_Region'], test['Province_State'])]
test1=test.merge(train,on=['Country_Region','Province_State','Date'],how='inner')
 print(RMSLE(sub1[sub1.ForecastId.isin(test1.ForecastId.values)]['ConfirmedCases'].values,test1['ConfirmedCases'].values))
print(RMSLE(sub1[sub1.ForecastId.isin(test1.ForecastId.values)]['Fatalities'].values,test1['Fatalities'].values)) 
<compute_test_metric>
for x in dirs:
model.load_model(f".. /input/tabnetregressor-2-0-3-seed-7-fold/{x}")
 preds_test = model.predict(X_test)
 test_cv_preds.append(1 /(1 + np.exp(-preds_test)) )
print(RMSLE(sub4[sub4.ForecastId.isin(test1.ForecastId.values)]['ConfirmedCases'].values,test1['ConfirmedCases'].values))
print(RMSLE(sub4[sub4.ForecastId.isin(test1.ForecastId.values)]['Fatalities'].values,test1['Fatalities'].values)) 
<save_to_csv>
mean = np.mean(X_test, axis=0)
 std = np.std(X_test, axis=0 )
<load_from_csv><EOS> 
test_preds_all = np.stack(test_cv_preds)
 all_feat = [col for col in submission.columns if col not in ["sig_id"]]
submission[all_feat] = test_preds_all.mean(axis=0)
 submission.loc[test['cp_type']==0, submission.columns[1:]] = 0
submission.to_csv('submission.csv', index=None )