《Python机器学习基础教程》1.7.3笔记

本文解决在使用Python进行机器学习时遇到的三个常见问题:pandas版本更新导致的scatter_matrix属性错误,matplotlib版本更新引起的DeprecationWarning警告,以及图形显示缺失。提供了详细的解决方案,包括代码修改和版本回退。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


成果展示:
在这里插入图片描述

第一个报错:AttributeError: module ‘pandas’ has no attribute ‘scatter_matrix’

报错内容:

AttributeError: module 'pandas' has no attribute 'scatter_matrix'

在这里插入图片描述
原因:pandas版本更改
需要在前面增加plotting.即

grr = pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15),
                       marker='o', hist_kwds={'bins': 20}, s=60,
                       alpha=.8, cmap=mglearn.cm3)

这个报错在源码中已经修改过来了
在这里插入图片描述

第二个报错:MatplotlibDeprecationWarning: The colNum attribute was deprecated in Matplotlib 3.2 and will be removed two minor relea

报错内容:

MatplotlibDeprecationWarning:  The colNum attribute was deprecated in Matplotlib 3.2 and will be removed two minor relea.....

原因:matlplotlib版本更改
方法:卸载最新版本,换成之前的版本,我换成了2.2.5
在这里插入图片描述

第三个问题:没有图形显示

在pycharm中换成旧版本仍然无法输出,但是也没有报错。
在这里插入图片描述

原因:如同matplotlib绘图一样需要进行展示,即plt.show()

方法:增加show()的命令

import matplotlib.pyplot as plt
grr = pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15),
                       marker='o', hist_kwds={'bins': 20}, s=60,
                       alpha=.8, cmap=mglearn.cm3)
plt.show()

展示成果
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值