0

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)

1 Answer 1

3

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]: 
2
  • Thanks Gboffi but I see a lot of delta between actual and expected. is there a way to reduce that
    – user826407
    Dec 4, 2017 at 2:39
  • @user826407 You have a linear model while, otoh, you possibly have a b=f(a) non linear dependency between the features and the targets. A linear model X does its best (it minimizes |b-X@a|²) but cannot predict exactly the targets values... That said, if you have outliers in your data set, removing them could improve the fit, but there is no guarantee.
    – gboffi
    Dec 4, 2017 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.