我正在尝试创建一个多类文本分类器,如此处所述。但是,我的代码在行中断:
NB_pipeline.fit(X_train, train[category])
以下是我收到的错误:
File "pandashashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandashashtable.c:12322)
我试图找出train[category]
返回的内容,但我得到了同样的错误。
1(X_train
是一个有一列的dataframe
,包含客户反馈。
2(train
是两列dataframe
;第一列包含客户评论(与X_train
相同(,第二列包含 5 个类别之一 (Systems Error, Proactive Communication, Staff Behaviour, Website Functionalities, Others
(。
3(category
是上述类别之一。
以下是示例火车dataframe
:
Index Feedback Category
0 While making payment got system error. System error
Staff behaviour was good at hotel
1 While making payment got system error. Staff Behaviour
Staff behaviour was good at hotel
这是最容易被忽视的问题之一。
此错误的原因是脚本正在查找的"列"在数据帧中不可用。您拥有的所有 5 个类别都应该是输入数据框中的列,如果其中一个类别适用于反馈/评论,则行将占 1/0。理想情况下,输入数据帧应如下所示。
Index Feedback System error Staff Behaviour
0 While making payment got system error. 1 1
Staff behaviour was good at hotel
1 While making payment got system error. 1 0
2 Staff behaviour was good at hotel 0 1
我使用相同的注释来显示输入数据帧的外观。