[英]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.
我正在使用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)
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 LinearRegression
的相关方法是.fit()
, 如所记录的那样 ,该方法接受共享行数/样本数的两个2D数组作为输入。
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]:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.