image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

train = pd.read_csv('/kaggle/input/data-without-drift/train_clean.csv')
test = pd.read_csv('/kaggle/input/data-without-drift/test_clean.csv')

batch_indices = [slice(500000 * i, 500000 * (i + 1)) for i in range(10)]

fig, axes = plt.subplots(2,5,sharex=False,sharey=True, figsize=(25,10))
for i,ax in enumerate(axes.ravel()):
    train.iloc[batch_indices[i]].plot(kind='line',x='time',y=['signal'],ax=ax,linewidth=.1)
    ax.set_title('Batch_'+str(i))
ax.set_ylim(-5,14)
ax.legend()
fig.suptitle('Training Data',y=1.05)

plt.tight_layout()

fig, axes = plt.subplots(1,4,sharex=False,sharey=True, figsize=(25,10))
for i,ax in enumerate(axes.ravel()):
    test.iloc[batch_indices[i]].plot(kind='line',x='time',y=['signal'],ax=ax,linewidth=.1)
    ax.set_title('Batch_'+str(i))
ax.set_ylim(-5,11)
ax.legend()
fig.suptitle('Testing Data',y=1.05)

plt.tight_layout()

fig, axes = plt.subplots(2,5,sharex=True,sharey=True, figsize=(20,8))
for i,ax in enumerate(axes.ravel()):
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 0')['signal'],ax=ax,label='0')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 1')['signal'],ax=ax,label='1')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 2')['signal'],ax=ax,label='2')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 3')['signal'],ax=ax,label='3')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 4')['signal'],ax=ax,label='4')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 5')['signal'],ax=ax,label='5')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 6')['signal'],ax=ax,label='6')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 7')['signal'],ax=ax,label='7')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 8')['signal'],ax=ax,label='8')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 9')['signal'],ax=ax,label='9')
        sns.distplot(train.iloc[batch_indices[i]].query('open_channels == 10')['signal'],ax=ax,label='10')
        ax.set_title('Batch_'+str(i))
ax.legend()
fig.suptitle('Training Data',y=1.05)

ax.set_ylim(0,2)
plt.tight_layout()

train_seg_boundaries = np.concatenate([[0, 500000, 600000], np.arange(1000000, 5000000 + 1, 500000)])
train_signal = np.split(np.zeros(5000000), train_seg_boundaries[1:-1])
test_seg_boundaries = np.concatenate([np.arange(0, 1000000 + 1, 100000), [1500000, 2000000]])
test_signal = np.split(np.zeros(2000000), test_seg_boundaries[1:-1])

test['signal_type'] = np.concatenate([test_signal[0] + 1, test_signal[1] + 3, test_signal[2] + 4, test_signal[3] + 1, test_signal[4] + 2, test_signal[5] + 5, test_signal[6] + 4, test_signal[7] + 5, test_signal[8] + 1, test_signal[9] + 3, test_signal[10] + 1, test_signal[11] + 1])
test['signal'].plot(kind='line', linewidth=0.2, label='Test Signal')
test['signal_type'].plot(kind='line', label='Signal Type')
plt.legend()
del test_signal