Share the joy
Suppose we have a 2-degree polynomial functionÂ
And let’s generate some training data sets. First, let’s have some random (x1, x2) sets:
Then, we transform it to (1, x1, x2, x1x2, x1^2, x2^2) form:
For , we know the coefficients is [2, 1, -3, 2, -5, 6]. Then we will have training result:
Let’s make it a little randomly, and we have training result set:
So now our training set is:
Now, we can solve Xtrans, y as how we solve multivariate linear regression:
regr = linear_model.LinearRegression() regr.fit(X_trans, y) print regr.coef_ # slope print regr.intercept_ # intercept
And we got the result, it is very similar to the coefficient we set [2, 1, -3, 2, -5, 6]
Check my code on github.
Pingback: Logistic Regression by Scikit | allenlipeng47()