【发布时间】:2019-07-26 10:57:23
【问题描述】:
我正在尝试在下面的 sklearn 中执行逻辑回归:
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
mod_data2 = mod_data.copy()
classifier.fit(mod_data2[['prob1_norm', 'prob2_norm']].values.reshape(-1,2), mod_data2['Success'].values.reshape(-1,1))
但它给了我错误信息:
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(),但它告诉我尺寸错误。
谢谢
【问题讨论】:
-
你试过
mod_data2['Success'].values.ravel()吗? -
是的,我试过了,它告诉我 ValueError: Expected 2D array, got 1D array instead: array=[0.46062633 0.39853439 0.46062633 ... 0.21442516 0.06186648 0.02173996],而不是仅仅给我一个警告。如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 重塑您的数据,如果它包含单个样本,则使用 array.reshape(1, -1)。
标签: python-3.x pandas scikit-learn sklearn-pandas