Repository navigation
ENH stepwise regression - #4813
anishgoyal24 wants to merge 5 commits into
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4813 +/- ##
==========================================
- Coverage 81.14% 81.14% -0.01%
==========================================
Files 581 581
Lines 89895 89901 +6
Branches 10041 10041
==========================================
+ Hits 72944 72946 +2
- Misses 14673 14675 +2
- Partials 2278 2280 +2
Continue to review full report at Codecov.
|
| bestModel = r_sq_elimination(bestModel, y) | ||
| return bestModel | ||
| else: | ||
| return bestModel |
There was a problem hiding this comment.
In any case, bestModel needs to returned, could this be used without needing else check?
if foundNew == True:
bestModel = r_sq_elimination(bestModel, y)
return bestModel
| for i in range(0, noCols): | ||
| ols_regeressor = sm.OLS(exog=x, endog=y).fit() | ||
| pValues = ols_regeressor.pvalues | ||
| print(pValues) |
There was a problem hiding this comment.
Do you intend to print these values? If this was meant for debugging, you can remove them?
There was a problem hiding this comment.
Yes. Left them by mistake. Removed thanks!
| bestModel = pd.DataFrame(x) | ||
| foundNew = False | ||
| for i in range(1, noOfColumn): | ||
| temp = x.drop(x.columns[i], axis=1) |
There was a problem hiding this comment.
You could loop through column names like
for col in x.columns:
temp = x.drop(col, axis=1)
There was a problem hiding this comment.
Yes. I ran and realised that something was going wrong when I changed it. And secondly I do not want to work on the 0th column. So this is saving me resources.
There was a problem hiding this comment.
I see, which could be done with slicing btw.
for col in x.columns[1:]
| noCols = x.shape[1] | ||
| for i in range(0, noCols): | ||
| ols_regeressor = sm.OLS(exog=x, endog=y).fit() | ||
| pValues = ols_regeressor.pvalues |
There was a problem hiding this comment.
IIUIC, you're doing the ols_regeressor = sm.OLS(exog=x, endog=y).fit() same check, any reason for looping it noCols times?
There was a problem hiding this comment.
Yes. Actually I am dropping columns with pvalues > sl sequentially and not all at once.
|
LGTM pull request analysis was skipped for b44a141 by anishgoyal24. Analysis of future commits will happen as normal. Comment posted by LGTM.com |
| @@ -0,0 +1,46 @@ | |||
| import pandas as pd | |||
There was a problem hiding this comment.
filename is not good. Should be backward_elimination.py to conform to pep.
|
LGTM pull request analysis was skipped for 77b8373 by anishgoyal24. Analysis of future commits will happen as normal. Comment posted by LGTM.com |
|
This needs some design discussion/decision. The current module location is wrong, it is on the top level AFAICS. It needs to move "somewhere" depending on the models that can be used with it. |
This python file provides the functionality to optimise the dataset for Multiple Regression Models using Backward Elimination. Columns are first dropped using the adjusted R-Squared values and then to further optimise the data, p-values of the columns are also checked.
Pass the features(X) followed by the labels(y) and the significance level you want to consider into the backward_eliminaton function. It will return the optimised dataset.
NOTE: No need to pass the dataset with the constant column already added. It will automatically add the column.