Python sm.logit() - getting LinAlgError: Singular matrix when using function



Hi Team,

I am trying to build and run a logistic regression model (with a very large dataset). After data cleaning, dummy creation and vif check when tried to run the model i am getting below error:

Build logistic regression model (using statsmodels package/library)

import statsmodels.api as sm
M1 = sm.Logit(Train_Y, Train_X) # (Dep_Var, Indep_Vars) # This is model definition
M1_Model = # This is model building

File “C:\Users\Gaurav Rai\Anaconda3\lib\site-packages\numpy\linalg\”, line 528, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)

File “C:\Users\Gaurav Rai\Anaconda3\lib\site-packages\numpy\linalg\”, line 89, in _raise_linalgerror_singular
raise LinAlgError(“Singular matrix”)

LinAlgError: Singular matrix

Complete code is attached. Along with below links to datasets:

Initial Dataset:

Code Attachment: (3.3 KB)

Kindly help me in resolving this issue.

Thanks & Regards,
Gaurav Rai


Since it did not allow me to provide link to dataset after vif step in my code so putting it here:

Thanks & Regards,
Gaurav Rai