TypeError: 不支持的操作数类型 -: ‘module’ 和 ‘LinearSegmentedColormap’

import matplotlib.pyplot as pltimport matplotlib as cmapfrom sklearn import datasetsfrom sklearn import svmdigits = datasets.load_digits()clf = svm.SVC(gamma=0.001, C=100)print(len(digits.data))x, y = digits.data[:-1], digits.target[:-1]clf.fit(x,y)print('Prediction:', clf.predict(digits.data[[-1]]))plt.imshow(digits.images[-1], cmap-plt.cm.gray_r, interpolation-"nearest")plt.show()

在Python 3.8.3中运行这段代码时,我得到了以下错误信息:

Traceback (most recent call last):  File "C:\Users\Aben\Downloads\pythonstuff\machinelearning.py", line 18, in <module>    plt.imshow(digits.images[-1], cmap-plt.cm.gray_r, interpolation-"nearest")TypeError: unsupported operand type(s) for -: 'module' and 'LinearSegmentedColormap'

有谁知道这是为什么吗?我顺便提一下,我正在使用这个教程


回答:

不知为何,您在向imshow()传递参数时使用了-而不是=。请按以下方式修复:

plt.imshow(digits.images[-1], cmap=plt.cm.gray_r, interpolation="nearest")

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注