我有一个以稀疏矩阵的scipy.sparse格式之一存储的数据矩阵,以及一堆我需要预测的结果。基本上,我想为每个结果拟合一个线性模型。由于数据集非常大(数万),因此我使用SGDRegressor进行此操作。现在,我有了我的特征矩阵:
In [62]: features
Out[62]:
<77946x72239 sparse matrix of type '<type 'numpy.float64'>'
with 1084093 stored elements in LInked List format>我的结果是
In [63]: outcomes
Out[63]:
<77946x24 sparse matrix of type '<type 'numpy.float64'>'
with 416487 stored elements in LInked List format>我的问题是:为了在第一个结果上训练线性模型,为什么我不能像下面这样做(参见错误)?那么正确的方法是什么呢?
In [64]: reg.fit(features, outcomes[:,0])
[...]
ValueError: Shapes of X and y do not match.发布于 2014-01-18 18:26:50
首先,y不应该是稀疏矩阵。其次,它的形状应该是(n_samples,)而不是(1, n_samples),所以
y = outcomes[:, 0].toarray().ravel()应该行得通。
https://stackoverflow.com/questions/21190362
复制相似问题