473,503 Members | 1,360 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 2989
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
6687
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
5838
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
10528
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
11493
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...
2
23734
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...
1
11680
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...
2
3113
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...
3
17998
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...
2
44055
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...
4
4239
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>...
0
7282
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,...
0
7339
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...
1
6995
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...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
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,...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
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...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.