简体   繁体   English

Python 1D CNN model - train_test_split 中的错误

[英]Python 1D CNN model - Error in train_test_split

I'm trying to build a 1D CNN model by processing ECG signals to diagnose sleep apnea.我正在尝试通过处理心电图信号来诊断睡眠呼吸暂停来构建一维 CNN model。

I am using the sklearn library and encountered an error in train_test_split .我正在使用 sklearn 库并在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.任何帮助将非常感激。

Probably sklearn understands your data as 1xN matrix and thinks of it as 1 sample with N features.可能 sklearn 将您的数据理解为 1xN 矩阵,并将其视为具有 N 个特征的 1 个样本。 So you need to transpose it and get Nx1.所以你需要转置它并得到Nx1。

That is a typical situation for sklearn functions, not only train_split, but fit-transform.这是 sklearn 函数的典型情况,不仅是 train_split,而且是 fit-transform。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM