我在运行这部分代码时一直出错:
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'
你们有解决这个问题的方法吗?
非常感谢!
最佳答案
关于arrays - 数据转换警告: A column-vector y was passed when a 1d array was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42719863/