python implementation of multivariate linear regression, some refactoring