numpy - Multiple linear regression python -


i use multiple linear regression, have 1 dependant variable (var) , several independant variables (varm1, varm2,...) use code in python:

z=array([varm1, varm2, varm3],int32) n=max(shape(var)) x = vstack([np.ones(n), z]).t = np.linalg.lstsq(x, var)[0] 

how can calculate r-square change every variable python ? see how regression changes if add or remove predictor variables.

if broadcasting correct along way following should give correlation coefficient r:

r = np.sqrt( ((var - x.dot(a))**2).sum() ) 

one full example of multi-variate regression:

import numpy np  x1 = np.array([1,2,3,4,5,6]) x2 = np.array([1,1.5,2,2.5,3.5,6]) x3 = np.array([6,5,4,3,2,1]) y = np.random.random(6)  nvar = 3 1 = np.ones(x1.shape) = np.vstack((x1,one,x2,one,x3,one)).t.reshape(nvar,x1.shape[0],2)  i,ai in enumerate(a):     = np.linalg.lstsq(ai,y)[0]     r = np.sqrt( ((y - ai.dot(a))**2).sum() )     print r 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -