NLTK ValueError:太多值无法解包(预期2) [英] NLTK ValueError: too many values to unpack (expected 2)

查看:85
本文介绍了NLTK ValueError:太多值无法解包(预期2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该训练模型以确定姓名的性别. 我把列表做成

I should train the model to determine gender of a name. I made the list like

[['Friedtic','Homer'],['Alice','Miranda']]

[['Friedtic', 'Homer'], ['Alice', 'Miranda']]

我尝试了

classifier = nltk.NaiveBayesClassifier.train(train_data)

但是有错误

ValueError:太多值无法解包(预期2)

ValueError: too many values to unpack (expected 2)

推荐答案

您需要将数据结构化为元组项.此外,火车集中的每个项目都需要一个标签,该标签告诉分类器该名称属于哪个类别.最后,您需要包含有关如何识别名称(假设)性别"的信息的功能.

You need to structure your data into tuple items. Additionally, every item in your train set needs a label which tells the classifier to what class the name belongs. Finally, you need features that contain information on how to identify a name's (supposed) 'gender'.

NLTK教程下显示了如何构造商品性别识别.

我可以告诉您如何做,但这很清楚开发人员的意图.

I could show you how, but this is quite clearly how the developers intended it.

这篇关于NLTK ValueError:太多值无法解包(预期2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆