numpy.ndarray'对象没有属性'iloc

问题描述 投票:-1回答:1

为了划分训练测试数据:

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'

如何解决此问题?

python arrays testing shapes training-data
1个回答
0
投票

正如评论所建议,尝试将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)

© www.soinside.com 2019 - 2024. All rights reserved.