python-3.x - 如何解决模块'pandas'没有属性'scatter_matrix'属性错误
问题描述
这是我使用的代码,但即使在导入 scatter_matrix 之后它也会给我错误:
from matplotlib import cm
from pandas.plotting import scatter_matrix
X = fruits[['height', 'width', 'mass', 'color_score']]
y = fruits['fruit_label']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
cmap = cm.get_cmap('gnuplot')
scatter = pd.scatter_matrix(X_train, c= y_train, marker = 'o', s=40, hist_kwds={'bins':15}, figsize=(9,9), cmap=cmap)
解决方案
确保您的格式没问题,您可以尝试删除pd.scatter_matrix
并保留scatter_matrix
scatter = pd.scatter_matrix(X_train, c= y_train, marker = 'o', s=40, hist_kwds={'bins':15}, figsize=(9,9), cmap=cmap)
进入
scatter = scatter_matrix(X_train, c= y_train, marker = 'o', s=40, hist_kwds={'bins':15}, figsize=(9,9), cmap=cmap)
如果您使用 jupyter notebook,您可能还需要为您的笔记本添加 matplotlib 内联
%matplotlib notebook
from matplotlib import cm
from pandas.plotting import scatter_matrix
X = fruits[['height', 'width', 'mass', 'color_score']]
y = fruits['fruit_label']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
cmap = cm.get_cmap('gnuplot')
scatter = scatter_matrix(X_train, c= y_train, marker = 'o', s=40, hist_kwds={'bins':15}, figsize=(9,9), cmap=cmap)
推荐阅读
- python - 检查数组的数组元素是否存在于python中的另一个数组中
- pthreads - 无法在 Firefox 中运行简单的 Emscripten 线程示例
- windows - 本地 Kyma 重启问题
- javascript - 使用道具更改禁用属性时的无限循环。(VueJs)
- python - 我想在值错误的地方打印 Insufficient data 并继续 for 循环?如何做呢?
- c# - C# 构造函数如何为只读属性赋值?
- amazon-athena - pyathena 或 pyathenajdbc 无法使用 `schema_name` 连接其他目录没有得到尊重
- c# - 自定义格式异常 c# - 异常未处理,为什么?
- c# - 非主键属性的唯一约束
- swift - 带有可编码数组的 swift 5 抽象网络响应