Python TypeError:';的操作数类型不受支持;模块';和';LinearSegmentedColormap';
在python 3.8.3中运行此代码时,我收到以下错误消息:Python TypeError:';的操作数类型不受支持;模块';和';LinearSegmentedColormap';,python,matplotlib,machine-learning,svm,Python,Matplotlib,Machine Learning,Svm,在python 3.8.3中运行此代码时,我收到以下错误消息: 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 = digit
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()
回溯(最近一次呼叫最后一次):
文件“C:\Users\Aben\Downloads\pythonstuff\machinelearning.py”,第18行,在
plt.imshow(数字图像[-1],cmap-plt.cm.gray\u r,插值-“最近”)
TypeError:-:“module”和“LinearSegmentedColormap”的操作数类型不受支持
有人知道为什么吗?
顺便说一句,我使用教程是因为在将参数传递给
imshow()
时,您使用了-
而不是=
。像这样修理它:
plt.imshow(数字图像[-1],cmap=plt.cm.gray\u r,插值=“最近”)
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'