By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

How to correct the NameError: name 'xx' is not defined?

P: 7





May I know how to correct the NameError: name 'xx' is not defined ?







Expand|Select|Wrap|Line Numbers
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from sklearn import svm, datasets
  4. # import some data to play with
  5. iris = datasets.load_iris()
  6. X = iris.data[:,[2,3]]
  7. y = iris.target
  8.  
  9. def plotSVC(title):
  10. # create a mesh to plot in
  11.     x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
  12.     y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
  13.     h = (x_max / x_min)/100
  14.     xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
  15.              np.arange(y_min, y_max, h))
  16.     plt.subplot(1, 1, 1)
  17.     Z = svc.predict(np.c_[xx.ravel(), yy.ravel()])
  18.     Z = Z.reshape(xx.shape)
  19.  
  20. cs = [0.1, 1, 10, 100]
  21. for c in cs:
  22.     svc = svm.SVC(kernel='rbf', C=c).fit(X, y)
  23.     plotSVC('C=' + str(c))
  24. plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
  25. plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired)
  26. plt.xlabel('petal length')
  27. plt.ylabel('petal width')
  28. plt.xlim(xx.min(), xx.max())
  29. plt.show()
  30.  



The error message is as below - NameError: name 'xx' is not defined



Expand|Select|Wrap|Line Numbers
  1.  
  2. runfile('C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py', wdir='C:/Users/HSIPL/Desktop/New f/a i')
  3. C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py:13: RuntimeWarning: divide by zero encountered in double_scalars
  4.   h = (x_max / x_min)/100
  5. 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.
  6.   warnings.warn(message, mplDeprecation, stacklevel=1)
  7. Traceback (most recent call last):
  8.  
  9.   File "<ipython-input-2-9e53960ad79d>", line 1, in <module>
  10.     runfile('C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py', wdir='C:/Users/HSIPL/Desktop/New f/a i')
  11.  
  12.   File "C:\Users\HSIPL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
  13.     execfile(filename, namespace)
  14.  
  15.   File "C:\Users\HSIPL\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
  16.     exec(compile(f.read(), filename, 'exec'), namespace)
  17.  
  18.   File "C:/Users/HSIPL/Desktop/New f/a i/Homework 5 6 Solution draft.py", line 24, in <module>
  19.     plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
  20.  
  21. NameError: name 'xx' is not defined
  22.  
  23.  






Please see the attached files -




Please help me so that I can improve my computing skills








Attached Images
File Type: jpg SVM.jpg (59.1 KB, 19 views)
File Type: jpg Kernel SVM.jpg (48.4 KB, 18 views)
Attached Files
File Type: pdf SVM.pdf (178.4 KB, 23 views)
File Type: pdf Kernel SVM.pdf (938.6 KB, 25 views)
Apr 2 '19 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
We have to be able to locate the line the error is on among other things. Post the complete error message with trackback.
Please see the attached files
No one is going to open an unknown file on a public website.
Apr 2 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.