1. 程式人生 > >DataConversionWarning: A column-vector y was passed when a 1d array was expected. 問題解決

DataConversionWarning: A column-vector y was passed when a 1d array was expected. 問題解決

在用SMOTE演算法模組進行過取樣(oversampling)時,pandas匯入訓練集合特徵和label。

from imblearn.over_sampling import SMOTE # 匯入SMOTE演算法模組
# 處理不平衡資料
sm = SMOTE(random_state=42)    # 處理過取樣的方法
X, y = sm.fit_sample(X, y)

出現:

/Users/wangchuang/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:547: 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)

通過查詢,解決方法如下,

from imblearn.over_sampling import SMOTE # 匯入SMOTE演算法模組
# 處理不平衡資料
sm = SMOTE(random_state=42)    # 處理過取樣的方法
X, y = sm.fit_sample(X, y.values.ravel())