嗨,我是机器学习的新手。
我正在使用textblob库进行简单的情感分析。
我正在尝试使用与https://textblob.readthedocs.io/en/dev/classifiers.html上的条件完全匹配的json文件中的数据
当我运行函数时:
def trainAndClassify(name):
with open(name + '.json', 'r') as fp:
cl = NaiveBayesClassifier(fp, format="json")
answer = cl.classify("The beer is good. But the hangover is horrible.")
print( answer )
我得到以下跟踪:
Traceback (most recent call last):
File "sentiment.py", line 102, in <module>
run()
File "sentiment.py", line 95, in run
constructor(sys.argv[2])
File "sentiment.py", line 81, in constructor
cl = NaiveBayesClassifier(fp, format="json")
File "/usr/local/lib/python3.4/dist-packages/textblob/classifiers.py", line 185, in __init__
self.train_features = [(self.extract_features(d), c) for d, c in self.train_set]
File "/usr/local/lib/python3.4/dist-packages/textblob/classifiers.py", line 185, in <listcomp>
self.train_features = [(self.extract_features(d), c) for d, c in self.train_set]
ValueError: too many values to unpack (expected 2)
我的JSON文件结构如下:
[{"text": "This is a good sentence", "label": "pos"}]
为了简单起见,我将其与伪造数据减少到一行。
我在做什么错了?