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
Asked
Active
Viewed 107 times
-1
-
Your question is not very clear, but if you use Pandas you can try function corr() to check correlations between all valiables in dataset: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corr.html – CrazyElf Dec 27 '19 at 10:13
-
You can also check this topic: https://stackoverflow.com/questions/29432629/plot-correlation-matrix-using-pandas – CrazyElf Dec 27 '19 at 10:15
1 Answers
0
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.
taga
- 3,537
- 13
- 53
- 119
-
taga, so as I mean if values are close to 0 the is NOT a linear reliance between independent variables and dependent variable? – dingaro Dec 27 '19 at 10:39
-
If values in correlation result are close to 0 , that means that there is no correlation (use classification algorithms). – taga Dec 27 '19 at 10:40
-
-