【发布时间】:2020-12-06 12:09:51
【问题描述】:
让我们考虑数据:
import numpy as np
from sklearn.linear_model import LogisticRegression
x=np.linspace(0,2*np.pi,80)
x = x.reshape(-1,1)
y = np.sin(x)+np.random.normal(0,0.4,80)
y[y<1/2] = 0
y[y>1/2] = 1
clf=LogisticRegression(solver="saga", max_iter = 1000)
我想拟合逻辑回归,其中 y 是因变量,x 是自变量。但是当我使用时:
clf.fit(x,y)
我看到错误
'y should be a 1d array, got an array of shape (80, 80) instead'.
我试图通过使用来重塑数据
y=y.reshape(-1,1)
但我最终得到了长度为 6400 的数组! (怎么会?)
您能帮我执行此回归吗?
【问题讨论】:
-
80 乘以 80 是 6400
标签: python numpy scikit-learn