python-3.x - 我正在尝试使用 NLTK 朴素贝叶斯分类器对文本进行分类。我收到 ValueError: too many values to unpack (expected 2)
问题描述
我对文本进行了清理并生成了二元语法。正在显示二元组,但我正在尝试训练和测试文本以使用 NLTK 朴素贝叶斯进行分类。我收到标题中显示的错误。
import nltk
from nltk.util import ngrams
#generating bigrams for all narratives
bigrams_all=ngrams(df,2)
#printing bigrams of one narrative
ninety_seven=df.loc[97].loc['FSR Narrative']
nine_bi=ngrams(ninety_seven,2)
print(nine_bi)
print([" ".join(t) for t in nine_bi])
# set that we'll train our classifier with
training_set = df[:1280]
# set that we'll test our classifier with
training_set = df[1280:]
classifier = nltk.NaiveBayesClassifier.train(training_set)
错误跟踪:
ValueError Traceback (most recent call last)
<ipython-input-13-745201c14989> in <module>()
113 training_set = df[1280:]
114
--> 115 classifier = nltk.NaiveBayesClassifier.train(training_set)
C:\Anaconda\envs\py35\lib\site-packages\nltk\classify\naivebayes.py in train(cls, labeled_featuresets, estimator)
195 # Count up how many times each feature value occurred, given
196 # the label and featurename.
--> 197 for featureset, label in labeled_featuresets:
198 label_freqdist[label] += 1
199 for fname, fval in featureset.items():
ValueError: too many values to unpack (expected 2)
解决方案
推荐阅读
- printing - 我在哪里可以获得 pdf 格式的官方 PyTorch 文档?
- python - python的'super'可以给子类它的父类类变量吗
- javascript - 组件的状态不断恢复到原来的状态
- wordpress - 这是插件还是自定义编码?
- nginx - 启用了某些配置的错误重定向
- snowflake-cloud-data-platform - Dedup rows with case insensitive (Snowflake)
- wordpress - 将部分放在同一页面上的 wordpress 选项卡中的 elementor 中
- github - 合并后文件被删除的问题如何解决?
- laravel - 此集合实例上不存在属性 [costo]
- python-3.x - 使用子图创建轴 - 散点图