How can I handle the error in load_svmlight_file?

129 views Asked by At

when I run this code in mac:

x_train, y_train = load_svmlight_file("mq2008.train")

I get this error in bash:

-bash: syntax error near unexpected token `('

and if I run it in shell, I face this error:

NameError: name 'load_svmlight_file' is not defined

How can I solve this problem?

1

There are 1 answers

3
sam On

Welcome to StackOverflow!

IMO, you have a Python code and trying to replicate its output. If so, you should first load all Python-related imports first. This is what it means to NameError here, Python interpreter is not able to understand what it is, because this function is not part of its existing definitions it has.

If I may suggest, please spend some time to get the hands-on-learning of Python.