我正在使用朴素的托架和SVM进行情感分析, 我引用了这段代码https://github.com/sravyaysk/MyProjects/blob/master/SentimentAnalysis.py
我在python 3中转换了此实现,下面是实现它的代码,它将正值指定为1,将负值指定为2,我将中性值添加为3,但仍然返回无关的错误
我的代码和数据集 https://drive.google.com/drive/folders/1NiZC7DNOkzpUFZ1X6PjD2rrn99TGXnkL?usp=sharing
这是我遇到错误的代码部分:SVM.py
labels_to_array={"positive":1,"negative":2}
labels=[labels_to_array[tweet[1]] for tweet in ppTrainingData]
y=np.array(labels)
错误:
KeyError Traceback (most recent call last)
<ipython-input-11-d1d8945f9453> in <module>
161 # Lets map positive to 1 and negative to 2 so that everything is nicely represented as arrays
162 labels_to_array={"neutral":1,"negative":2,"positive":3}
--> 163 labels=[labels_to_array[tweet[1]] for tweet in ppTrainingData]
164 y=np.array(labels)
165
<ipython-input-11-d1d8945f9453> in <listcomp>(.0)
161 # Lets map positive to 1 and negative to 2 so that everything is nicely represented as arrays
162 labels_to_array={"neutral":1,"negative":2,"positive":3}
--> 163 labels=[labels_to_array[tweet[1]] for tweet in ppTrainingData]
164 y=np.array(labels)
165
KeyError: 'neutral'