gpt4 book ai didi

arrays - 数据转换警告: A column-vector y was passed when a 1d array was expected

转载 作者:行者123 更新时间:2023-12-02 11:55:03 24 4
gpt4 key购买 nike

我在运行这部分代码时一直出错:

scores = cross_val_score(XGB_Clf, X_resampled, y_resampled, cv=kf)

错误是:

DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True)

我知道这个问题有很多答案,并且我需要使用 ravel(),但使用它不会改变任何东西!

此外,我传递给函数的数组“y”不是列向量 ...

参见:

y_resampled
Out[82]: array([0, 0, 0, ..., 1, 1, 1], dtype=int64)

当我运行时

y_resampled.ravel()

我明白

Out[81]: array([0, 0, 0, ..., 1, 1, 1], dtype=int64)

这与我的初始变量完全相同...

另外,当我运行 y_resampled.values.ravel() 时,我收到一条错误消息,告诉我这是一个 numpy 数组...

Traceback (most recent call last): 
File "<ipython-input-80-9d28d21eeab5>", line 1, in <module>
y_resampled.values.ravel()

AttributeError: 'numpy.ndarray' object has no attribute 'values'

你们有解决这个问题的方法吗?

非常感谢!

最佳答案

查看this answer伙计!

简单地说:

model = forest.fit(train_fold, train_y.values.ravel())

关于arrays - 数据转换警告: A column-vector y was passed when a 1d array was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42719863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com