I am doing multidimensional linear regression in Python ( sklearn ), but for some reason the coefficients are not true as a list. Instead, an IN A LIST list is returned:
from sklearn import linear_model clf = linear_model.LinearRegression()
This returns the values ββin list [[]] instead of list []. Any idea why this is happening? Exit:
coef array [[ 1.03428648e-03 9.54477167e-04 1.45135995e-07 0.00000000e+00 0.00000000e+00 0.00000000e+00]] length 1 getting value 0: [ 1.03428648e-03 9.54477167e-04 1.45135995e-07 0.0000000 0e+00 0.00000000e+00 0.00000000e+00] getting value 1: Traceback (most recent call last): File "regress.py", line 8, in <module> print 'getting value 1:', clf.coef_[1] IndexError: index out of bounds
But it works:
from sklearn import linear_model clf = linear_model.LinearRegression() clf.fit ([[0, 0, 0], [1, 1, 1], [2, 2, 2]], [0, 1, 2])
Output:
coef array [ 0.33333333 0.33333333 0.33333333] length 3 getting value 0: 0.333333333333 getting value 1: 0.333333333333
python list regression
Zach Jul 18 '12 at 20:12 2012-07-18 20:12
source share