That works when there is only 1 feature / indepedent-variable / x-value
for each case, but not when there are many (ie. for multivariate
regression).
Since there are many independent variables my variables look like this:
|x= [[1,2,3,4,5], [2,2,4,4,5], [2,2,4,4,1]]
y= [1,2,3,4,5]
|
For example, this code:
reg = linear_model.Ridge()
x = [[t.x1,t.x2,t.x3,t.x4,t.x5] for t in trainingTexts]
y = [t.human_rating for t in trainingTexts]
degree = 1
reg.fit(numpy.vander(x, degree + 1),y)
Returns this error:
Traceback (most recent call last):
File "22.07.py", line 795, in <module>
trainingSet = TrainingSet(humanRatedText)
File "22.07.py", line 393, in __init__
reg.fit(numpy.vander(x, degree + 1),y)
File "C:\Python27\lib\site-packages\numpy\lib\twodim_base.py", line
518, in va
nder
X[:,i] = x**(N - i - 1)
ValueError: operands could not be broadcast together with shapes (35) (35,8)
So, how do you do multivariate regression with higher degree polynomials?
Thanks,
Zach
On 07/08/2012 20:23, Mathieu Blondel wrote:
The following example explains how to do it using the numpy.vander
function:
http://scikit-learn.org/stable/auto_examples/linear_model/plot_polynomial_interpolation.html
Mathieu
On Wed, Aug 8, 2012 at 11:27 AM, Zach Bastick <[email protected]
<mailto:[email protected]>> wrote:
How can you increase the degree of the polynomial for multivariate
LinearRegression?
Numpy.polyfit has a "deg" parameter, allowing you to choose the degree
of the fitting polynomial, but doesn't work with multivariate data:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html
For example, a 2nd degree polynomial fit would have the following
regression equation:
y = intercept + (b*x1 +b* x1^2) + (b*x2 + b*x2^2) + (b*x3 + b*x3^2)
The following only does 1st degree polynomial fit:
clf = linear_model.LinearRegression()
clf.fit(x,y)
regress_coefs = clf.coef_
regress_intercept = clf.intercept_
So how can you do higher degree polynomial fits? This should allow
me to
getting a better fitting curve to get a prediction/regression formula
for my machine learning project.
Thanks,
Zach
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond.
Discussions
will include endpoint security, mobile security and the latest in
malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general