Kaggle competition: University of Liverpool - Ion Switching
<SOS> metric: MacroFScore Kaggle data source: university-of-liverpool-ion-switching<statistical_test>
!pip install --no-warn-conflicts -q tensorflow-addons
def maddest(d, axis=None):
return np.mean(np.absolute(d - np.mean(d, axis)) , axis)
 def high_pass_filter(x, low_cutoff=1000, sample_rate=10000):
nyquist = 0.5 * sample_rate
norm_low_cutoff = low_cutoff / nyquist
print(norm_low_cutoff)
 sos = butter(10, Wn=[norm_low_cutoff], btype='highpass', output='sos')
 filtered_sig = signal.sosfilt(sos, x)
 return filtered_sig
def denoise_signal(x, wavelet='db4', level=1):
coeff = pywt.wavedec(x, wavelet, mode="per")
 sigma =(1/0.6745)* maddest(coeff[-level])
 uthresh = sigma * np.sqrt(2*np.log(len(x)))
 coeff[1:] =(pywt.threshold(i, value=uthresh, mode='hard')for i in coeff[1:])
 return pywt.waverec(coeff, wavelet, mode='per' )<load_from_csv>
Add, AveragePooling1D, Multiply, GRU, GRUCell, LSTMCell, SimpleRNNCell, SimpleRNN, TimeDistributed, RNN,
RepeatVector, Conv1D, MaxPooling1D, Concatenate, GlobalAveragePooling1D, UpSampling1D)
 warnings.simplefilter('ignore')
 warnings.filterwarnings('ignore')
 pd.set_option('display.max_columns', 1000)
 pd.set_option('display.max_rows', 500)
 %matplotlib inline
base = '.. /input/data-without-drift/'
train = pd.read_csv(os.path.join(base + 'train_clean.csv'))
test = pd.read_csv(os.path.join(base + 'test_clean.csv'))<feature_engineering>
EPOCHS=120
NNBATCHSIZE=20
BATCHSIZE = 4000
SEED = 321
SELECT = True
SPLITS = 5
LR = 0.001
fe_config = [ 
(True, 4000),
]
def features(df):
df = df.sort_values(by=['time'] ).reset_index(drop=True)
 df.index =(( df.time * 10_000)- 1 ).values
df['batch'] = df.index // 25_000
df['batch_index'] = df.index -(df.batch * 25_000)
 df['batch_slices'] = df['batch_index'] // 2500
df['batch_slices2'] = df.apply(lambda r: '_'.join([str(r['batch'] ).zfill(3), str(r['batch_slices'] ).zfill(3)]), axis=1)
 for c in ['batch','batch_slices2']:
d = {}
d['mean'+c] = df.groupby([c])['signal'].mean()
d['median'+c] = df.groupby([c])['signal'].median()
d['max'+c] = df.groupby([c])['signal'].max()
d['min'+c] = df.groupby([c])['signal'].min()
d['std'+c] = df.groupby([c])['signal'].std()
d['mean_abs_chg'+c] = df.groupby([c])['signal'].apply(lambda x: np.mean(np.abs(np.diff(x))))
d['abs_max'+c] = df.groupby([c])['signal'].apply(lambda x: np.max(np.abs(x)))
 d['abs_min'+c] = df.groupby([c])['signal'].apply(lambda x: np.min(np.abs(x)))
 d['range'+c] = d['max'+c] - d['min'+c]
d['maxtomin'+c] = d['max'+c] / d['min'+c]
d['abs_avg'+c] =(d['abs_min'+c] + d['abs_max'+c])/ 2
for v in d:
df[v] = df[c].map(d[v].to_dict())
 df['signal_shift_+1'] = [0,] + list(df['signal'].values[:-1])
 df['signal_shift_-1'] = list(df['signal'].values[1:])+ [0]
for i in df[df['batch_index']==0].index:
df['signal_shift_+1'][i] = np.nan
for i in df[df['batch_index']==49999].index:
df['signal_shift_-1'][i] = np.nan
for c in [c1 for c1 in df.columns if c1 not in ['time', 'signal', 'open_channels', 'batch',
'batch_index', 'batch_slices', 'batch_slices2'
]]:
df[c+'_msignal'] = df[c] - df['signal']
return df
train = features(train)
 test = features(test)
 col = [c for c in train.columns if c not in ['time', 'open_channels', 'batch', 'batch_index', 'batch_slices',
'batch_slices2',
'mean_abs_chgbatch', 'meanbatch', 'rangebatch', 'stdbatch',
'maxbatch', 'medianbatch', 'abs_minbatch', 'abs_avgbatch']]
target = train['open_channels']
train = train[col]<categorify>
def seed_everything(seed : int)-> NoReturn :
rn.seed(seed)
 np.random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 tf.random.set_seed(seed)
 seed_everything(SEED)
train.replace(np.inf,np.nan,inplace=True)
 train.replace(-np.inf,np.nan,inplace=True)
 test.replace(np.inf,np.nan,inplace=True)
 test.replace(-np.inf,np.nan,inplace=True )<predict_on_test>
def read_data(base : os.path.abspath)-> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
train = pd.read_csv('/kaggle/input/clean-kalman/train_clean_kalman.csv', dtype={'time': np.float32, 'signal': np.float32, 'open_channels':np.int32})
 test = pd.read_csv('/kaggle/input/clean-kalman/test_clean_kalman.csv', dtype={'time': np.float32, 'signal': np.float32})
 sub = pd.read_csv('/kaggle/input/liverpool-ion-switching/sample_submission.csv', dtype={'time': np.float32})
 return train, test, sub
train_preds = gp.GrabPredictions(train[col].fillna(-999))
test_preds = gp.GrabPredictions(test[col].fillna(-999))<compute_test_metric>
def batching(df : pd.DataFrame,
batch_size : int)-> pd.DataFrame :
df['group'] = df.groupby(df.index//batch_size, sort=False)['signal'].agg(['ngroup'] ).values
df['group'] = df['group'].astype(np.uint16)
 return df
print('Score:',f1_score(target.values,np.argmax(train_preds.values,axis=1),average='macro'))<save_to_csv>
def lag_with_pct_change(df : pd.DataFrame,
shift_sizes : Optional[List]=[1, 2],
add_pct_change : Optional[bool]=False,
add_pct_change_lag : Optional[bool]=False)-> pd.DataFrame:
for shift_size in shift_sizes:
df['signal_shift_pos_'+str(shift_size)] = df.groupby('group')['signal'].shift(shift_size ).fillna(0)
 df['signal_shift_neg_'+str(shift_size)] = df.groupby('group')['signal'].shift(-1*shift_size ).fillna(0)
 if add_pct_change:
df['pct_change'] = df['signal'].pct_change()
if add_pct_change_lag:
for shift_size in shift_sizes:
df['pct_change_shift_pos_'+str(shift_size)] = df.groupby('group')['pct_change'].shift(shift_size ).fillna(0)
 df['pct_change_shift_neg_'+str(shift_size)] = df.groupby('group')['pct_change'].shift(-1*shift_size ).fillna(0)
 return df
test['open_channels'] = np.argmax(test_preds.values,axis=1)
 test[['time','open_channels']].to_csv('gpsubmission.csv', index=False, float_format='%.4f' )<compute_test_metric>
def run_feat_enginnering(df : pd.DataFrame,
create_all_data_feats : bool,
batch_size : int)-> pd.DataFrame:
df = batching(df, batch_size=batch_size)
 if create_all_data_feats:
df = lag_with_pct_change(df, [1, 2, 3], add_pct_change=False, add_pct_change_lag=False)
 df['signal_2'] = df['signal'] ** 2
return df
def MacroF1Metric(preds, dtrain):
labels = dtrain.get_label()
preds = preds.reshape(( -1,11))
preds = np.argmax(preds,axis=1)
 score = f1_score(labels, preds, average = 'macro')
 return('MacroF1Metric', score, True )<split>
def feature_selection(df : pd.DataFrame,
df_test : pd.DataFrame)-> Tuple[pd.DataFrame , pd.DataFrame, List]:
use_cols = [col for col in df.columns if col not in ['index','group', 'open_channels', 'time']]
df = df.replace([np.inf, -np.inf], np.nan)
 df_test = df_test.replace([np.inf, -np.inf], np.nan)
 for col in use_cols:
col_mean = pd.concat([df[col], df_test[col]], axis=0 ).mean()
df[col] = df[col].fillna(col_mean)
 df_test[col] = df_test[col].fillna(col_mean)
 gc.collect()
return df, df_test, use_cols
for c in range(11):
train['gp_'+str(int(c)) ] = train_preds.values[:,c]
test['gp_'+str(int(c)) ] = test_preds.values[:,c]
x1, x2, y1, y2 = model_selection.train_test_split(train, target, test_size=0.2, random_state=7)
 del train
gc.collect()
col = x1.columns
params = {'learning_rate': 0.1,
'max_depth': -1,
'num_leaves':2**7+1,
'objective': 'multiclass',
'num_class': 11,
'metric': 'multi_logloss',
'random_state': 7,
'n_jobs':4}
model = lgb.train(params, lgb.Dataset(x1, y1), 22222, lgb.Dataset(x2, y2), verbose_eval=0, early_stopping_rounds=250,feval=MacroF1Metric)
 preds_lgb =(model.predict(test[col], num_iteration=model.best_iteration))
oof_lgb =(model.predict(x2, num_iteration=model.best_iteration))
print('f1_score',f1_score(y2,np.argmax(oof_lgb,axis=1),average='macro'))
test['open_channels'] = np.argmax(preds_lgb,axis=1)
 test[['time','open_channels']].to_csv('lgbsubmission.csv', index=False, float_format='%.4f' )<import_modules>
def augment(X: np.array, y:np.array)-> Tuple[np.array, np.array]:
X = np.vstack(( X, np.flip(X, axis=1)))
 y = np.vstack(( y, np.flip(y, axis=1)))
 return X, y
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import keras
from keras.models import Sequential
from keras.layers import Conv2D, Dropout, Dense, Flatten, BatchNormalization, MaxPooling2D
from keras.optimizers import RMSprop
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import ReduceLROnPlateau, EarlyStopping
from keras.utils.np_utils import to_categorical
from sklearn.model_selection import train_test_split<load_from_csv>
def run_cv_model_by_batch(train : pd.DataFrame,
test : pd.DataFrame,
splits : int,
batch_col : Text,
feats : List,
sample_submission: pd.DataFrame,
nn_epochs : int,
nn_batch_size : int)-> NoReturn:
seed_everything(SEED)
 K.clear_session()
config = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=1,inter_op_parallelism_threads=1)
 sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph() , config=config)
 tf.compat.v1.keras.backend.set_session(sess)
 oof_ = np.zeros(( len(train), 11))
preds_ = np.zeros(( len(test), 11))
target = ['open_channels']
group = train['group']
kf = GroupKFold(n_splits=5)
 splits = [x for x in kf.split(train, train[target], group)]
new_splits = []
for sp in splits:
new_split = []
new_split.append(np.unique(group[sp[0]]))
new_split.append(np.unique(group[sp[1]]))
new_split.append(sp[1])
 new_splits.append(new_split)
 tr = pd.concat([pd.get_dummies(train.open_channels), train[['group']]], axis=1)
 tr.columns = ['target_'+str(i)for i in range(11)] + ['group']
target_cols = ['target_'+str(i)for i in range(11)]
train_tr = np.array(list(tr.groupby('group' ).apply(lambda x: x[target_cols].values)) ).astype(np.float32)
 train = np.array(list(train.groupby('group' ).apply(lambda x: x[feats].values)))
 test = np.array(list(test.groupby('group' ).apply(lambda x: x[feats].values)))
 for n_fold,(tr_idx, val_idx, val_orig_idx)in enumerate(new_splits[0:], start=0):
train_x, train_y = train[tr_idx], train_tr[tr_idx]
valid_x, valid_y = train[val_idx], train_tr[val_idx]
if n_fold < 2:
train_x, train_y = augment(train_x, train_y)
 gc.collect()
shape_ =(None, train_x.shape[2])
 model = Classifier(shape_)
 cb_lr_schedule = LearningRateScheduler(lr_schedule)
 cb_prg = tfa.callbacks.TQDMProgressBar(leave_epoch_progress=False,leave_overall_progress=False, show_epoch_progress=False,show_overall_progress=True)
 model.fit(train_x,train_y,
epochs=nn_epochs,
callbacks=[cb_prg, cb_lr_schedule, MacroF1(model, valid_x,valid_y)],
batch_size=nn_batch_size,verbose=0,
validation_data=(valid_x,valid_y))
preds_f = model.predict(valid_x)
 f1_score_ = f1_score(np.argmax(valid_y, axis=2 ).reshape(-1), np.argmax(preds_f, axis=2 ).reshape(-1), average = 'macro')
 logger.info(f'Training fold {n_fold + 1} completed.macro f1 score : {f1_score_ :1.5f}')
 preds_f = preds_f.reshape(-1, preds_f.shape[-1])
 oof_[val_orig_idx,:] += preds_f
te_preds = model.predict(test)
 te_preds = te_preds.reshape(-1, te_preds.shape[-1])
 preds_ += te_preds / SPLITS
f1_score_ =f1_score(np.argmax(train_tr, axis=2 ).reshape(-1), np.argmax(oof_, axis=1), average = 'macro')
 logger.info(f'Training completed.oof macro f1 score : {f1_score_:1.5f}')
 sample_submission['open_channels'] = np.argmax(preds_, axis=1 ).astype(int)
 sample_submission.to_csv('submission.csv', index=False, float_format='%.4f')
 display(sample_submission.head())
 np.save('oof.npy', oof_)
 np.save('preds.npy', preds_)
 return
Dig_MNIST = pd.read_csv(".. /input/Kannada-MNIST/Dig-MNIST.csv")
 sample_submission = pd.read_csv(".. /input/Kannada-MNIST/sample_submission.csv")
 test = pd.read_csv(".. /input/Kannada-MNIST/test.csv")
 train = pd.read_csv(".. /input/Kannada-MNIST/train.csv")
 x = train.iloc[:,1:].values
y = train.iloc[:,0].values
y[:10]
x_test = test.drop('id', axis=1 ).iloc[:,:].values
x_dig = Dig_MNIST.drop('label', axis=1 ).iloc[:,:].values
y_dig = Dig_MNIST.label
x = x.reshape(x.shape[0], 28, 28, 1)
 y = to_categorical(y, 10)
 x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
 x_dig = x_dig.reshape(x_dig.shape[0], 28, 28, 1)
 x_train, x_valid, y_train, y_valid = train_test_split(x, y, test_size = 0.10, random_state=42)
 train_datagen = ImageDataGenerator(rescale=1./255.,
rotation_range=10,
width_shift_range=0.25,
height_shift_range=0.25,
shear_range=0.1,
zoom_range=0.25,
horizontal_flip=False)
 valid_datagen = ImageDataGenerator(rescale=1./255.)<choose_model_class>
def lr_schedule(epoch):
if epoch < 40:
lr = LR
elif epoch < 50:
lr = LR / 3
elif epoch < 60:
lr = LR / 6
elif epoch < 75:
lr = LR / 9
elif epoch < 85:
lr = LR / 12
elif epoch < 100:
lr = LR / 15
else:
lr = LR / 50
return lr
batch_size = 1024
num_classes = 10
epochs = 50
learning_rate = 0.001
model_name = 'k-mnist_trained_model.h5'
model = Sequential()
model.add(Conv2D(64, kernel_size=3, activation='relu', input_shape=(28, 28, 1)))
 model.add(BatchNormalization())
 model.add(Conv2D(64, kernel_size=3, activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(64, kernel_size=5, padding='same', activation='relu'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.2))
model.add(Conv2D(128, kernel_size=3, activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(128, kernel_size=3, activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(128, kernel_size=5, padding='same', activation='relu'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.2))
model.add(Conv2D(256, kernel_size=3, activation='relu'))
model.add(BatchNormalization())
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.2))
model.add(Flatten())
 model.add(Dense(256))
model.add(BatchNormalization())
 model.add(Dense(128))
model.add(BatchNormalization())
 model.add(Dense(10, activation='softmax'))
model.summary()
optimizer = RMSprop(lr=learning_rate)
 model.compile(loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['accuracy'] )<train_model>
class Mish(tf.keras.layers.Layer):
def __init__(self, **kwargs):
super(Mish, self ).__init__(**kwargs)
 self.supports_masking = True
def call(self, inputs):
return inputs * K.tanh(K.softplus(inputs))
def get_config(self):
base_config = super(Mish, self ).get_config()
return dict(list(base_config.items())+ list(config.items()))
def compute_output_shape(self, input_shape):
return input_shape
def mish(x):
	return tf.keras.layers.Lambda(lambda x: x*K.tanh(K.softplus(x)) )(x)
 get_custom_objects().update({'mish': Activation(mish)} )
learning_rate_reduction = ReduceLROnPlateau(monitor='val_loss',
patience=200,
verbose=1,
factor=0.2)
 es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=200)
 history = model.fit_generator(train_datagen.flow(x_train, y_train, batch_size=batch_size),
steps_per_epoch=100,
epochs=epochs,
validation_data=valid_datagen.flow(x_valid, y_valid),
validation_steps=50,
callbacks=[learning_rate_reduction, es] )<save_to_csv>
class Attention(Layer):

 def __init__(self, hidden_size,
num_heads = 8,
attention_dropout=.1,
trainable=True,
name='Attention'):
if hidden_size % num_heads != 0:
raise ValueError("Hidden size must be evenly divisible by the number of heads.")
 self.hidden_size = hidden_size
self.num_heads = num_heads
self.trainable = trainable
self.attention_dropout = attention_dropout
self.dense = tf.keras.layers.Dense(self.hidden_size, use_bias=False)
 super(Attention, self ).__init__(name=name)
 def split_heads(self, x):

 with tf.name_scope("split_heads"):
batch_size = tf.shape(x)[0]
length = tf.shape(x)[1]
depth =(self.hidden_size // self.num_heads)
 x = tf.reshape(x, [batch_size, length, self.num_heads, depth])
 return tf.transpose(x, [0, 2, 1, 3])
 def combine_heads(self, x):

 with tf.name_scope("combine_heads"):
batch_size = tf.shape(x)[0]
length = tf.shape(x)[2]
x = tf.transpose(x, [0, 2, 1, 3])
 return tf.reshape(x, [batch_size, length, self.hidden_size])
 def call(self, inputs):

 q = self.dense(inputs)
 k = self.dense(inputs)
 v = self.dense(inputs)
 q = self.split_heads(q)
 k = self.split_heads(k)
 v = self.split_heads(v)
 depth =(self.hidden_size // self.num_heads)
 q *= depth ** -0.5
logits = tf.matmul(q, k, transpose_b=True)
 weights = tf.nn.softmax(logits, name="attention_weights")
 if self.trainable:
weights = tf.nn.dropout(weights, 1.0 - self.attention_dropout)
 attention_output = tf.matmul(weights, v)
 attention_output = self.combine_heads(attention_output)
 attention_output = self.dense(attention_output)
 return attention_output
def compute_output_shape(self, input_shape):
return tf.TensorShape(input_shape )
predictions = model.predict_classes(x_test/255.)
submission = pd.read_csv('.. /input/Kannada-MNIST/sample_submission.csv')
 submission['label'] = predictions
submission.to_csv("submission.csv", index=False )<set_options>
def categorical_focal_loss(gamma=2.0, alpha=0.25):

 def focal_loss(y_true, y_pred):
epsilon = K.epsilon()
y_pred = K.clip(y_pred, epsilon, 1.0-epsilon)
 cross_entropy = -y_true*K.log(y_pred)
 weight = alpha * y_true * K.pow(( 1-y_pred), gamma)
 loss = weight * cross_entropy
loss = K.sum(loss, axis=1)
 return loss
return focal_loss
!nvidia-smi<import_modules>
def WaveNetResidualConv1D(num_filters, kernel_size, stacked_layer):
def build_residual_block(l_input):
resid_input = l_input
for dilation_rate in [2**i for i in range(stacked_layer)]:
l_sigmoid_conv1d = Conv1D(
 num_filters, kernel_size, dilation_rate=dilation_rate,
padding='same', activation='sigmoid' )(l_input)
 l_tanh_conv1d = Conv1D(
 num_filters, kernel_size, dilation_rate=dilation_rate,
padding='same', activation='mish' )(l_input)
 l_input = Multiply()([l_sigmoid_conv1d, l_tanh_conv1d])
 l_input = Conv1D(num_filters, 1, padding='same' )(l_input)
 resid_input = Add()([resid_input ,l_input])
 return resid_input
return build_residual_block
def Classifier(shape_):
num_filters_ = 16
kernel_size_ = 3
stacked_layers_ = [12, 8, 4, 1]
l_input = Input(shape=(shape_))
x = Conv1D(num_filters_, 1, padding='same' )(l_input)
 x = WaveNetResidualConv1D(num_filters_, kernel_size_, stacked_layers_[0] )(x)
 x = Conv1D(num_filters_*2, 1, padding='same' )(x)
 x = WaveNetResidualConv1D(num_filters_*2, kernel_size_, stacked_layers_[1] )(x)
 x = Conv1D(num_filters_*4, 1, padding='same' )(x)
 x = WaveNetResidualConv1D(num_filters_*4, kernel_size_, stacked_layers_[2] )(x)
 x = Conv1D(num_filters_*8, 1, padding='same' )(x)
 x = WaveNetResidualConv1D(num_filters_*8, kernel_size_, stacked_layers_[3] )(x)
 l_output = Dense(11, activation='softmax' )(x)
 model = models.Model(inputs=[l_input], outputs=[l_output])
 opt = Adam(lr=LR)
 opt = tfa.optimizers.SWA(opt)
 model.compile(loss=losses.CategoricalCrossentropy() , optimizer=opt, metrics=['accuracy'])
 return model
from fastai import *
from fastai.vision import *
import pandas as pd<load_from_csv>
def Classifierx(shape_):
inp = Input(shape=(shape_))
x = Bidirectional(GRU(256, return_sequences=True))(inp)
 x = Attention(512 )(x)
 x = TimeDistributed(Dense(256, activation='mish'))(x)
 x = TimeDistributed(Dense(128, activation='mish'))(x)
 out = TimeDistributed(Dense(11, activation='softmax', name='out'))(x)
 model = models.Model(inputs=inp, outputs=out)
 opt = Adam(lr=LR)
 opt = tfa.optimizers.SWA(opt)
 model.compile(loss=losses.CategoricalCrossentropy() , optimizer=opt, metrics=['accuracy'])
 return model
<load_from_csv>
class MacroF1(Callback):
def __init__(self, model, inputs, targets):
self.model = model
self.inputs = inputs
self.targets = np.argmax(targets, axis=2 ).reshape(-1)
 def on_epoch_end(self, epoch, logs):
pred = np.argmax(self.model.predict(self.inputs), axis=2 ).reshape(-1)
 score = f1_score(self.targets, pred, average="macro")
 print(f' F1Macro: {score:.5f}')
class CustomImageItemList(ImageList):
def open(self, fn):
img = fn.reshape(28, 28)
 img = np.stack(( img,)*3, axis=-1)
 return Image(pil2tensor(img, dtype=np.float32))
@classmethod
def from_csv_custom(cls, path:PathOrStr, csv_name:str, imgIdx:int=1, header:str='infer', **kwargs)-> 'ItemList':
df = pd.read_csv(Path(path)/csv_name, header=header)
 res = super().from_df(df, path=path, cols=0, **kwargs)
 res.items = df.iloc[:,imgIdx:].apply(lambda x: x.values / 783.0, axis=1 ).values
return res<load_from_csv>
def normalize(train, test):
train_input_mean = train.signal.mean()
train_input_sigma = train.signal.std()
train['signal'] =(train.signal-train_input_mean)/train_input_sigma
test['signal'] =(test.signal-train_input_mean)/train_input_sigma
return train, test
<load_from_csv>
def run_everything(fe_config : List)-> NoReturn:
not_feats_cols = ['time']
target_col = ['open_channels']
init_logger()
with timer(f'Reading Data'):
logger.info('Reading Data Started...')
 base = os.path.abspath('/kaggle/input/liverpool-ion-switching/')
 train, test, sample_submission = read_data(base)
 train, test = normalize(train, test)
 logger.info('Reading and Normalizing Data Completed...')
 with timer(f'Creating Features'):
logger.info('Feature Enginnering Started...')
 for config in fe_config:
train = run_feat_enginnering(train, create_all_data_feats=config[0], batch_size=config[1])
 test = run_feat_enginnering(test, create_all_data_feats=config[0], batch_size=config[1])
 train, test, feats = feature_selection(train, test)
 logger.info('Feature Enginnering Completed...')
 with timer(f'Running Wavenet model'):
logger.info(f'Training Wavenet model with {SPLITS} folds of GroupKFold Started...')
 run_cv_model_by_batch(train, test, splits=SPLITS, batch_col='group', feats=feats, sample_submission=sample_submission, nn_epochs=EPOCHS, nn_batch_size=NNBATCHSIZE)
 logger.info(f'Training completed...')