Skip to content
Advertisement

How to do Linear Regression and get Standard Deviation (Python)

I have this very simple problem, but somehow I have not found a solution for it yet:

I have two curves, A1 = [1,2,3] A2 = [4,5,6]

I want to fit those curves to another curve B1 = [4,5,3] with Linear Regression so B1 = aA1 + bA2

This can easily be done with sklearn LinearRegression – but sklearn does not give you the standard deviation on your fitting parameters.

I tried using statsmodels… but somehow i cant get the format right

JavaScript

Error : ValueError: endog and exog matrices are different sizes

Advertisement

Answer

If your formula is B1 = aA1 + bA2, then the array b is your endogenous and the array a is your exogenous. You need to transpose your exogenous:

JavaScript

From sklearn:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement