"""
# EDA on dataset - 2
"""
#importing the required libraries
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy.fft import fft,fftfreq
from sklearn.preprocessing import StandardScaler
#loading the dataset using pandas
x_train = pd.read_csv("../input/power-quality-distribution-dataset-2/VoltageL1Train.csv")
y_train = pd.read_csv("../input/power-quality-distribution-dataset-2/outputTrain.csv")
x_test = pd.read_csv("../input/power-quality-distribution-dataset-2/VoltageL1Test.csv")
y_test = pd.read_csv("../input/power-quality-distribution-dataset-2/outputTest.csv")
print("x_train",x_train.shape)
print("y_train",y_train.shape)
print("x_test",x_test.shape)
print("y_test",y_test.shape)
"""
## Data Preprocessing
"""
"""
This segment of notebook contains all the preprocessing steps which are performed on the data.
"""
header =[]
for i in range(1,x_train.shape[1]+1):
    header.append("Col"+str(i))

x_train.columns = header
x_test.columns = header
header = ["output"]
y_train.columns = header
y_test.columns = header
x_train = x_train.to_numpy()
x_test = x_test.to_numpy()
X_train = np.zeros((x_train.shape[0],256))
X_test = np.zeros((x_test.shape[0],256))

for i in range(0,x_train.shape[0]):
    for j in range(0,256):
         X_train[i][j] = x_train[i][j]#+x_train[i][255-j]

for i in range(0,x_test.shape[0]):
    for j in range(0,256):
        X_test[i][j] = x_test[i][j]#+x_test[i][255-j]
    
print(X_train.shape)
X_train
transform = StandardScaler()
X_norm = transform.fit_transform(X_train)
X_norm_fft = X_train.copy()
n = X_norm_fft.shape[0]
for i in range(0,x_train.shape[0]):
    X_norm_fft[i][:] = np.abs(fft(X_train[i][:]))
transform = StandardScaler()
X_norm_fft = np.log(X_norm_fft)#transform.fit_transform(X_norm_fft)    
print("class", "TYPE-1")
fig, axes = plt.subplots(2, 2,figsize=(16,8))

#raw data
axes[0][0].plot([i for i in range(1,257)], X_train[0][0:256])
axes[0][0].title.set_text('Raw_data')

#with fft
yf = fft(X_train[0][0:256])
xf = fftfreq(256,1/256)
axes[0][1].plot(xf, np.abs(yf))
axes[0][1].title.set_text('With_FFT')

#after normalization
axes[1][0].plot([i for i in range(1,257)], X_norm[0][0:256])
axes[1][0].title.set_text('With_Norm')

#with normalization and fft
axes[1][1].plot([i for i in range(1,257)], X_norm_fft[0][0:256])
axes[1][1].title.set_text('With_NormAndFFT')
print("class", "TYPE-2")
fig, axes = plt.subplots(2, 2,figsize=(16,8))

#raw data
axes[0][0].plot([i for i in range(1,257)], X_train[1995][0:256])
axes[0][0].title.set_text('Raw_data')

#with fft
yf = fft(X_train[1995][0:256])
xf = fftfreq(256,1/256)
axes[0][1].plot(xf, np.abs(yf))
axes[0][1].title.set_text('With_FFT')

#after normalization
axes[1][0].plot([i for i in range(1,257)], X_norm[1995][0:256])
axes[1][0].title.set_text('With_Norm')

#with normalization and fft
axes[1][1].plot([i for i in range(1,257)], X_norm_fft[1995][0:256])
axes[1][1].title.set_text('With_NormAndFFT')
print("class", "TYPE-3")
fig, axes = plt.subplots(2, 2,figsize=(16,8))

#raw data
axes[0][0].plot([i for i in range(1,257)], X_train[1999][0:256])
axes[0][0].title.set_text('Raw_data')

#with fft
yf = fft(X_train[1999][0:256])
xf = fftfreq(256,1/256)
axes[0][1].plot(xf, np.abs(yf))
axes[0][1].title.set_text('With_FFT')

#after normalization
axes[1][0].plot([i for i in range(1,257)], X_norm[1999][0:256])
axes[1][0].title.set_text('With_Norm')

#with normalization and fft
axes[1][1].plot([i for i in range(1,257)], X_norm_fft[1999][0:256])
axes[1][1].title.set_text('With_NormAndFFT')
print("class", "TYPE-4")
fig, axes = plt.subplots(2, 2,figsize=(16,8))

#raw data
axes[0][0].plot([i for i in range(1,257)], X_train[3495][0:256])
axes[0][0].title.set_text('Raw_data')

#with fft
yf = fft(X_train[3495][0:256])
xf = fftfreq(256,1/256)
axes[0][1].plot(xf, np.abs(yf))
axes[0][1].title.set_text('With_FFT')

#after normalization
axes[1][0].plot([i for i in range(1,257)], X_norm[3495][0:256])
axes[1][0].title.set_text('With_Norm')

#with normalization and fft
axes[1][1].plot([i for i in range(1,257)], X_norm_fft[3495][0:256])
axes[1][1].title.set_text('With_NormAndFFT')
print("class", "TYPE-5")
fig, axes = plt.subplots(2, 2,figsize=(16,8))

#raw data
axes[0][0].plot([i for i in range(1,257)], X_train[4495][0:256])
axes[0][0].title.set_text('Raw_data')

#with fft
yf = fft(X_train[4495][0:256])
xf = fftfreq(256,1/256)
axes[0][1].plot(xf, np.abs(yf))
axes[0][1].title.set_text('With_FFT')

#after normalization
axes[1][0].plot([i for i in range(1,257)], X_norm[4495][0:256])
axes[1][0].title.set_text('With_Norm')

#with normalization and fft
axes[1][1].plot([i for i in range(1,257)], X_norm_fft[4495][0:256])
axes[1][1].title.set_text('With_NormAndFFT')
print("class", "TYPE-6")
fig, axes = plt.subplots(2, 2,figsize=(16,8))

#raw data
axes[0][0].plot([i for i in range(1,257)], X_train[5495][0:256])
axes[0][0].title.set_text('Raw_data')

#with fft
yf = fft(X_train[5495][0:256])
xf = fftfreq(256,1/256)
axes[0][1].plot(xf, np.abs(yf))
axes[0][1].title.set_text('With_FFT')

#after normalization
axes[1][0].plot([i for i in range(1,257)], X_norm[5495][0:256])
axes[1][0].title.set_text('With_Norm')

#with normalization and fft
axes[1][1].plot([i for i in range(1,257)], X_norm_fft[5495][0:256])
axes[1][1].title.set_text('With_NormAndFFT')