<jupyter_start><jupyter_text>Plot PSD for dataset<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from scipy import signal
def plot_PSD(zero, one):
    psds_zero = []
    psds_one = []

    freqs = signal.welch(zero[0])[0]
    for zero_elem in zero:
        _, psd = signal.welch(zero_elem)
        psds_zero.append(psd)

    psds_zero = np.array(psds_zero).mean(axis=0)

    for one_elem in one:
        _, psd = signal.welch(one_elem)
        psds_one.append(psd)

    psds_one = np.array(psds_one).mean(axis=0)

    fig = plt.figure(figsize=(5, 4))
    ax = fig.add_subplot(1, 1, 1)
    plt.semilogx(freqs, psds_zero, label='<5 IEDs in next 10 seconds')
    plt.semilogx(freqs, psds_one, label='>=5 IEDs in next 10 seconds')
    plt.title('Average power spectral density')
    plt.xlabel('Frequency')
    plt.ylabel('Power')
    ax.set_yscale('log')
    # plt.xlim([0, 5e-2])
    plt.legend()
    plt.tight_layout()
X = np.load('Data/ref_L6_window_1_chans_12/X.npy')
y = np.load('Data/ref_L6_window_1_chans_12/y.npy')

y = 1 * (y > 0)
zero = X[y == 0]
one = X[y == 1]

print(zero.shape[0] / one.shape[0])
plot_PSD(zero, one)
X = np.load('Data/ref_L6_window_10s_chans_12/X.npy')
y = np.load('Data/ref_L6_window_10s_chans_12/y.npy')

y = 1 * (y > 4)
zero = X[y == 0]
one = X[y == 1]

print(zero.shape[0] / one.shape[0])
plot_PSD(zero, one)<jupyter_output>6.07037643207856
{'fraction_non_alphanumeric': 0.15766738660907129, 'fraction_numerical': 0.04535637149028078, 'mean_word_length': 3.5874587458745872, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '246557', 'license': 'MIT', 'n_tokens_mistral': 656, 'n_tokens_neox': 614, 'n_words': 110, 'path': 'old/PSD.ipynb', 'repo_name': 'norrisjamie23/forecasting-epileptic-discharges', 'size': '1389'}