python - 如何解决 seaborn :RuntimeWarning: log10 中遇到的除以零?
问题描述
我正在尝试可视化一些特征的统计信息,我的一些特征的值为0,我正在使用seaborn histplot 的参数log_scale,log for base 10
因为我的特征值中存在0,所以我无法可视化绘图,所以应该我这样做不会对数据造成损害?
我的代码:
fig, axes = plt.subplots(ncols=2, nrows=len(METAFEATURES), figsize=(20,50),dpi=100)
for i, feature in enumerate(METAFEATURES):
sns.histplot(dfs['toxic'][feature], label='toxic', ax=axes[i][0], color=colors[0],log_scale=True)
sns.histplot(dfs['severe_toxic'][feature], label='severe_toxic',ax=axes[i][0], color=colors[1],log_scale=True)
sns.histplot(dfs['obscene'][feature], label='obscene', ax=axes[i][0], color=colors[2],log_scale=True)
sns.histplot(dfs['threat'][feature], label='threat', ax=axes[i][0], color=colors[3],log_scale=True)
sns.histplot(dfs['insult'][feature], label='insult', ax=axes[i][0], color=colors[4],log_scale=True)
sns.histplot(dfs['identity_hate'][feature], label='identity_hate', ax=axes[i][0], color=colors[5],log_scale=True)
sns.histplot(train_df[feature], label="Training", ax=axes[i][1],color=colors[0],log_scale=True)
sns.histplot(test_df[feature], label='Test', ax=axes[i][1],color=colors[1],log_scale=True)
for j in range(2):
axes[i][j].set_xlabel('')
axes[i][j].tick_params(axis='x', labelsize=12)
axes[i][j].tick_params(axis='y', labelsize=12)
axes[i][j].legend()
axes[i][0].set_title(f"{feature} Target Distribution in Training Set", fontsize=13)
axes[i][1].set_title(f"{feature} Training & Test Set Distribution", fontsize=13)
plt.show()
解决方案
推荐阅读
- python - 从用户 id discord.py 获取语音通道 id
- hive - Hive 3 中的 ALTER TABLE 问题
- javascript - 如何查看当前模拟的函数?
- flutter - 在 Flutter 中获取 List 元素
- c# - 无法获取要插入数组的值
- javascript - 如何使用JS将图像制作成具有透明背景的轮廓
- vue.js - 如何使用 Jest 在 Nuxt 应用程序中测试水平滚动?
- javascript - javascript quad 等于含义 ====
- c# - C# Selenium XPath,调用链接文本的点击函数
- javascript - 如何延迟 list.js 中的搜索?