Apr-03-2019, 01:54 PM
May I know how to correct the NameError: name 'xx' is not defined ?
Please help me so that I can improve my computing skills
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()Please see the attached files -
Please help me so that I can improve my computing skills