text_plain_output_1.png
from os import listdir

from os.path import isfile, join

import numpy as np

import scipy.io as sio

number_of_classes = 4
def change(x):
    answer = np.zeros(np.shape(x)[0])
    for i in range(np.shape(x)[0]):
        max_value = max(x[i, :])
        max_index = list(x[i, :]).index(max_value)
        answer[i] = max_index
    return answer.astype(int)

mypath = '../input/mitbihecgtraining2017/training2017/'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f)) and f[0] == 'A']
bats = [f for f in onlyfiles if f[7] == 'm']
mats = [f for f in bats if np.shape(sio.loadmat(mypath + f)['val'])[1] >= 9000]
check = np.shape(sio.loadmat(mypath + mats[0])['val'])[1]
check = 9000
X = np.zeros((len(mats), check))
print(len(mats), check, X.shape)
for i in range(len(mats)):
    X[i, :] = sio.loadmat(mypath + mats[i])['val'][0, :9000]