【问题标题】:TypeError: unsupported operand type(s) for -: 'module' and 'LinearSegmentedColormap'TypeError: 不支持的操作数类型 -: 'module' 和 'LinearSegmentedColormap'
【发布时间】:2020-05-22 15:33:02
【问题描述】:
import matplotlib.pyplot as plt
import matplotlib as cmap

from sklearn import datasets
from sklearn import svm

digits = 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'

有人知道为什么吗? 我正在使用this 教程顺便说一句

【问题讨论】:

    标签: python matplotlib machine-learning svm


    【解决方案1】:

    由于某种原因,在将参数传递给 imshow() 时,您使用的是 - 而不是 =。像这样修复它:

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

    【讨论】:

      猜你喜欢
      • 2022-06-11
      • 2022-07-24
      • 1970-01-01
      • 2020-02-29
      • 2011-03-08
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多