我已经搜索过 S/O,但我找不到这个问题的答案。
当我尝试使用 seaborn 绘制分布图时,我收到了未来警告。我想知道这里可能是什么问题。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
% matplotlib inline
from sklearn import datasets
iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['class'] = iris.target
df['species'] = df['class'].map({idx:s for idx, s in enumerate(iris.target_names)})
fig, ((ax1,ax2),(ax3,ax4))= plt.subplots(2,2, figsize =(13,9))
sns.distplot(a = df.iloc[:,0], ax=ax1)
sns.distplot(a = df.iloc[:,1], ax=ax2)
sns.distplot(a = df.iloc[:,2], ax=ax3)
sns.distplot(a = df.iloc[:,3], ax=ax4)
plt.show()
这是警告:
C:\ProgramData\Anaconda3\lib\site-packages\scipy\stats\stats.py:1713:
FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated;
use `arr[tuple(seq)]` instead of `arr[seq]`.
In the future this will be interpreted as an array index, `arr[np.array(seq)]`,
which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
有什么帮助吗?你可以运行上面的代码。你会收到警告。
Pandas : 0.23.4
, seaborn : 0.9.0
, matplotlib : 2.2.3
, scipy : 1.1.0
, numpy: 1.15.0'
原文由 user_6396 发布,翻译遵循 CC BY-SA 4.0 许可协议
更完整的回溯会很好。我的猜测是
seaborn.distplot
正在使用scipy.stats
来计算一些东西。错误发生在所以在最后一行中,列表
indexer
用于切片sorted
。使用切片列表是可行的,但计划是在未来贬值。涉及多个维度的索引应该是元组。在上下文中使用列表是一种正在逐步淘汰的旧样式。
所以
scipy
开发人员需要解决这个问题。这不是最终用户应该处理的事情。但是现在,不用担心futurewarning
。它不影响计算或绘图。有一种方法可以抑制未来的警告,但我不知道。FutureWarning:不推荐使用非元组序列进行多维索引使用 `arr[tuple(seq)]` 而不是 `arr[seq]`