当我在 for 循环中迭代时,我不断收到相同的警告,我想抑制它。警告内容如下:
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 "
产生警告的代码如下:
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
我已经禁用了一个警告。我不想禁用所有警告,我只想禁用此警告。我正在使用 python 3.7 和 sklearn 版本 0.0
原文由 njalex22 发布,翻译遵循 CC BY-SA 4.0 许可协议
在脚本开头尝试此操作以忽略特定警告: