Kaggle competition: Indoor Location & Navigation
<SOS> metric: IndoorLocalization Kaggle data source: indoor-location-&-navigation<feature_engineering>
!git clone --depth 1 https://github.com/location-competition/indoor-location-competition-20 indoor_location_competition_20
!rm -rf indoor_location_competition_20/data
def fe_stats(train, test):
for df in train, test:
df['c52_c42'] = df['c-52'] * df['c-42']
df['c13_c73'] = df['c-13'] * df['c-73']
df['c26_c13'] = df['c-23'] * df['c-13']
df['c33_c6'] = df['c-33'] * df['c-6']
df['c11_c55'] = df['c-11'] * df['c-55']
df['c38_c63'] = df['c-38'] * df['c-63']
df['c38_c94'] = df['c-38'] * df['c-94']
df['c13_c94'] = df['c-13'] * df['c-94']
df['c4_c52'] = df['c-4'] * df['c-52']
df['c4_c42'] = df['c-4'] * df['c-42']
df['c13_c38'] = df['c-13'] * df['c-38']
df['c55_c2'] = df['c-55'] * df['c-2']
df['c55_c4'] = df['c-55'] * df['c-4']
df['c4_c13'] = df['c-4'] * df['c-13']
df['c82_c42'] = df['c-82'] * df['c-42']
df['c66_c42'] = df['c-66'] * df['c-42']
df['c6_c38'] = df['c-6'] * df['c-38']
df['c2_c13'] = df['c-2'] * df['c-13']
df['c62_c42'] = df['c-62'] * df['c-42']
df['c90_c55'] = df['c-90'] * df['c-55']
return train, test
train_features2,test_features2=fe_stats(train_features2,test_features2 )<split>
%matplotlib inline
train_features_stats=train_features2.iloc[:,902:]
test_features_stats=test_features2.iloc[:,902:]<concatenate>
INPUT_PATH = '.. /input/indoor-location-navigation'
train_features = pd.concat(( train_features, train_features_cluster,train_features_stats), axis=1)
 test_features = pd.concat(( test_features, test_features_cluster,test_features_stats), axis=1 )<merge>
dfk = pd.DataFrame({
'Kernel ID': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
'Score': [9.773, 9.530, 8.500, 8.418, 8.333, 8.073, 7.745, 7.661, 7.274, 7.285],
'File Path': ['.. /input/indoor9773/Indoor9773.csv', '.. /input/indoor9530/Indoor9530.csv', '.. /input/indoor8500/Indoor8500.csv', '.. /input/indoor8418/Indoor8418.csv', '.. /input/indoor8333/Indoor8333.csv', '.. /input/indoor8073/Indoor8073.csv', '.. /input/indoornav7745sub/submission.csv', '.. /input/indoor7661/Indoor7661.csv', '.. /input/indoor-wifi-floor/submission.csv', '.. /input/time-series-rnn-xy-prediction/submission.csv']
})
 dfk
train = train_features.merge(train_targets_scored, on='sig_id')
 train = train[train['cp_type']!='ctl_vehicle'].reset_index(drop=True)
 test = test_features[test_features['cp_type']!='ctl_vehicle'].reset_index(drop=True)
 target = train[train_targets_scored.columns]<drop_column>
def compute_rel_positions(acce_datas, ahrs_datas):
step_timestamps, step_indexs, step_acce_max_mins = compute_f.compute_steps(acce_datas)
 headings = compute_f.compute_headings(ahrs_datas)
 stride_lengths = compute_f.compute_stride_length(step_acce_max_mins)
 step_headings = compute_f.compute_step_heading(step_timestamps, headings)
 rel_positions = compute_f.compute_rel_positions(stride_lengths, step_headings)
 return rel_positions
train = train.drop('cp_type', axis=1)
 test = test.drop('cp_type', axis=1 )<drop_column>
def correct_path(args):
path, path_df = args
T_ref = path_df['timestamp'].values
xy_hat = path_df[['x', 'y']].values
example = read_data_file(f'{INPUT_PATH}/test/{path}.txt')
 rel_positions = compute_rel_positions(example.acce, example.ahrs)
 if T_ref[-1] > rel_positions[-1, 0]:
rel_positions = [np.array([[0, 0, 0]]), rel_positions, np.array([[T_ref[-1], 0, 0]])]
else:
rel_positions = [np.array([[0, 0, 0]]), rel_positions]
rel_positions = np.concatenate(rel_positions)
 T_rel = rel_positions[:, 0]
delta_xy_hat = np.diff(scipy.interpolate.interp1d(T_rel, np.cumsum(rel_positions[:, 1:3], axis=0), axis=0 )(T_ref), axis=0)
 N = xy_hat.shape[0]
delta_t = np.diff(T_ref)
 alpha =(8.1)**(-2)* np.ones(N)
 beta =(0.30 + 0.30 * 1e-3 * delta_t)**(-2)
 A = scipy.sparse.spdiags(alpha, [0], N, N)
 B = scipy.sparse.spdiags(beta, [0], N-1, N-1)
 D = scipy.sparse.spdiags(np.stack([-np.ones(N), np.ones(N)]), [0, 1], N-1, N)
 Q = A +(D.T @ B @ D)
 c =(A @ xy_hat)+(D.T @(B @ delta_xy_hat))
xy_star = scipy.sparse.linalg.spsolve(Q, c)
 return pd.DataFrame({
'site_path_timestamp' : path_df['site_path_timestamp'],
'floor' : path_df['floor'],
'x' : xy_star[:, 0],
'y' : xy_star[:, 1],
})
target_cols = target.drop('sig_id', axis=1 ).columns.values.tolist()<split>
sub = pd.read_csv(dfk.iloc[0, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
folds = train.copy()
mskf = MultilabelStratifiedKFold(n_splits=7)
 for f,(t_idx, v_idx)in enumerate(mskf.split(X=train, y=target)) :
folds.loc[v_idx, 'kfold'] = int(f)
 folds['kfold'] = folds['kfold'].astype(int )<categorify>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('a9773cm99.csv', index=False)
 a9773cm99 = sub
class MoADataset:
def __init__(self, features, targets):
self.features = features
self.targets = targets
def __len__(self):
return(self.features.shape[0])
 def __getitem__(self, idx):
dct = {
'x' : torch.tensor(self.features[idx, :], dtype=torch.float),
'y' : torch.tensor(self.targets[idx, :], dtype=torch.float)
 }
return dct
class TestDataset:
def __init__(self, features):
self.features = features
def __len__(self):
return(self.features.shape[0])
 def __getitem__(self, idx):
dct = {
'x' : torch.tensor(self.features[idx, :], dtype=torch.float)
 }
return dct<train_model>
sub = pd.read_csv(dfk.iloc[1, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
def train_fn(model, optimizer, scheduler, loss_fn, dataloader, device):
model.train()
final_loss = 0
for data in dataloader:
optimizer.zero_grad()
inputs, targets = data['x'].to(device), data['y'].to(device)
 outputs = model(inputs)
 loss = loss_fn(outputs, targets)
 loss.backward()
optimizer.step()
scheduler.step()
final_loss += loss.item()
final_loss /= len(dataloader)
 return final_loss
def valid_fn(model, loss_fn, dataloader, device):
model.eval()
final_loss = 0
valid_preds = []
for data in dataloader:
inputs, targets = data['x'].to(device), data['y'].to(device)
 outputs = model(inputs)
 loss = loss_fn(outputs, targets)
 final_loss += loss.item()
valid_preds.append(outputs.sigmoid().detach().cpu().numpy())
 final_loss /= len(dataloader)
 valid_preds = np.concatenate(valid_preds)
 return final_loss, valid_preds
def inference_fn(model, dataloader, device):
model.eval()
preds = []
for data in dataloader:
inputs = data['x'].to(device)
 with torch.no_grad() :
outputs = model(inputs)
 preds.append(outputs.sigmoid().detach().cpu().numpy())
 preds = np.concatenate(preds)
 return preds<normalization>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('b9530cm99.csv', index=False)
 b9530cm99 = sub
class SmoothBCEwLogits(_WeightedLoss):
def __init__(self, weight=None, reduction='mean', smoothing=0.0):
super().__init__(weight=weight, reduction=reduction)
 self.smoothing = smoothing
self.weight = weight
self.reduction = reduction
@staticmethod
def _smooth(targets:torch.Tensor, n_labels:int, smoothing=0.0):
assert 0 <= smoothing < 1
with torch.no_grad() :
targets = targets *(1.0 - smoothing)+ 0.5 * smoothing
return targets
def forward(self, inputs, targets):
targets = SmoothBCEwLogits._smooth(targets, inputs.size(-1),
self.smoothing)
 loss = F.binary_cross_entropy_with_logits(inputs, targets,self.weight)
 if self.reduction == 'sum':
loss = loss.sum()
elif self.reduction == 'mean':
loss = loss.mean()
return loss<categorify>
sub = pd.read_csv(dfk.iloc[2, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
def process_data(df):
df['time_dose'] = df['cp_time'].astype(str)+df['cp_dose']
df = pd.get_dummies(df, columns=['cp_time','cp_dose','time_dose'])
 features_g = list(df.columns[4:776])
 features_c = list(df.columns[776:876])
 df['g_sum'] = df[features_g].sum(axis = 1)
 df['g_mean'] = df[features_g].mean(axis = 1)
 df['g_std'] = df[features_g].std(axis = 1)
 df['g_kurt'] = df[features_g].kurtosis(axis = 1)
 df['g_skew'] = df[features_g].skew(axis = 1)
 df['c_sum'] = df[features_c].sum(axis = 1)
 df['c_mean'] = df[features_c].mean(axis = 1)
 df['c_std'] = df[features_c].std(axis = 1)
 df['c_kurt'] = df[features_c].kurtosis(axis = 1)
 df['c_skew'] = df[features_c].skew(axis = 1)
 df['gc_sum'] = df[features_g + features_c].sum(axis = 1)
 df['gc_mean'] = df[features_g + features_c].mean(axis = 1)
 df['gc_std'] = df[features_g + features_c].std(axis = 1)
 df['gc_kurt'] = df[features_g + features_c].kurtosis(axis = 1)
 df['gc_skew'] = df[features_g + features_c].skew(axis = 1)
 features_c = list(df.columns[776:876])
 for feature in features_c:
df[f'{feature}_squared'] = df[feature] ** 2
return df<define_variables>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('c8500cm99.csv', index=False)
 c8500cm99 = sub
feature_cols = [c for c in process_data(folds ).columns if c not in target_cols]
feature_cols = [c for c in feature_cols if c not in ['kfold','sig_id']]
len(feature_cols )<define_variables>
sub = pd.read_csv(dfk.iloc[3, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
DEVICE =('cuda' if torch.cuda.is_available() else 'cpu')
 EPOCHS = 23
BATCH_SIZE = 128
LEARNING_RATE = 1e-3
WEIGHT_DECAY = 1e-5
NFOLDS = 7
EARLY_STOPPING_STEPS = 10
EARLY_STOP = False
num_features=len(feature_cols)
 num_targets=len(target_cols)
 hidden_size=1500<normalization>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('d8418cm99.csv', index=False)
 d8418cm99 = sub
class Model(nn.Module):
def __init__(self, num_features, num_targets, hidden_size):
super(Model, self ).__init__()
self.batch_norm1 = nn.BatchNorm1d(num_features)
 self.dense1 = nn.utils.weight_norm(nn.Linear(num_features, hidden_size))
self.batch_norm2 = nn.BatchNorm1d(hidden_size)
 self.dropout2 = nn.Dropout(Dropout_Model)
 self.dense2 = nn.utils.weight_norm(nn.Linear(hidden_size, hidden_size))
self.batch_norm3 = nn.BatchNorm1d(hidden_size)
 self.dropout3 = nn.Dropout(Dropout_Model)
 self.dense3 = nn.utils.weight_norm(nn.Linear(hidden_size, num_targets))
def forward(self, x):
x = self.batch_norm1(x+0.05)
 x = F.leaky_relu(self.dense1(x))
x = self.batch_norm2(x)
 x = self.dropout2(x)
 x = F.leaky_relu(self.dense2(x))
x = self.batch_norm3(x)
 x = self.dropout3(x)
 x = self.dense3(x)
 return x
class LabelSmoothingLoss(nn.Module):
def __init__(self, classes, smoothing=0.0, dim=-1):
super(LabelSmoothingLoss, self ).__init__()
self.confidence = 1.0 - smoothing
self.smoothing = smoothing
self.cls = classes
self.dim = dim
def forward(self, pred, target):
pred = pred.log_softmax(dim=self.dim)
 with torch.no_grad() :
true_dist = torch.zeros_like(pred)
 true_dist.fill_(self.smoothing /(self.cls - 1))
true_dist.scatter_(1, target.data.unsqueeze(1), self.confidence)
 return torch.mean(torch.sum(-true_dist * pred, dim=self.dim))<prepare_x_and_y>
sub = pd.read_csv(dfk.iloc[4, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
def run_training(fold, seed):
seed_everything(seed)
 train = process_data(folds)
 test_ = process_data(test)
 trn_idx = train[train['kfold'] != fold].index
val_idx = train[train['kfold'] == fold].index
train_df = train[train['kfold'] != fold].reset_index(drop=True)
 valid_df = train[train['kfold'] == fold].reset_index(drop=True)
 x_train, y_train = train_df[feature_cols].values, train_df[target_cols].values
x_valid, y_valid = valid_df[feature_cols].values, valid_df[target_cols].values
train_dataset = MoADataset(x_train, y_train)
 valid_dataset = MoADataset(x_valid, y_valid)
 trainloader = torch.utils.data.DataLoader(train_dataset, batch_size=BATCH_SIZE, shuffle=True)
 validloader = torch.utils.data.DataLoader(valid_dataset, batch_size=BATCH_SIZE, shuffle=False)
 model = Model(
 num_features=num_features,
num_targets=num_targets,
hidden_size=hidden_size, 
)
 model.to(DEVICE)
 optimizer = torch.optim.Adam(model.parameters() , lr=LEARNING_RATE, weight_decay=WEIGHT_DECAY)
 scheduler = optim.lr_scheduler.OneCycleLR(optimizer=optimizer, pct_start=0.1, div_factor=1e3,
max_lr=1e-2, epochs=EPOCHS, steps_per_epoch=len(trainloader))
loss_fn = nn.BCEWithLogitsLoss()
loss_tr = SmoothBCEwLogits(smoothing =0.001)
 early_stopping_steps = EARLY_STOPPING_STEPS
early_step = 0
oof = np.zeros(( len(train), target.iloc[:, 1:].shape[1]))
best_loss = np.inf
for epoch in range(EPOCHS):
train_loss = train_fn(model, optimizer,scheduler, loss_tr, trainloader, DEVICE)
 print(f"FOLD: {fold}, EPOCH: {epoch}, train_loss: {train_loss}")
 valid_loss, valid_preds = valid_fn(model, loss_fn, validloader, DEVICE)
 print(f"FOLD: {fold}, EPOCH: {epoch}, valid_loss: {valid_loss}")
 if valid_loss < best_loss:
best_loss = valid_loss
oof[val_idx] = valid_preds
torch.save(model.state_dict() , f"FOLD{fold}_.pth")
 elif(EARLY_STOP == True):
early_step += 1
if(early_step >= early_stopping_steps):
break
x_test = test_[feature_cols].values
testdataset = TestDataset(x_test)
 testloader = torch.utils.data.DataLoader(testdataset, batch_size=BATCH_SIZE, shuffle=False)
 model = Model(
 num_features=num_features,
num_targets=num_targets,
hidden_size=hidden_size, 
)
 model.load_state_dict(torch.load(f"FOLD{fold}_.pth"))
model.to(DEVICE)
 predictions = np.zeros(( len(test_), target.iloc[:, 1:].shape[1]))
predictions = inference_fn(model, testloader, DEVICE)
 return oof, predictions<categorify>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('e8333cm99.csv', index=False)
 e8333cm99 = sub
def run_k_fold(NFOLDS, seed):
oof = np.zeros(( len(train), len(target_cols)))
 predictions = np.zeros(( len(test), len(target_cols)))
 for fold in range(NFOLDS):
oof_, pred_ = run_training(fold, seed)
 predictions += pred_ / NFOLDS
oof += oof_
return oof, predictions<define_variables>
sub = pd.read_csv(dfk.iloc[5, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
SEED = [50,60,70,40,30,55]
oof = np.zeros(( len(train), len(target_cols)))
 predictions = np.zeros(( len(test), len(target_cols)))
 for seed in SEED:
oof_, predictions_ = run_k_fold(NFOLDS, seed)
 oof += oof_ / len(SEED)
 predictions += predictions_ / len(SEED )<set_options>
sub.to_csv('f8073cm99.csv', index=False)
 f8073cm99 = sub
def set_seed(seed):
random.seed(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 os.environ["PYTHONHASHSEED"] = str(seed)
 if torch.cuda.is_available() :
torch.cuda.manual_seed(seed)
 torch.cuda.manual_seed_all(seed)
 torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
seed = 42
set_seed(seed)
<import_modules>
sub = pd.read_csv(dfk.iloc[6, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
class LogitsLogLoss(Metric):

 def __init__(self):
self._name = "logits_ll"
self._maximize = False
def __call__(self, y_true, y_pred):

 logits = 1 /(1 + np.exp(-y_pred))
aux =(1 - y_true)* np.log(1 - logits + 1e-15)+ y_true * np.log(logits + 1e-15)
 return np.mean(-aux)
<define_search_space>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('g7745cm99.csv', index=False)
 g7745cm99 = sub
seeds = [8,6,3,5]
MAX_EPOCH = 100
seeds_preds = []
scores_auc_all = []
test_cv_preds = []
oof_preds = []
oof_targets = []
scores = []
scores_auc = []
tabnet_params = dict(
 n_d = 32,
n_a = 32,
n_steps = 1,
gamma = 1,
n_independent=2,
n_shared = 1,
momentum = 0.03,
lambda_sparse = 0.0,
optimizer_fn = optim.Adam,
optimizer_params = dict(lr = 2e-2, weight_decay = 1e-5),
mask_type = "entmax",
scheduler_params = dict(
 mode = "min", patience = 5, min_lr = 1e-5, factor = 0.9),
scheduler_fn = ReduceLROnPlateau,
seed = seeds[0],
verbose = 10 
)
 for seed in seeds:
tabnet_params['seed']=seed
for fold in range(NFOLDS):
print("FOLDS: ", fold + 1)
 print('*' * 60)
 train = process_data(folds)
 test_ = process_data(test)
 trn_idx = train[train['kfold'] != fold].index
val_idx = train[train['kfold'] == fold].index
train_df = train[train['kfold'] != fold].reset_index(drop=True)
 valid_df = train[train['kfold'] == fold].reset_index(drop=True)
 X_train, y_train = train_df[feature_cols].values, train_df[target_cols].values
X_val, y_val = valid_df[feature_cols].values, valid_df[target_cols].values
model = TabNetRegressor(**tabnet_params)
 model.fit(
 X_train = X_train,
y_train = y_train,
eval_set = [(X_val, y_val)],
eval_name = ["val"],
eval_metric = ["logits_ll"],
max_epochs = MAX_EPOCH,
patience = 20,
batch_size = 1024,
virtual_batch_size = 32,
num_workers = 1,
drop_last = False,
loss_fn = F.binary_cross_entropy_with_logits 
)
 print('-' * 60)
 preds_val = model.predict(X_val)
 preds = 1 /(1 + np.exp(-preds_val))
score = np.min(model.history["val_logits_ll"])
 oof_preds.append(preds_val)
 oof_targets.append(y_val)
 scores.append(score)
 X_test = test_[feature_cols].values
preds_test = model.predict(X_test)
 test_cv_preds.append(1 /(1 + np.exp(-preds_test)))
 oof_preds_all = np.concatenate(oof_preds)
 oof_targets_all = np.concatenate(oof_targets)
 test_preds_all = np.stack(test_cv_preds )<merge>
sub = pd.read_csv(dfk.iloc[7, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
submission = sample_submission.copy()
all_feat = [col for col in submission.columns if col not in ["sig_id"]]
test = test_features.copy()
sig_id = test[test["cp_type"] != "ctl_vehicle"].sig_id.reset_index(drop = True)
 tmp = pd.DataFrame(( predictions + test_preds_all.mean(axis = 0)) /2, columns = all_feat)
 tmp["sig_id"] = sig_id
submission = pd.merge(test[["sig_id"]], tmp, on = "sig_id", how = "left")
 submission.fillna(0, inplace = True )<save_to_csv>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('h7661cm99.csv', index=False)
 h7661cm99 = sub
submission.to_csv("submission.csv", index = None )<import_modules>
sub = pd.read_csv(dfk.iloc[8, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
import pickle
import numpy as np
import pandas as pd
import tensorflow as tf<define_variables>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('i7274cm99.csv', index=False)
 i7274cm99 = sub
MIXED_PRECISION = False
XLA_ACCELERATE = True<set_options>
sub = pd.read_csv(dfk.iloc[9, 2])
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp' )
if MIXED_PRECISION:
policy = tf.keras.mixed_precision.experimental.Policy("mixed_float16")
 tf.keras.mixed_precision.experimental.set_policy(policy)
 tf.config.optimizer.set_jit(XLA_ACCELERATE )<choose_model_class>
simple_accurate_99 = pd.read_csv(dfk.iloc[5, 2])
 sub['floor'] = simple_accurate_99['floor'].values
sub.to_csv('j7285cm99.csv', index=False)
 j7285cm99 = sub
def build_callbacks(
 checkpoint_path,
factor=0.1,
mode="auto",
monitor="val_loss",
patience_for_es=0,
patience_for_rlop=10,
save_best_only=False,
verbose=0, 
):
callbacks = []
if checkpoint_path is not None:
model_checkpoint = tf.keras.callbacks.ModelCheckpoint(
 checkpoint_path,
mode=mode,
monitor=monitor,
save_best_only=save_best_only,
verbose=verbose, 
)
 callbacks.append(model_checkpoint)
 if patience_for_es is not None:
early_stopping = tf.keras.callbacks.EarlyStopping(
 mode=mode, monitor=monitor, patience=patience_for_es, verbose=verbose 
)
 callbacks.append(early_stopping)
 if patience_for_rlop is not None:
reduce_lr_on_plateau = tf.keras.callbacks.ReduceLROnPlateau(
 factor=factor,
monitor=monitor,
mode=mode,
patience=patience_for_rlop,
verbose=verbose, 
)
 callbacks.append(reduce_lr_on_plateau)
 return callbacks<choose_model_class>
gfk = pd.DataFrame({
'Kernel ID' : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
'Before Score': [9.773, 9.530, 8.500, 8.418, 8.333, 8.073, 7.745, 7.661, 7.274, 7.285],
'After Score' : [7.110, 6.674, 6.290, 6.189, 6.077, 6.062, 5.995, 5.694, 5.471, 5.847],
'File Name' : ['a9773cm99.csv', 'b9530cm99.csv', 'c8500cm99.csv', 'd8418cm99.csv', 'e8333cm99.csv', 'f8073cm99.csv', 'g7745cm99.csv', 'h7661cm99.csv', 'i7274cm99.csv', 'j7285cm99.csv']
})
 gfk
<compute_test_metric><EOS> 
sub = i7274cm99
sub.to_csv("submission.csv", index=False)
 a9773cm99.to_csv("a9773cm99.csv", index=False)
 b9530cm99.to_csv("b9530cm99.csv", index=False)
 c8500cm99.to_csv("c8500cm99.csv", index=False)
 d8418cm99.to_csv("d8418cm99.csv", index=False)
 e8333cm99.to_csv("e8333cm99.csv", index=False)
 f8073cm99.to_csv("f8073cm99.csv", index=False)
 g7745cm99.to_csv("g7745cm99.csv", index=False)
 h7661cm99.to_csv("h7661cm99.csv", index=False)
 i7274cm99.to_csv("i7274cm99.csv", index=False)
 j7285cm99.to_csv("j7285cm99.csv", index=False)
 !ls