简体   繁体   中英

Linear reliance in Linear Regression in Python

How to check linear reliance between dependent variable and independent variables? Because so as to make Linear Regression model in Python we have to use (as I suppose) only variables which are: 1. correlated with dependent variable 2. independent variables which are not correlated with other independent variables 3. independent variables with linear reliance with dependent variables ? Please give me the code which is able to chech linear reliance in Python

You can use pandas for that:

df = pd.DataFrame({'feature one': [1,2,3,5,2,3],
                   'feature two': [5,10,18,23,16,20],
                   'feature three': [-23,-4,1,29,2,112],
                   'result': [10,20,30,50,20,30]})


print(df)

print(df.corr())

You will see that feature one has the biggest correlation with result, then feature two and then feature three . You can also check out the correlation between each feature.

So, for your linear model I would chose first and second feature

If values are close to -1 or 1, that means that there is big correlation between features, if values are close to 0, that means that that there is no correlation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM