0

I'm trying to build a 1D CNN model by processing ECG signals to diagnose sleep apnea.

I am using the sklearn library and encountered an error in train_test_split. Here is my code:

# loading the file
with open("ApneaData.csv") as csvDataFile:
    csvReader = csv.reader(csvDataFile)
    for line in csvReader:
        lis.append(line[0].split())  # create a list of lists

# making a list of all x-variables
for i in range(1, len(lis)):
    data.append(list(map(int, lis[i])))

# a list of all y-variables (either 0 or 1)
target = Extract(data)  # sleep apn or not

# converting to numpy arrays
data = np.array(data)
target = np.array(target)

# stacking data into 3D
loaded = dstack(data)
change = dstack(target)


trainX, testX, trainy, testy = train_test_split(loaded, change, test_size=0.3)

I get the error:

With n_samples=1, test_size=0.3 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters.

I do not understand what I am doing wrong? Any help would be much appreciated.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Please do **not** change the question *after* an answer has been provided; it makes the answer seem irrelevant. If you have follow-up issues, please open a new question (rolled back the question to its previous form). – desertnaut May 08 '20 at 11:46

1 Answers1

1

Probably sklearn understands your data as 1xN matrix and thinks of it as 1 sample with N features. So you need to transpose it and get Nx1.

That is a typical situation for sklearn functions, not only train_split, but fit-transform.

Alexander Chervov
  • 616
  • 3
  • 7
  • 23