Skip to content Skip to sidebar Skip to footer

Python How To Filter Specific Warning?

How to filter the specific warning for specific module in python? MWE ERROR: cross_val_score(model, df_Xtrain,ytrain,cv=2,scoring='r2') /usr/local/lib/python3.6/dist-packages/skl

Solution 1:

You have to pass category as WarningClass not in String:

from scipy.linalg import LinAlgWarning

warnings.filterwarnings(action='ignore', category=LinAlgWarning, module='sklearn')

Solution 2:


More pythonic way to filter WARNING :


import logging
    
for name in logging.Logger.manager.loggerDict.keys():
    if ('LinAlgWarning'in name):
            logging.getLogger(name).setLevel(logging.CRITICAL)

#rest of the code starts here...

Post a Comment for "Python How To Filter Specific Warning?"