3 Replies - 552 Views - Last Post: 21 February 2013 - 06:32 AM Rate Topic: -----

#1 Mola_SH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-February 13

need help in Naive bayes classifier code

Posted 21 February 2013 - 01:03 AM

hello everybody !

i need a good programmer helping me because i found an open source code but i still have an error and i have been tried since 2 week ago ..

this part of code :
usage = ('Usage: %s <file> <expected doctype> <other doctype>' % sys.argv[0])


if len(sys.argv) !=4:
		raise ValueError(usage)

input_file = sys.argv[1]
doctype_expected = sys.argv[2]
doctype_other = sys.argv[3]

classifier.set_doctypes(doctype_expected, doctype_other)

results = None 


what is <file> mean is it a database or what ?
i hope any one explane the usage variables content for me :(/>

Is This A Good Question/Topic? 0
  • +

Replies To: need help in Naive bayes classifier code

#2 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: need help in Naive bayes classifier code

Posted 21 February 2013 - 03:03 AM

the arguments are defined in order with 0 being the script that is run, if i remeber correctly.

This means that sys.argv[1] is the first argument passed to this script, so anything that is given as the first argument after the name of the script is stored in input_file.

Still you should be more clear on what the actual problem with the code is.

Also if you wish to implement something like this in your own code i would strongly recommend using the argparse module which is well documented here http://docs.python.o...o/argparse.html and will allow you to very easily handle any kind of arguments you may want.

Hope this helps, if you need anything else just ask.
Nekroze
Was This Post Helpful? 0
  • +
  • -

#3 Mola_SH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-February 13

Re: need help in Naive bayes classifier code

Posted 21 February 2013 - 05:47 AM

the problem is that my pyscribter editor marked this line as an error and i'm as a beginner programmer in python couldn't know how to solve it :
 	usage = ('Usage: %s <file> <expected doctype> <other doctype>' % sys.argv[0]) 


and any using of " usage " var

this is a link of all classes ,would you mind checking on ?

http://www.4shared.c...ier-master.html
Was This Post Helpful? 0
  • +
  • -

#4 lisperati  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 16-February 13

Re: need help in Naive bayes classifier code

Posted 21 February 2013 - 06:32 AM

First of all the line is fine as it is. What is probably happening is you dont have an import statement for sytem because argv is part of the system module.

you need this at the top of your file.
import sys



Then what sys.argv[0] does is read the file name you are running.
usage is just a variable to hold the string in brackets and all this does is print out the string as a useful helper on what to put on your command line to make use of this program. ie the program expects a file to load. It also wants to be told what format the file is like pdf or doc or text etc.

Regards
Lisperati
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1