【发布时间】:2016-06-19 03:13:05
【问题描述】:
我经常有两个numpy 1d 数组,x 和 y,并想使用它们执行一些快速的 sklearn 拟合 + 预测。
import numpy as np
from sklearn import linear_model
# This is an example for the 1d aspect - it's obtained from something else.
x = np.array([1, 3, 2, ...])
y = np.array([12, 32, 4, ...])
现在我想做一些类似的事情
linear_model.LinearRegression().fit(x, y)...
问题在于它expects an X which is a 2d column array。因此,我通常会喂它
x.reshape((len(x), 1))
我觉得很麻烦且难以阅读。
是否有一些更短的方法可以将一维数组转换为二维列数组(或者,让sklearn 接受一维数组)?
【问题讨论】:
标签: python numpy scikit-learn