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'],
'Score' : [7.110, 6.674, 6.290, 6.189, 6.077, 6.062, 5.995, 5.694, 5.471, 5.847],
'File Path': ['.. /input/1-3-indoor-navigation-cost-minimization-floor/a9773cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/b9530cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/c8500cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/d8418cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/e8333cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/f8073cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/g7745cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/h7661cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/i7274cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/j7285cm99.csv']
})
 dfk
def seed_everything(seed=42):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
seed_everything(seed=42 )<create_dataframe>
ff1x = 0.60
ff1y = 0.60
ff2x = 0.60
ff2y = 0.60
ff3x = 0.90
ff3y = 0.90
ff4x = 0.95
ff4y = 0.95
main = pd.read_csv(dfk.iloc[8, 2])
 support = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated1 = 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(6):
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, 6):
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(3, 5):
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})
 ')
 for k in range(3):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff4x)+(kx[k][j] *(1.- ff4x))
ey =(ey * ff4y)+(ky[k][j] *(1.- ff4y))
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)
 generated1.iloc[:, 2] = rx
generated1.iloc[:, 3] = ry
data = pd.concat([pd.DataFrame(train_features[GENES]), pd.DataFrame(test_features[GENES])])
 data2 =(PCA(n_components=n_comp_GENES, random_state=42 ).fit_transform(data[GENES]))
train2 = data2[:train_features.shape[0]]; test2 = data2[-test_features.shape[0]:]
train2 = pd.DataFrame(train2, columns=[f'pca_G-{i}' for i in range(n_comp_GENES)])
 test2 = pd.DataFrame(test2, columns=[f'pca_G-{i}' for i in range(n_comp_GENES)])
 train_features = pd.concat(( train_features, train2), axis=1)
 test_features = pd.concat(( test_features, test2), axis=1 )<concatenate>
ff1x = 0.60
ff1y = 0.60
ff2x = 0.60
ff2y = 0.60
ff3x = 0.90
ff3y = 0.90
ff4x = 0.95
ff4y = 0.95
main = pd.read_csv(dfk.iloc[7, 2])
 support = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated2 = 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(6):
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, 6):
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(3, 5):
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})
 ')
 for k in range(3):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff4x)+(kx[k][j] *(1.- ff4x))
ey =(ey * ff4y)+(ky[k][j] *(1.- ff4y))
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)
 generated2.iloc[:, 2] = rx
generated2.iloc[:, 3] = ry
data = pd.concat([pd.DataFrame(train_features[CELLS]), pd.DataFrame(test_features[CELLS])])
 data2 =(PCA(n_components=n_comp_CELLS, random_state=42 ).fit_transform(data[CELLS]))
train2 = data2[:train_features.shape[0]]; test2 = data2[-test_features.shape[0]:]
train2 = pd.DataFrame(train2, columns=[f'pca_C-{i}' for i in range(n_comp_CELLS)])
 test2 = pd.DataFrame(test2, columns=[f'pca_C-{i}' for i in range(n_comp_CELLS)])
 train_features = pd.concat(( train_features, train2), axis=1)
 test_features = pd.concat(( test_features, test2), axis=1 )<concatenate>
ff1x = 0.60
ff1y = 0.60
main = generated1
support = generated2
rx , ry = [] , []
generated3 = 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()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
rx.append(ex)
 ry.append(ey)
 generated3.iloc[:, 2] = rx
generated3.iloc[:, 3] = ry
data = train_features.append(test_features )<create_dataframe>
ff1x = 0.44
ff1y = 0.44
ff2x = 0.24
ff2y = 0.24
ff3x = 0.32
ff3y = 0.32
main = pd.read_csv(dfk.iloc[8, 2])
 support1 = pd.read_csv(dfk.iloc[7, 2])
 support2 = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated4 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
s1x , s1y = [] , []
s1x = support1.iloc[:, 2].tolist()
s1y = support1.iloc[:, 3].tolist()
s2x , s2y = [] , []
s2x = support2.iloc[:, 2].tolist()
s2y = support2.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(s1x[j] * ff2x)+(s2x[j] * ff3x)
 ey =(my[j] * ff1y)+(s1y[j] * ff2y)+(s2y[j] * ff3y)
 rx.append(ex)
 ry.append(ey)
 generated4.iloc[:, 2] = rx
generated4.iloc[:, 3] = ry
var_thresh = VarianceThreshold(VarianceThreshold_for_FS)
 data = train_features.append(test_features)
 data_transformed = var_thresh.fit_transform(data.iloc[:, 4:])
 train_features_transformed = data_transformed[ : train_features.shape[0]]
test_features_transformed = data_transformed[-test_features.shape[0] : ]
train_features = pd.DataFrame(train_features[['sig_id','cp_type','cp_time','cp_dose']].values.reshape(-1, 4),\
columns=['sig_id','cp_type','cp_time','cp_dose'])
 train_features = pd.concat([train_features, pd.DataFrame(train_features_transformed)], axis=1)
 test_features = pd.DataFrame(test_features[['sig_id','cp_type','cp_time','cp_dose']].values.reshape(-1, 4),\
columns=['sig_id','cp_type','cp_time','cp_dose'])
 test_features = pd.concat([test_features, pd.DataFrame(test_features_transformed)], axis=1)
 train_features.shape<define_search_model>
ff1x = 0.50
ff1y = 0.50
main = generated3
support = generated4
rx , ry = [] , []
generated5 = 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()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
rx.append(ex)
 ry.append(ey)
 generated5.iloc[:, 2] = rx
generated5.iloc[:, 3] = ry
def fe_cluster_genes(train, test, n_clusters_g = 22, SEED = 42):
features_g = GENES
def create_cluster(train, test, features, kind = 'g', n_clusters = n_clusters_g):
train_ = train[features].copy()
test_ = test[features].copy()
data = pd.concat([train_, test_], axis = 0)
 kmeans_genes = KMeans(n_clusters = n_clusters, random_state = SEED ).fit(data)
 dump(kmeans_genes, open('kmeans_genes.pkl', 'wb'))
train[f'clusters_{kind}'] = kmeans_genes.predict(train_.values)
 test[f'clusters_{kind}'] = kmeans_genes.predict(test_.values)
 train = pd.get_dummies(train, columns = [f'clusters_{kind}'])
 test = pd.get_dummies(test, columns = [f'clusters_{kind}'])
 return train, test
train, test = create_cluster(train, test, features_g, kind = 'g', n_clusters = n_clusters_g)
 return train, test
train_features2 ,test_features2=fe_cluster_genes(train_features2,test_features2)
<find_best_model_class>
ff1x = 0.40
ff1y = 0.40
ff2x = 0.25
ff2y = 0.25
ff3x = 0.35
ff3y = 0.35
main = pd.read_csv(dfk.iloc[8, 2])
 support1 = pd.read_csv(dfk.iloc[7, 2])
 support2 = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated6 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
s1x , s1y = [] , []
s1x = support1.iloc[:, 2].tolist()
s1y = support1.iloc[:, 3].tolist()
s2x , s2y = [] , []
s2x = support2.iloc[:, 2].tolist()
s2y = support2.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(s1x[j] * ff2x)+(s2x[j] * ff3x)
 ey =(my[j] * ff1y)+(s1y[j] * ff2y)+(s2y[j] * ff3y)
 rx.append(ex)
 ry.append(ey)
 generated6.iloc[:, 2] = rx
generated6.iloc[:, 3] = ry
<split><EOS> 
sub = generated5
sub.to_csv("submission.csv", index=False)
 generated1.to_csv("generated1.csv", index=False)
 generated2.to_csv("generated2.csv", index=False)
 generated3.to_csv("generated3.csv", index=False)
 generated4.to_csv("generated4.csv", index=False)
 generated5.to_csv("generated5.csv", index=False)
 generated6.to_csv("generated6.csv", index=False)
 !ls