numpy - polynomial regression using python -


from understand polynomial regression specific type of regression analysis, more complicated linear regression. there python module can this? have looked in matplotlib ,scikitand numpy can find linear regression analysis.

and possible work out correlation coefficient of none linear line?

scikit supports linear , polynomial regression.

check generalized linear models page @ section polynomial regression: extending linear models basis functions.

example:

>>> sklearn.preprocessing import polynomialfeatures >>> import numpy np >>> x = np.arange(6).reshape(3, 2) >>> x array([[0, 1],        [2, 3],        [4, 5]]) >>> poly = polynomialfeatures(degree=2) >>> poly.fit_transform(x) array([[ 1,  0,  1,  0,  0,  1],        [ 1,  2,  3,  4,  6,  9],        [ 1,  4,  5, 16, 20, 25]]) 

the features of x have been transformed [x_1, x_2] [1, x_1, x_2, x_1^2, x_1 x_2, x_2^2], , can used within linear model.

this sort of preprocessing can streamlined pipeline tools. single object representing simple polynomial regression can created , used follows:

>>> sklearn.preprocessing import polynomialfeatures >>> sklearn.linear_model import linearregression >>> sklearn.pipeline import pipeline >>> model = pipeline([('poly', polynomialfeatures(degree=3)), ...                   ('linear', linearregression(fit_intercept=false))]) >>> # fit order-3 polynomial data >>> x = np.arange(5) >>> y = 3 - 2 * x + x ** 2 - x ** 3 >>> model = model.fit(x[:, np.newaxis], y) >>> model.named_steps['linear'].coef_ array([ 3., -2.,  1., -1.]) 

the linear model trained on polynomial features able recover input polynomial coefficients.

in cases it’s not necessary include higher powers of single feature, so-called interaction features multiply @ d distinct features. these can gotten polynomialfeatures setting interaction_only=true.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -