<jupyter_start><jupyter_text>Visualise the data<jupyter_code>import os
import pathlib
import time
import itertools
from datetime import datetime

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

flist = ['private_dog2_correct']  # List dataset directory names. WormsTwoClass Lightning2 Earthquakes GunPoint 
# Input directory
if 'private' in flist[0]:
    fdir = '../../data/private_data/private_events_dev2' 
else:
    fdir = '../../data' 
sns.set(style="whitegrid")
def readucr(filename):
    data = np.loadtxt(filename)
    Y = data[:,0]
    X = data[:,1:]
    return X, Y

def read_data(filename):
    data = np.loadtxt(filename)
    return data<jupyter_output><empty_output><jupyter_text>Dataset size<jupyter_code>fname = flist[0]
train = pd.DataFrame(read_data(fdir+'/'+fname+'/'+fname+'_TRAIN.txt'))
test = pd.DataFrame(read_data(fdir+'/'+fname+'/'+fname+'_TEST.txt'))
train = train.rename(index=str, columns={0:'class'})
test = test.rename(index=str, columns={0:'class'})
classes = train['class'].unique()
classes = np.sort(classes)
print('Class labels are', classes)
n0_train = train[train['class'] == classes[0]]['class'].count()
n1_train = train[train['class'] == classes[1]]['class'].count()
n0_test = test[test['class'] == classes[0]]['class'].count()
n1_test = test[test['class'] == classes[1]]['class'].count()
print('Number of samples in each class:')
print('Train:', n0_train, ',', n1_train)
print('Test:', n0_test, ',', n1_test)<jupyter_output><empty_output><jupyter_text>Create data subsets on class 0 and 1<jupyter_code>train_0 = train[(train['class'] == classes[0])]
train_1 = train[(train['class'] == classes[1])]
test_0 = test[(test['class'] == classes[0])]
test_1 = test[(test['class'] == classes[1])]
fig = plt.figure()
ax = fig.add_subplot(111)
rand = int(np.random.rand()*min(n0_train, n1_train))
#n = x_train.shape[1]
plt.plot(train_0.iloc[rand][1:], label='class '+str(int((train_0.iloc[rand]['class']))))
plt.plot(train_1.iloc[rand][1:], label='class '+str(int(train_1.iloc[rand]['class'])))
plt.legend(loc='upper right', frameon=False)
plt.suptitle(fname)
ax.set_xlabel('time, t')
ax.set_ylabel('x(t)')<jupyter_output><empty_output><jupyter_text>Compare classes<jupyter_code>def plot_class_data(data, fname, n_plots=20):
    fig, ax = plt.subplots(n_plots, 2, sharex='col', sharey='row', figsize=(10, 10))
    rows = [0, 0]
    colors = [None, 'darkorange']
    for i in range(data.shape[0]):
        col = 0
        if data.iloc[i]['class']==1:
            col = 1
        row = rows[col]
        rows[col] = rows[col] + 1
        if row < n_plots:
            ax[row, col].plot(data.iloc[i][1:], color=colors[col])
            ax[0, col].set_title('Class '+str(int(data.iloc[i]['class'])))
            ax[row, col].set_ylim(bottom=0, top=2.2)
    ax[n_plots-1, 0].set_ylabel('x(t)')
    ax[n_plots-1, 0].set_xlabel('time, t')
    ax[n_plots-1, 1].set_xlabel('time, t')
    fig.suptitle(fname)
plot_class_data(train, fname, 20)
plot_class_data(test, fname, 20)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19171829149005543, 'fraction_numerical': 0.023475709162047602, 'mean_word_length': 5.325773195876288, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '404634', 'license': 'MIT', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1176, 'n_words': 213, 'path': 'notebooks/results/data_plots.ipynb', 'repo_name': 'Withington/deepscent', 'size': '3067'}