2013-03-20 60 views
2

我試圖用scikit學會做線性迴歸與幾個輸出Scikit學習線性迴歸與幾個輸出

碼(隨機數據爲例):

from sklearn import datasets, linear_model 
import numpy as np 

X = np.random.rand(300,10) 
y = np.random.rand(300,9) 
reg_model = linear_model.LinearRegression() 
reg_model.fit(X,y) 

我得到collowing錯誤:

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
/Users/sorensonderby/Documents/workspaces/workspace/Chemoinformatics_proect/notebooks/<ipython-input-116-e235c7159573> in <module>() 
     5 y = np.random.rand(300,9) 
     6 reg_model = linear_model.LinearRegression() 
----> 7 reg_model.fit(X,y) 
     8 

/Library/Python/2.7/site-packages/scikit_learn-0.10-py2.7-macosx-10.7-intel.egg/sklearn/linear_model/base.pyc in fit(self, X, y) 
    178      linalg.lstsq(X, y) 
    179 
--> 180   self._set_intercept(X_mean, y_mean, X_std) 
    181   return self 
    182 

/Library/Python/2.7/site-packages/scikit_learn-0.10-py2.7-macosx-10.7-intel.egg/sklearn/linear_model/base.pyc in _set_intercept(self, X_mean, y_mean, X_std) 
    106   """ 
    107   if self.fit_intercept: 
--> 108    self.coef_ = self.coef_/X_std 
    109    self.intercept_ = y_mean - np.dot(X_mean, self.coef_.T) 
    110   else: 

ValueError: operands could not be broadcast together with shapes (10,9) (10) 

我讀的擬合方法的API,它說,X應該是n樣本X n_features和y應該是n樣本X n_targets。 Link to fit method

我在做什麼錯?

回答

1

您正在使用scikit-learn 0.10和0.13.1的文檔。升級你的安裝,然後再試一次 - 它應該工作。