我在运行这部分代码时一直出错:
scores = cross_val_score(XGB_Clf, X_resampled, y_resampled, cv=kf)
Run Code Online (Sandbox Code Playgroud)
错误是:
DataConversionWarning:当需要一维数组时,传递了列向量 y。请将 y 的形状更改为 (n_samples, ),例如使用 ravel()。y = column_or_1d(y, warn=True)
我知道这个问题有很多答案,我需要使用ravel()
,但使用它不会改变任何东西!
另外,我传递给函数的数组“y”不是列向量......
看:
y_resampled
Out[82]: array([0, 0, 0, ..., 1, 1, 1], dtype=int64)
Run Code Online (Sandbox Code Playgroud)
当我跑步时
y_resampled.ravel()
Run Code Online (Sandbox Code Playgroud)
我明白了
Out[81]: array([0, 0, 0, ..., 1, 1, 1], dtype=int64)
Run Code Online (Sandbox Code Playgroud)
这与我的初始变量完全相同......
另外,当我运行时y_resampled.values.ravel()
,我收到一个错误,告诉我这是一个 numpy 数组......
Traceback (most recent call last):
File "<ipython-input-80-9d28d21eeab5>", line 1, in <module>
y_resampled.values.ravel()
Run Code Online (Sandbox Code Playgroud)
AttributeError:“numpy.ndarray”对象没有属性“值”
你们中有人有办法解决这个问题吗?
多谢!