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

logistic_regression
python

#1

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 = M1.fit() # This is model building

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

File “C:\Users\Gaurav Rai\Anaconda3\lib\site-packages\numpy\linalg\linalg.py”, 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: https://drive.google.com/drive/folders/1aclWn4EVlk8LYQxBfNDbDM697GeaddkK?usp=sharing

Code Attachment:
final_project1.zip (3.3 KB)

Kindly help me in resolving this issue.

Thanks & Regards,
Gaurav Rai


#2

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

https://drive.google.com/drive/u/1/folders/18HmABBUvNB9vqNHzSoRZ0SiusjLjehg-

Thanks & Regards,
Gaurav Rai