473,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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, 270 views)
File Type: jpg Kernel SVM.jpg (48.4 KB, 223 views)
Attached Files
File Type: pdf SVM.pdf (178.4 KB, 142 views)
File Type: pdf Kernel SVM.pdf (938.6 KB, 155 views)
Apr 2 '19 #1
2 4993
dwblas
626 Expert 512MB
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
geraldwarp
1 Bit
In most cases, this error is triggered when Python sees a variable name (Global or Local) and doesn't know what it's for. These errors can happen if you forget to initialize a variable , if you misspell a variable, or if you misspell a reserved word such as "True". Before you use the global variable in your function for reading, it must be first initialized somewhere: either outside of the function or inside it.
Feb 17 '21 #3

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

Similar topics

5
by: NetKev | last post by:
I added a function 'warn_Admin' and defined it just before another function 'process_log'. 'process_log' calls this warn_Admin' function. However, when it gets called i get the following error...
2
by: jolly | last post by:
hey guys, When i try to run my code I get an error. NameError name 'main is not defined' if __name__ == "__main__": main() filename = "addbook.dat"
3
by: willkab6 | last post by:
I am very new to both programming and Pyhton and while trying to do some practice using A byte of python an Error pops up on the IDLE shell. I am using windows XP. PLease see below. while running:...
1
by: tshravan | last post by:
Hello All, I am newbie to python. I was trying to use a=zeros(5) in python shell, but it is throwing the following exception in the shell Traceback (most recent call last): File...
1
by: manojnkumar | last post by:
#This is to add, sub, mul and div using functions def menu(): print "" print "Welcome to the calculator" print "===== These are some of the options =====" print "1-->...
3
by: Mathieu Prevot | last post by:
Hi I import subprocess and use Popen, but PIPE is not defined. I used 2.5.1, 2.5.2, Python 2.6a3+ (trunk:63576, May 24 2008, 12:13:40), it's always the same. What am I missing ? Thanks...
3
by: cirfu | last post by:
im doing the python challenge and well, i solved this problem with ruby :) phrase = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb...
4
by: Harry | last post by:
Hi there. I am trying to download a file(sn.last) from a public FTP server with the following code: from ftplib import FTP ftp=FTP('tgftp.nws.noaa.gov') ftp.login()...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.