Kaggle competition: University of Liverpool - Ion Switching
test_X = test[features]
preds = model_lgb.predict(test_X)
 sub['target']=preds
sub.to_csv('submission_lgb.csv', index=False )<set_options>
def read_data(inp1, inp2):
train = pd.read_csv(inp1 + 'train.csv', dtype={'time': np.float32, 'signal': np.float32, 'open_channels':np.int32})
 test = pd.read_csv(inp1 + 'test.csv', dtype={'time': np.float32, 'signal': np.float32})
 Y_train_proba = np.load(inp2 + "Y_train_proba.npy")
 Y_test_proba = np.load(inp2 + "Y_test_proba.npy")
 for i in range(11):
train[f"proba_{i}"] = Y_train_proba[:, i]
test[f"proba_{i}"] = Y_test_proba[:, i]
return train, test
warnings.filterwarnings("ignore" )<load_from_csv>
from sklearn.metrics import f1_score
train = pd.read_csv('.. /input/tabular-playground-series-jan-2021/train.csv')
 test = pd.read_csv('.. /input/tabular-playground-series-jan-2021/test.csv')
 sub = pd.read_csv('.. /input/tabular-playground-series-jan-2021/sample_submission.csv' )<define_variables>
proba_tr, proba_te = read_data('/kaggle/input/liverpool-ion-switching/','/kaggle/input/ion-shifted-rfc-proba/' )
features = ['cont1', 'cont2', 'cont3', 'cont4', 'cont5', 'cont6', 'cont7',
'cont8', 'cont9', 'cont10', 'cont11', 'cont12', 'cont13', 'cont14']<prepare_x_and_y>
proba_tr.sort_values('time', ignore_index = True, inplace = True)
 proba_tr_value = proba_tr[['proba_0', 'proba_1', 'proba_2','proba_3', 'proba_4', 'proba_5', 'proba_6', 'proba_7', 'proba_8','proba_9', 'proba_10']].values
proba_tr_pred = np.argmax(proba_tr_value, axis=-1 )
X = train_01[features]
y = train_01['target']<init_hyperparams>
proba_tr['pred'] = proba_tr_pred
params_xgb = {'lambda': 1,
'alpha': 0,
'colsample_bytree': 1,
'subsample': 1,
'learning_rate': 0.05,
'max_depth': 6,
'min_child_weight': 3,
'random_state': 48}<choose_model_class>
for i in [0,1],[2,6],[3,7],[5,8],[4,9]:
j1 = i[0] + 1
j2 = i[1] + 1
batch = j1; a = 500000*(batch-1); b = 500000*batch
batch = j2; c = 500000*(batch-1); d = 500000*batch
print(j1,j2)
 pred_temp = np.concatenate([proba_tr.pred.values[a:b], proba_tr.pred.values[c:d]] ).reshape(( -1,1))
real_temp = np.concatenate([proba_tr.open_channels.values[a:b], proba_tr.open_channels.values[c:d]] ).reshape(( -1,1))
print(i);print('f1 score =',f1_score(pred_temp,real_temp,average='macro'))
model_xgb = xgb.XGBRegressor(**params_xgb )<define_search_space>
f1_score(proba_tr.pred,proba_tr.open_channels,average='macro' )
param_range = np.linspace(0, 1, 10)
 param_range<define_variables>
proba_te.sort_values('time', ignore_index = True, inplace = True)
 temp = proba_te[['proba_0','proba_1','proba_2','proba_3','proba_4','proba_5','proba_6','proba_7','proba_8','proba_9','proba_10']].values
temp_pred = pd.DataFrame(np.argmax(temp, axis=-1))
temp_pred.columns = ['open_channels']
x = datetime.datetime.now()
x = x.strftime("%Y%m%d%H%M%S")
 test_ori = pd.read_csv('/kaggle/input/liverpool-ion-switching/' + 'test.csv')
 pd.concat([test_ori[['time']],temp_pred], axis = 1 ).to_csv('sub'+x+'.csv.gz', compression='gzip', index = False, float_format='%.4f')
<define_variables><EOS> 
pd.concat([test_ori[['time']],temp_pred], axis = 1 ).to_csv('sub'+x+'.csv', index = False, float_format='%.4f' )