如何更正NameError:名称"xx"未定义?
我可以知道如何更正NameError:没有定义名称'xx'吗?
选择 | 换行 | 行号
- import numpy as np
- import matplotlib.pyplot as plt
- from sklearn import svm, datasets
- # import some data to play with
- iris = datasets.load_iris()
- X = iris.data[:,[2,3]]
- y = iris.target
- def plotSVC(title):
- # create a mesh to plot in
- x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
- y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
- h = (x_max / x_min)/100
- xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
- np.arange(y_min, y_max, h))
- plt.subplot(1, 1, 1)
- Z = svc.predict(np.c_[xx.ravel(), yy.ravel()])
- Z = Z.reshape(xx.shape)
- cs = [0.1, 1, 10, 100]
- for c in cs:
- svc = svm.SVC(kernel='rbf', C=c).fit(X, y)
- plotSVC('C=' + str(c))
- plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
- plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired)
- plt.xlabel('petal length')
- plt.ylabel('petal width')
- plt.xlim(xx.min(), xx.max())
- plt.show()
错误消息如下-NameError:未定义名称'xx'
选择 | 换行 | 行号
- runfile('C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py', wdir='C:/Users/HSIPL/Desktop/New f/a i')
- C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py:13: RuntimeWarning: divide by zero encountered in double_scalars
- h = (x_max / x_min)/100
- C:\Users\HSIPL\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
- warnings.warn(message, mplDeprecation, stacklevel=1)
- Traceback (most recent call last):
- File "<ipython-input-2-9e53960ad79d>", line 1, in <module>
- runfile('C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py', wdir='C:/Users/HSIPL/Desktop/New f/a i')
- File "C:\Users\HSIPL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
- execfile(filename, namespace)
- File "C:\Users\HSIPL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
- exec(compile(f.read(), filename, 'exec'), namespace)
- File "C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py", line 24, in <module>
- plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
- NameError: name 'xx' is not defined
请参阅所附文件-
请帮帮我,这样我才能提高我的计算能力
附加图像
SVM.jpg
(59.1KB,236次浏览)
内核SVM.jpg
(48.4KB,188次浏览)
附加的文件
SVM.pdf
(178.4 KB,89次浏览)
内核SVM.pdf
(938.6 KB,92次浏览)