How to check in easy way non-linear relationships using Python?

Viewed 1240

I have dataset in pandas DataFrame. I build a function which returns me a dataframe which looks like this:

Feature_name_1   Feature_name_2   corr_coef   p-value
ABC              DCA              0.867327    0.02122 

So it's taking independent variables and returns correlation coefficient of them. Is there is any easy way I can check in this way non-linear relationship? In above case I used scipy Pearson correlation but I cannot find how to check non-linear? I found only more sophisticated methods and I would like have something easy to implement as above.

It will be enough if method will be easy to implement it's not necessary have to be from scipy on other specific packages

1 Answers

Regress your dependent variables on your independent variables and examine the residuals. If your residuals show a pattern there is likely a nonlinear relationship.

It may also be the case that your model is missing a cross term or could benefit from a transformation or something along those lines. I might be wrong but I'm not aware of a cut and dry test for non linearity.

Quick google search returned this which seems like it might be useful for you.

https://stattrek.com/regression/residual-analysis.aspx

Edit: Per the comment below, this is very general method that helps verify the linear regression assumptions.

Related