【问题标题】:How to fit SGDRegressor with two numpy arrays?如何用两个 numpy 数组拟合 SGDRegressor?
【发布时间】:2015-10-03 07:23:29
【问题描述】:

我正在努力学习SGDRegressor。我生成自己的数据,但我不知道如何将其融入算法。我收到此错误。

x = np.random.randint(100, size=1000)
y = x * 0.10
clf = linear_model.SGDRegressor()
clf.fit(x, y, coef_init=0, intercept_init=0)

找到样本数不一致的数组:[1 1000]

我是 python 和机器学习的新手。我错过了什么?

【问题讨论】:

  • x 的形状不正确。试试x = x.reshape(1000,)
  • 您能否将其添加到答案中以便我接受?

标签: python arrays numpy scikit-learn linear-regression


【解决方案1】:
>>> np.random.randint(100, size=1000)

会给你一个 1 x 1000 的数组。 您的特征和目标变量需要在一个列中。试试

>>> x = x.reshape(1000,)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多