# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.8.0 64-bit (''venv'': virtualenv)'
#     language: python
#     name: python38064bitvenvvirtualenve617f17e49084a7c973a4e86cf48a722
# ---

# +
import sys
sys.path.append('..')

from utils.misc import *
from utils.classifier import *
from utils.visualiser import *
# -

# ## Loading pre-processed data

# +
# train
df_train = pd.read_csv("../data/train/df_train.csv", index_col=0)

df_train_b0 = pd.read_csv("../data/train/df_train_b0.csv", index_col=0)
df_train_b1 = pd.read_csv("../data/train/df_train_b1.csv", index_col=0)
df_train_b2 = pd.read_csv("../data/train/df_train_b2.csv", index_col=0)

df_train_b0_f0 = pd.read_csv("../data/train/df_train_b0_f0.csv", index_col=0)
df_train_b0_f1 = pd.read_csv("../data/train/df_train_b0_f1.csv", index_col=0)
df_train_b0_f2 = pd.read_csv("../data/train/df_train_b0_f2.csv", index_col=0)
df_train_b0_f3 = pd.read_csv("../data/train/df_train_b0_f3.csv", index_col=0)

df_train_b1_f0 = pd.read_csv("../data/train/df_train_b1_f0.csv", index_col=0)
df_train_b1_f1 = pd.read_csv("../data/train/df_train_b1_f1.csv", index_col=0)
df_train_b1_f2 = pd.read_csv("../data/train/df_train_b1_f2.csv", index_col=0)
df_train_b1_f3 = pd.read_csv("../data/train/df_train_b1_f3.csv", index_col=0)

df_train_b2_f0 = pd.read_csv("../data/train/df_train_b2_f0.csv", index_col=0)
df_train_b2_f1 = pd.read_csv("../data/train/df_train_b2_f1.csv", index_col=0)
df_train_b2_f2 = pd.read_csv("../data/train/df_train_b2_f2.csv", index_col=0)
df_train_b2_f3 = pd.read_csv("../data/train/df_train_b2_f3.csv", index_col=0)
df_train_b2_f4 = pd.read_csv("../data/train/df_train_b2_f4.csv", index_col=0)

df_train_wap = np.load("../data/train/df_train_wap.npy", allow_pickle=True)

df_train_b0_wap = np.load("../data/train/df_train_b0_wap.npy", allow_pickle=True)
df_train_b1_wap = np.load("../data/train/df_train_b1_wap.npy", allow_pickle=True)
df_train_b2_wap = np.load("../data/train/df_train_b2_wap.npy", allow_pickle=True)

df_train_b0_f0_wap = np.load("../data/train/df_train_b0_f0_wap.npy", allow_pickle=True)
df_train_b0_f1_wap = np.load("../data/train/df_train_b0_f1_wap.npy", allow_pickle=True)
df_train_b0_f2_wap = np.load("../data/train/df_train_b0_f2_wap.npy", allow_pickle=True)
df_train_b0_f3_wap = np.load("../data/train/df_train_b0_f3_wap.npy", allow_pickle=True)

df_train_b1_f0_wap = np.load("../data/train/df_train_b1_f0_wap.npy", allow_pickle=True)
df_train_b1_f1_wap = np.load("../data/train/df_train_b1_f1_wap.npy", allow_pickle=True)
df_train_b1_f2_wap = np.load("../data/train/df_train_b1_f2_wap.npy", allow_pickle=True)
df_train_b1_f3_wap = np.load("../data/train/df_train_b1_f3_wap.npy", allow_pickle=True)

df_train_b2_f0_wap = np.load("../data/train/df_train_b2_f0_wap.npy", allow_pickle=True)
df_train_b2_f1_wap = np.load("../data/train/df_train_b2_f1_wap.npy", allow_pickle=True)
df_train_b2_f2_wap = np.load("../data/train/df_train_b2_f2_wap.npy", allow_pickle=True)
df_train_b2_f3_wap = np.load("../data/train/df_train_b2_f3_wap.npy", allow_pickle=True)
df_train_b2_f4_wap = np.load("../data/train/df_train_b2_f4_wap.npy", allow_pickle=True)
# -

# test
df_test = pd.read_csv("../data/test/df_test.csv", index_col=0)

# ## Dividing space by direction
#

# ### Building 0

# +
lat_split = np.mean(df_train_b0['LATITUDE'].astype(float))
# long_split = np.mean(df_train_b0['LONGITUDE'].astype(float))

# NE
df_train_b0_ne = df_train_b0[(df_train_b0['LATITUDE'] >= lat_split) & 
                             (df_train_b0['LONGITUDE'] >= -7629)]
# NW
df_train_b0_nw = df_train_b0[(df_train_b0['LATITUDE'] >= lat_split) & 
                             (df_train_b0['LONGITUDE'] < -7629)]
# SE
df_train_b0_se = df_train_b0[(df_train_b0['LATITUDE'] < lat_split) & 
                             (df_train_b0['LONGITUDE'] >= -7655)]
# SW
df_train_b0_sw = df_train_b0[(df_train_b0['LATITUDE'] < lat_split) & 
                             (df_train_b0['LONGITUDE'] < -7655)]

# +
# floors in NE
df_train_b0_ne_f0 = df_train_b0_ne[df_train_b0_ne['FLOOR'] == 0]
df_train_b0_ne_f1 = df_train_b0_ne[df_train_b0_ne['FLOOR'] == 1]
df_train_b0_ne_f2 = df_train_b0_ne[df_train_b0_ne['FLOOR'] == 2]
df_train_b0_ne_f3 = df_train_b0_ne[df_train_b0_ne['FLOOR'] == 3]

# floors in NW
df_train_b0_nw_f0 = df_train_b0_nw[df_train_b0_nw['FLOOR'] == 0]
df_train_b0_nw_f1 = df_train_b0_nw[df_train_b0_nw['FLOOR'] == 1]
df_train_b0_nw_f2 = df_train_b0_nw[df_train_b0_nw['FLOOR'] == 2]
df_train_b0_nw_f3 = df_train_b0_nw[df_train_b0_nw['FLOOR'] == 3]

# floors in SE
df_train_b0_se_f0 = df_train_b0_se[df_train_b0_se['FLOOR'] == 0]
df_train_b0_se_f1 = df_train_b0_se[df_train_b0_se['FLOOR'] == 1]
df_train_b0_se_f2 = df_train_b0_se[df_train_b0_se['FLOOR'] == 2]
df_train_b0_se_f3 = df_train_b0_se[df_train_b0_se['FLOOR'] == 3]

# floors in SW
df_train_b0_sw_f0 = df_train_b0_sw[df_train_b0_sw['FLOOR'] == 0]
df_train_b0_sw_f1 = df_train_b0_sw[df_train_b0_sw['FLOOR'] == 1]
df_train_b0_sw_f2 = df_train_b0_sw[df_train_b0_sw['FLOOR'] == 2]
df_train_b0_sw_f3 = df_train_b0_sw[df_train_b0_sw['FLOOR'] == 3]
# -

# ### Building 1

# +
# NE
df_train_b1_ne = df_train_b1[(df_train_b1['LATITUDE'] >= 4864850) & 
                             (df_train_b1['LONGITUDE'] >= -7465)]
# NW
df_train_b1_nw = df_train_b1[(df_train_b1['LATITUDE'] >= 4864900) & 
                             (df_train_b1['LONGITUDE'] < -7510)]
# SE
df_train_b1_se = df_train_b1[(df_train_b1['LATITUDE'] < 4864855) & 
                             (df_train_b1['LONGITUDE'] >= -7480)]
# SW
df_train_b1_sw = df_train_b1[(df_train_b1['LATITUDE'] < 4864900) & 
                             (df_train_b1['LONGITUDE'] < -7540)]

# CENTRE
df_train_b1_ct = df_train_b1[(df_train_b1['LATITUDE'] >= 4864830) & 
                             (df_train_b1['LATITUDE'] < 4864920) &
                             (df_train_b1['LONGITUDE'] >= -7540) &
                             (df_train_b1['LONGITUDE'] < -7465)]

# +
# floors in NE
df_train_b1_ne_f0 = df_train_b1_ne[df_train_b1_ne['FLOOR'] == 0]
df_train_b1_ne_f1 = df_train_b1_ne[df_train_b1_ne['FLOOR'] == 1]
df_train_b1_ne_f2 = df_train_b1_ne[df_train_b1_ne['FLOOR'] == 2]
df_train_b1_ne_f3 = df_train_b1_ne[df_train_b1_ne['FLOOR'] == 3]

# floors in NW
df_train_b1_nw_f0 = df_train_b1_nw[df_train_b1_nw['FLOOR'] == 0]
df_train_b1_nw_f1 = df_train_b1_nw[df_train_b1_nw['FLOOR'] == 1]
df_train_b1_nw_f2 = df_train_b1_nw[df_train_b1_nw['FLOOR'] == 2]
df_train_b1_nw_f3 = df_train_b1_nw[df_train_b1_nw['FLOOR'] == 3]

# floors in SE
df_train_b1_se_f0 = df_train_b1_se[df_train_b1_se['FLOOR'] == 0]
df_train_b1_se_f1 = df_train_b1_se[df_train_b1_se['FLOOR'] == 1]
df_train_b1_se_f2 = df_train_b1_se[df_train_b1_se['FLOOR'] == 2]
df_train_b1_se_f3 = df_train_b1_se[df_train_b1_se['FLOOR'] == 3]

# floors in SW
df_train_b1_sw_f0 = df_train_b1_sw[df_train_b1_sw['FLOOR'] == 0]
df_train_b1_sw_f1 = df_train_b1_sw[df_train_b1_sw['FLOOR'] == 1]
df_train_b1_sw_f2 = df_train_b1_sw[df_train_b1_sw['FLOOR'] == 2]
df_train_b1_sw_f3 = df_train_b1_sw[df_train_b1_sw['FLOOR'] == 3]

# floors in CT
df_train_b1_ct_f0 = df_train_b1_ct[df_train_b1_ct['FLOOR'] == 0]
df_train_b1_ct_f1 = df_train_b1_ct[df_train_b1_ct['FLOOR'] == 1]
df_train_b1_ct_f2 = df_train_b1_ct[df_train_b1_ct['FLOOR'] == 2]
df_train_b1_ct_f3 = df_train_b1_ct[df_train_b1_ct['FLOOR'] == 3]
# -

# ### Building 2

# NE
df_train_b2_ne = df_train_b2[(df_train_b2['LATITUDE'] >= 4864780) & 
                             (df_train_b2['LONGITUDE'] >= -7345)]
# NW
df_train_b2_nw = df_train_b2[(df_train_b2['LATITUDE'] >= 4864820) & 
                             (df_train_b2['LONGITUDE'] < -7340)]
# SE
df_train_b2_se = df_train_b2[(df_train_b2['LATITUDE'] < 4864780) & 
                             (df_train_b2['LONGITUDE'] >= -7375)]
# SW
df_train_b2_sw = df_train_b2[(df_train_b2['LATITUDE'] < 4864820) & 
                             (df_train_b2['LONGITUDE'] < -7375)]

# +
# floors in NE
df_train_b2_ne_f0 = df_train_b2_ne[df_train_b2_ne['FLOOR'] == 0]
df_train_b2_ne_f1 = df_train_b2_ne[df_train_b2_ne['FLOOR'] == 1]
df_train_b2_ne_f2 = df_train_b2_ne[df_train_b2_ne['FLOOR'] == 2]
df_train_b2_ne_f3 = df_train_b2_ne[df_train_b2_ne['FLOOR'] == 3]
df_train_b2_ne_f4 = df_train_b2_ne[df_train_b2_ne['FLOOR'] == 4]

# floors in NW
df_train_b2_nw_f0 = df_train_b2_nw[df_train_b2_nw['FLOOR'] == 0]
df_train_b2_nw_f1 = df_train_b2_nw[df_train_b2_nw['FLOOR'] == 1]
df_train_b2_nw_f2 = df_train_b2_nw[df_train_b2_nw['FLOOR'] == 2]
df_train_b2_nw_f3 = df_train_b2_nw[df_train_b2_nw['FLOOR'] == 3]
df_train_b2_nw_f4 = df_train_b2_nw[df_train_b2_nw['FLOOR'] == 4]

# floors in SE
df_train_b2_se_f0 = df_train_b2_se[df_train_b2_se['FLOOR'] == 0]
df_train_b2_se_f1 = df_train_b2_se[df_train_b2_se['FLOOR'] == 1]
df_train_b2_se_f2 = df_train_b2_se[df_train_b2_se['FLOOR'] == 2]
df_train_b2_se_f3 = df_train_b2_se[df_train_b2_se['FLOOR'] == 3]
df_train_b2_se_f4 = df_train_b2_se[df_train_b2_se['FLOOR'] == 4]

# floors in SW
df_train_b2_sw_f0 = df_train_b2_sw[df_train_b2_sw['FLOOR'] == 0]
df_train_b2_sw_f1 = df_train_b2_sw[df_train_b2_sw['FLOOR'] == 1]
df_train_b2_sw_f2 = df_train_b2_sw[df_train_b2_sw['FLOOR'] == 2]
df_train_b2_sw_f3 = df_train_b2_sw[df_train_b2_sw['FLOOR'] == 3]
df_train_b2_sw_f4 = df_train_b2_sw[df_train_b2_sw['FLOOR'] == 4]
# -

# ## Normalisation & PCA

# +
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA

def preprocess(data, filename='df'):
    ss = StandardScaler()
    pca = PCA(n_components=.95)
    df = data.iloc[:, :465]
    df = ss.fit_transform(df)
    df = pca.fit_transform(df)
    
    data.to_csv("../data/train/area/" + filename + ".csv")
    np.save("../data/train/area/" + filename + "_wap.npy", df)


# -

# ### Building 0

# +
kwargs = {
    'data'    : df_train_b0_ne,
    'filename': 'df_train_b0_ne'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b0_nw,
    'filename': 'df_train_b0_nw'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b0_se,
    'filename': 'df_train_b0_se'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b0_sw,
    'filename': 'df_train_b0_sw'
}

preprocess(**kwargs)

# +
preprocess(df_train_b0_ne_f0, 'df_train_b0_ne_f0')
preprocess(df_train_b0_ne_f1, 'df_train_b0_ne_f1')
preprocess(df_train_b0_ne_f2, 'df_train_b0_ne_f2')
preprocess(df_train_b0_ne_f3, 'df_train_b0_ne_f3')

preprocess(df_train_b0_nw_f0, 'df_train_b0_nw_f0')
preprocess(df_train_b0_nw_f1, 'df_train_b0_nw_f1')
preprocess(df_train_b0_nw_f2, 'df_train_b0_nw_f2')
preprocess(df_train_b0_nw_f3, 'df_train_b0_nw_f3')

preprocess(df_train_b0_se_f0, 'df_train_b0_se_f0')
preprocess(df_train_b0_se_f1, 'df_train_b0_se_f1')
preprocess(df_train_b0_se_f2, 'df_train_b0_se_f2')
preprocess(df_train_b0_se_f3, 'df_train_b0_se_f3')

preprocess(df_train_b0_sw_f0, 'df_train_b0_sw_f0')
preprocess(df_train_b0_sw_f1, 'df_train_b0_sw_f1')
preprocess(df_train_b0_sw_f2, 'df_train_b0_sw_f2')
preprocess(df_train_b0_sw_f3, 'df_train_b0_sw_f3')
# -

# ### Building 1

# +
kwargs = {
    'data'    : df_train_b1_ne,
    'filename': 'df_train_b1_ne'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b1_nw,
    'filename': 'df_train_b1_nw'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b1_se,
    'filename': 'df_train_b1_se'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b1_sw,
    'filename': 'df_train_b1_sw'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b1_ct,
    'filename': 'df_train_b1_ct'
}

preprocess(**kwargs)

# +
preprocess(df_train_b1_ne_f0, 'df_train_b1_ne_f0')
preprocess(df_train_b1_ne_f1, 'df_train_b1_ne_f1')
preprocess(df_train_b1_ne_f2, 'df_train_b1_ne_f2')
preprocess(df_train_b1_ne_f3, 'df_train_b1_ne_f3')

preprocess(df_train_b1_nw_f0, 'df_train_b1_nw_f0')
preprocess(df_train_b1_nw_f1, 'df_train_b1_nw_f1')
preprocess(df_train_b1_nw_f2, 'df_train_b1_nw_f2')
preprocess(df_train_b1_nw_f3, 'df_train_b1_nw_f3')

preprocess(df_train_b1_se_f0, 'df_train_b1_se_f0')
preprocess(df_train_b1_se_f1, 'df_train_b1_se_f1')
preprocess(df_train_b1_se_f2, 'df_train_b1_se_f2')
preprocess(df_train_b1_se_f3, 'df_train_b1_se_f3')

preprocess(df_train_b1_sw_f0, 'df_train_b1_sw_f0')
preprocess(df_train_b1_sw_f1, 'df_train_b1_sw_f1')
preprocess(df_train_b1_sw_f2, 'df_train_b1_sw_f2')
preprocess(df_train_b1_sw_f3, 'df_train_b1_sw_f3')

preprocess(df_train_b1_ct_f0, 'df_train_b1_ct_f0')
preprocess(df_train_b1_ct_f1, 'df_train_b1_ct_f1')
preprocess(df_train_b1_ct_f2, 'df_train_b1_ct_f2')
preprocess(df_train_b1_ct_f3, 'df_train_b1_ct_f3')
# -

# ### Building 2

# +
kwargs = {
    'data'    : df_train_b2_ne,
    'filename': 'df_train_b2_ne'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b2_nw,
    'filename': 'df_train_b2_nw'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b2_se,
    'filename': 'df_train_b2_se'
}

preprocess(**kwargs)

# +
kwargs = {
    'data'    : df_train_b2_sw,
    'filename': 'df_train_b2_sw'
}

preprocess(**kwargs)

# +
preprocess(df_train_b2_ne_f0, 'df_train_b2_ne_f0')
preprocess(df_train_b2_ne_f1, 'df_train_b2_ne_f1')
preprocess(df_train_b2_ne_f2, 'df_train_b2_ne_f2')
preprocess(df_train_b2_ne_f3, 'df_train_b2_ne_f3')
preprocess(df_train_b2_ne_f4, 'df_train_b2_ne_f4')

preprocess(df_train_b2_nw_f0, 'df_train_b2_nw_f0')
preprocess(df_train_b2_nw_f1, 'df_train_b2_nw_f1')
preprocess(df_train_b2_nw_f2, 'df_train_b2_nw_f2')
preprocess(df_train_b2_nw_f3, 'df_train_b2_nw_f3')
preprocess(df_train_b2_nw_f4, 'df_train_b2_nw_f4')

preprocess(df_train_b2_se_f0, 'df_train_b2_se_f0')
preprocess(df_train_b2_se_f1, 'df_train_b2_se_f1')
preprocess(df_train_b2_se_f2, 'df_train_b2_se_f2')
preprocess(df_train_b2_se_f3, 'df_train_b2_se_f3')
# preprocess(df_train_b2_se_f4, 'df_train_b2_se_f4') # no samples

preprocess(df_train_b2_sw_f0, 'df_train_b2_sw_f0')
preprocess(df_train_b2_sw_f1, 'df_train_b2_sw_f1')
preprocess(df_train_b2_sw_f2, 'df_train_b2_sw_f2')
preprocess(df_train_b2_sw_f3, 'df_train_b2_sw_f3')
preprocess(df_train_b2_sw_f4, 'df_train_b2_sw_f4')
# -



StarcoderdataJupyterScriptsDedupFiltered