Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress a python warning

While I iterate within a for loop I continually receive the same warning, which I want to suppress. The warning reads:

C:\Users\Nick Alexander\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\preprocessing\data.py:193: UserWarning: Numerical issues were encountered when scaling the data and might not be solved. The standard deviation of the data is probably very close to 0. warnings.warn("Numerical issues were encountered "

The code that is producing the warning is as follows:

def monthly_standardize(cols, df_train, df_train_grouped, df_val, df_val_grouped, df_test, df_test_grouped):
    # Disable the SettingWithCopyWarning warning
    pd.options.mode.chained_assignment = None
    for c in cols:
        df_train[c] = df_train_grouped[c].transform(lambda x: scale(x.astype(float)))
        df_val[c] = df_val_grouped[c].transform(lambda x: scale(x.astype(float)))
        df_test[c] = df_test_grouped[c].transform(lambda x: scale(x.astype(float)))
    return df_train, df_val, df_test

I am already disabling one warning. I don't want to disable all warnings, I just want to disable this warning. I am using python 3.7 and sklearn version 0.0

like image 840
njalex22 Avatar asked Feb 19 '19 14:02

njalex22


People also ask

How do you suppress warnings?

Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code. 1. @SuppressWarnings("unchecked") public class Calculator { } - Here, it will ignore all unchecked warnings coming from that class.

How do you suppress a Tensorflow warning in Python?

Implementation for suppression of deprecation in Tensorflow:- where:- 0 = all messages are logged. 1= INFO logs are removed. 2 = INFO with WARNINGS is removed.


1 Answers

Try this at the beginning of the script to ignore specific warnings:

import warnings
warnings.filterwarnings("ignore", message="Numerical issues were encountered ")
like image 172
DirtyBit Avatar answered Sep 20 '22 21:09

DirtyBit