-2

I am trying to run this python script called fselect in windows 7. It can be downloaded from this website: http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/ under this name called Feature selection tool. I am running it on Python 2.7.2.Facing a bit of problem running it..

Typed this first in IDLE:

>>> import pprint
>>> import sys
>>> print pprint.pprint(sys.path)
>>> sys.path.append("C:\Users\HP\Documents\MATLAB\libsvm-3.11\tools")
>>> import fselect
Usage:  training_file [testing_file]

Then the problem is when i type the next part:

Tried this:

>>> ./fselect.py TrainVec
SyntaxError: invalid syntax

Next tried this:

>>> fselect.py TrainVec
SyntaxError: invalid syntax

Next tried this:

>>> TrainVec

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    TrainVec
NameError: name 'TrainVec' is not defined

Tried this also:

>>> TrainVec.mat

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    TrainVec.mat
NameError: name 'TrainVec' is not defined

What is the correct way of typing it? Need some guidance on it...

tried running using cmd but there is an error...

enter image description here

lakshmen
  • 28,346
  • 66
  • 178
  • 276

4 Answers4

1

If you are trying to run the fselect.py directly from the command prompt, make sure that python is set into the path variable. For guidance with that, please read http://people.cis.ksu.edu/~schmidt/200f07/setpath.html.

The script will also invoke grid.py. grid.py requires gnuplot to be there. So ensure that grid.py is running properly and if necessary check the paths of the svm_train, svm_test in the script along with that of grid.py. Hope it will work now.

Spectre87
  • 2,374
  • 1
  • 24
  • 37
partha
  • 26
  • 1
0

If it is a tool, you should run it, not import it. And of course you should not try to enter random commands, even if they are valid shell commands, in your Python prompt.

wRAR
  • 25,009
  • 4
  • 84
  • 97
  • I cannot, it's so trivial I don't know how to explain this further. – wRAR Feb 09 '12 at 16:16
  • got to run.. but one more qn: where shld i place the TrainVec file? – lakshmen Feb 09 '12 at 16:44
  • what shld the command be like? It is because when i run it, it returns me this: Usage: C:\Users\HP\Documents\MATLAB\libsvm-3.11\tools\fselect.py training_file [testing_file] – lakshmen Feb 17 '12 at 08:38
  • C:\Users\HP\Documents\MATLAB\libsvm-3.11\tools\fselect.py training_file [testing_file] – wRAR Feb 17 '12 at 10:16
  • does it matter if it python 3.2 or python 2 series? does it make a difference? – lakshmen Feb 17 '12 at 10:56
  • btw when i run C:\Users\HP\Documents\MATLAB\libsvm-3.11\tools\fselect.py training_file [testing_file], i get SyntaxError: invalid syntax. it pointing to : in the line... – lakshmen Feb 17 '12 at 10:58
0

Assuming TrainVec is your data (since you use it in the context of TrainVec.mat it must be a Matlab data file) then run it on the Command Prompt like this:

python fselect.py TrainVec.mat

The example of ./fselect.py is intended for Unix systems. Make sure you run the above command in what ever directory you have saved fselect.py in.

If you need to write your own scripts to leverage this .py file then I refer you here for an example of how to do this.

Community
  • 1
  • 1
BeRecursive
  • 6,286
  • 1
  • 24
  • 41
0

Like the previous answer said, it looks like you are (incorrectly) trying to run the script from inside the Python interpreter. According to the documentation on the page you link to, it is not a module but a free-standing script and should be run as such:

Usage: ./fselect.py training_file [testing_file]
martineg
  • 1,269
  • 13
  • 14
  • when it run like this, C:\Users\HP\Documents\MATLAB\libsvm-3.11\tools\fselect.py TrainVec.mat [TestVec.mat] it gives me this error SyntaxError: invalid syntax – lakshmen Feb 09 '12 at 17:27
  • `[]` mean it is an optional argument. – wRAR Feb 17 '12 at 10:17