为了划分训练测试数据:
X_train, X_test, y_train, y_test = train_test_split(X, y.iloc[:,1], test_size=0.3,random_state=seed, stratify=y)
但是当我跑步时,我看到此错误:(我写了x和y的大小)
Shape(X)= (284807, 28)
Shape(y)= (284807,)
Traceback (most recent call last):
, in <module>
X_train, X_test, y_train, y_test = train_test_split(X, y.iloc[:,1], test_size=0.3,random_state=seed, stratify=y)
AttributeError: 'numpy.ndarray' object has no attribute 'iloc'
如何解决此问题?
正如评论所建议,尝试将y.iloc[:,1]
替换为y[:,1]
:
X_train, X_test, y_train, y_test = train_test_split(X,
y[:,1],
test_size=0.3,
random_state=seed,
stratify=y)