I am trying to load an arff file using Python’s ‘loadarff’ function from scipy.io.arff. The file has string attributes and it is giving the following error.
>>> data,meta = arff.loadarff(fpath) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/data/home/eex608/conda3_envs/PyT3/lib/python3.6/site-packages/scipy/io/arff/arffread.py", line 805, in loadarff return _loadarff(ofile) File "/data/home/eex608/conda3_envs/PyT3/lib/python3.6/site-packages/scipy/io/arff/arffread.py", line 838, in _loadarff raise NotImplementedError("String attributes not supported yet, sorry") NotImplementedError: String attributes not supported yet, sorry
How to read the arff successfully?
Advertisement
Answer
Since SciPy’s loadarff converts containings of arff file into NumPy array, it does not support strings as attributes. In 2020, you can use liac-arff package.
import arff data = arff.load(open('your_document.arff', 'r'))
However, make sure your arff document does not contain inline comments after a meaningful text. So there won’t be such inputs:
@ATTRIBUTE class {F,A,L,LF,MN,O,PE,SC,SE,US,FT,PO} %Check and make sure that FT and PO should be there
Delete or move comment to the next line.
I’d got such mistake in one document and it took some time to figure out what’s wrong.