user826407
user826407

Reputation: 151

Linear Regression in python with vectors

I have the data:

(ax1,ax2,ax2)(ay1,ay2,ay3)
(bx1,bx2,bx2)(by1,by2,by3)
(cx1,cx2,cx2)(cy1,cy2,cy3)
(cx1,cx2,cx2)(cy1,cy2,cy3)
....

I have groups of data and the corresponding values. I am looking at having a Linear Regression using Sickitlearn.

I am looking at the regression models and did not find anything for the vectors like this. am I missing anything? Can you please let me know we have any model where with the given input data , if we give

(zx1,zx2,zx3) we can predict (zy1m zy2zy3)

Upvotes: 0

Views: 2498

Answers (1)

gboffi
gboffi

Reputation: 25023

The relevant method in LinearRegression is .fit() that, as it is documented, accept as input two 2D arrays that share the number of rows/samples

In [26]: import sklearn as sk
In [27]: from numpy import array
In [28]: model = sk.linear_model.LinearRegression()
In [29]: a = array(range(30)).reshape(10,3) # 10 samples, 3 features
In [30]: b = a**1.25 -0.25*a + 12           # 10 samples, 3 targets
In [31]: model.fit(a, b)
Out[31]: LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)
In [32]: a[5], b[5], model.predict([a[5]])
Out[32]: 
(array([15, 16, 17]),
 array([ 37.76984507,  40.        ,  42.26923414]),
 array([[ 39.47550026,  41.57922876,  43.75287898]]))
In [33]: 

Upvotes: 3

Related Questions