Kaggle competition: Indoor Location & Navigation
<SOS> metric: IndoorLocalization Kaggle data source: indoor-location-&-navigation<set_options>
%matplotlib inline
dfk = pd.DataFrame({
'Kernel ID': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'],
'Score': [14.763, 13.168, 11.600, 10.959, 9.773, 9.530, 8.500, 8.418, 8.333, 8.309, 8.073, 7.745, 7.661],
'File Path': ['.. /input/indoor14763/Indoor14763.csv', '.. /input/indoor13168/Indoor13168.csv', '.. /input/indoor11600/Indoor11600.csv', '.. /input/indoor10959/Indoor10959.csv', '.. /input/indoor9773/Indoor9773.csv', '.. /input/indoor9530/Indoor9530.csv', '.. /input/indoor8500/Indoor8500.csv', '.. /input/indoor8418/Indoor8418.csv', '.. /input/indoor8333/Indoor8333.csv', '.. /input/indoor8309/Indoor8309.csv', '.. /input/indoor8073/Indoor8073.csv', '.. /input/indoornav7745sub/submission.csv', '.. /input/indoor7661/Indoor7661.csv']
})
 dfk
def set_seed(seed=0):
os.environ["PYTHONHASHSEED"] = str(seed)
 rn.seed(seed)
 np.random.seed(seed)
 tf.random.set_seed(seed)
 graph = tf.compat.v1.get_default_graph()
session_conf = tf.compat.v1.ConfigProto(
 inter_op_parallelism_threads=1, intra_op_parallelism_threads=1 
)
 sess = tf.compat.v1.Session(graph=graph, config=session_conf)
 tf.compat.v1.keras.backend.set_session(sess )<train_model>
ff1x = 0.50
ff1y = 0.50
ff2x = 0.95
ff2y = 0.95
ff3x = 0.90
ff3y = 0.90
main = pd.read_csv(dfk.iloc[12, 2])
 support = pd.read_csv(dfk.iloc[11, 2])
 rx , ry = [] , []
generated = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
sx , sy = [] , []
sx = support.iloc[:, 2].tolist()
sy = support.iloc[:, 3].tolist()
kx = [[],[],[],[],[],[],[],[],[],[],[]]
ky = [[],[],[],[],[],[],[],[],[],[],[]]
for n in range(11):
kernel = pd.read_csv(dfk.iloc[n, 2])
 kx[n] = kernel.iloc[:, 2].tolist()
ky[n] = kernel.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
if(mx[j] >= sx[j]):
a = mx[j]
b = sx[j]
else:
a = sx[j]
b = mx[j]
if(my[j] >= sy[j]):
c = my[j]
d = sy[j]
else:
c = sy[j]
d = my[j]
for k in range(5):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff2x)+(kx[k][j] *(1.- ff2x))
ey =(ey * ff2y)+(ky[k][j] *(1.- ff2y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 for k in range(5, 11):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff3x)+(kx[k][j] *(1.- ff3x))
ey =(ey * ff3y)+(ky[k][j] *(1.- ff3y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 rx.append(ex)
 ry.append(ey)
 generated.iloc[:, 2] = rx
generated.iloc[:, 3] = ry
def mixup(x, y=None, alpha=0.2, p=1.0, random_state=None):
n, _ = x.shape
if n is not None and rn.random() < p:
random_state = check_random_state(random_state)
 l = random_state.beta(alpha, alpha)
 shuffle = random_state.choice(n, n, replace=False)
 x = l * x +(1.0 - l)* x[shuffle]
if y is not None:
y = l * y +(1.0 - l)* y[shuffle]
return x, y
class ModelWithMixup(tf.keras.models.Model):
def __init__(self, *args, alpha=1.0, p=1.0, **kwargs):
super().__init__(*args, **kwargs)
 self.alpha = alpha
self.p = p
def train_step(self, data):
data = mixup(*data, alpha=self.alpha, p=self.p)
 return super().train_step(data )<features_selection>
import json
import matplotlib.pylab as plt
<load_from_csv><EOS> 
sub = generated
sub.to_csv("submission.csv", index=False)