473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NameError: global name 'numbers_t' is not defined

1 New Member
Can you help me with the NameError?
Expand|Select|Wrap|Line Numbers
  1. def addExample(self, klass, words):
  2.     """
  3.      * TODO
  4.      * Train your model on an example document with label klass ('pos' or 'neg') and
  5.      * words, a list of strings.
  6.      * You should store whatever data structures you use for your classifier 
  7.      * in the NaiveBayes class.
  8.      * Returns nothing
  9.     """
  10.     #numbers_t = (0,)*3
  11.     #numbers_t_sum = (0,)*3
  12.     self.count_docs += 1
  13.     for word in words:
  14.        if word not in self.vocab:
  15.             self.vocab.append(word)
  16.  
  17.     if klass == 'pos':
  18.         self.num_pos += 1
  19.         self.docs_pos.append(words)    
  20.     if klass == 'neg':
  21.         self.num_neg += 1
  22.         self.docs_neg.append(words)
  23.  
  24.     for t in self.vocab:
  25.         self.condprob_pos = math.log(numbers_t(self.vocab, self.docs_pos) + 1) - math.log(self.numbers_t_sum(self.vocab, self.docs_pos) + len(self.vocab))
  26.  
  27.     for t in self.vocab:
  28.         self.condprob_neg = math.log(numbers_t(self.vocab, self.docs_neg) + 1) - math.log(self.numbers_t_sum(self.vocab, self.docs_neg) + len(self.vocab))
  29.  
  30.     pass
  31.  
  32.   def numbers_t(self, a, b):
  33.     for t in a:
  34.         for word in b:
  35.             if t == b:
  36.                 result += 1  
  37.     return result
  38.  
  39.   def numbers_t_sum(self, a, b):
  40.     for t in a:
  41.         for word in b:
  42.             if t == b:
  43.                 result += 1
  44.     sum += result
  45.     return sum
  46.  
  47.  
Apr 4 '12 #1
1 2994
dwblas
626 Recognized Expert Contributor
You did not post the complete error message so there is no way to tell. Perhaps you commented that line
#numbers_t = (0,)*3 ??
Apr 18 '12 #2

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

Similar topics

5
6693
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 every time: --- Traceback (most recent call last): File "/usr/bin/denyhosts.py", line 202, in ? first_time, noemail, daemon) File...
2
5847
by: a | last post by:
def fn(): for i in range(l) global count count= .... how do i declare count to be global if it is an array subsequently i should access or define count as an array error:
8
10529
by: Evan | last post by:
Hi I have a short script that makes 2 calls to methods in another script as follows: import canPlaces as canp callOne=canp.addMe(3,5) callTwo=canp.estocStn()
3
11495
by: barronmo | last post by:
I'm getting an error msg I don't understand, "global name EMR_globals is not defined", and could use some help. I've separated the application I'm building into several modules. One of the modules holds variables I need to pass from one module to another and is called 'EMR_globals'. Several other modules hold functions or user menus and...
2
23739
by: pythonnewb | last post by:
I am fairly new to programming but have some very basic Java background. I am just learning python and tried to make a module that would allow me to create a file containing an address book. I was planning to then create a program to detect input and use this module, but I am hung up. I have constructed the code that I thought would work (though...
1
11697
by: Lalit | last post by:
Hi I am very new to web development. I started with Pylons. I am using http://www.rexx.com/~dkuhlman/pylons_quick_site.html as reference to create a sample web page using pylons. I got stuck up at step 4.3 i.e when modifying controller to "return Response('<p>firstapp default</p>')" I am getting error of <type 'exceptions.NameError'>:...
2
3116
by: jmike | last post by:
I'm using some legacy code that has a user-defined exception in it. The top level program includes this line from TestRunError import * It also imports several other modules. These other modules do not explicitly import TestRunError. TestRunError is raised in various places throughout the modules.
3
18016
by: Netwatcher | last post by:
im try to activate the tutorial code for wxPython, it is working properly when i tell it to import * from wxPython.wx but with an error about the package, i've done as i was told to change the import to wx and change all wxsomething to wx.something but when i start it it gives me an error that say Traceback (most recent call last): File...
2
44067
by: Geared | last post by:
Hello I'm new to python (been using it all of 2 weeks) and I'm trying to write a program that compares the result of an equation using two different starting numbers that the user chooses. It also lets the user choose how many time it preforms the function and the amplitude of the function . here is the code. I'm using Vista 64 bit and Python...
4
4244
by: jorgejch | last post by:
Hello, I've started with python (3) recently. Initialy only for scripting. Now I'm trying the object oriented bit. I'm getting the following error message <Atom.Atom object at 0x7f0b09597fd0> Traceback (most recent call last): File "./Main.py", line 7, in <module> print (t.getAtomName()) File...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.