【发布时间】:2019-07-25 21:38:33
【问题描述】:
我有一个数据框,df 由文本和数字特征组成,类似于下图所示。
Feature 1 Feature 2 Feature 3 Feature 4 Label
10 20 keyword Human 1
2 3 Keywords Dog 0
8 2 Stackoverflow cat 0
目前我使用factorize函数将文本特征转换为数字特征,然后使用新的数据框进行分类。
df[' Feature 3'] = df[' Feature 3'].factorize()[0]
df[' Feature 4'] = df[' Feature 4'].factorize()[0]
运行上述代码后,我的数据框如下所示
Feature 1 Feature 2 Feature 3 Feature 4 Label
10 20 0 0 1
2 3 1 1 0
8 2 2 2 0
factorize 函数将 'keywords' 和 'keyword' 读取为不同的单词,那么是否有任何函数可以将类似于 'keywords' 和 'keyword' 的单词读取为相同的单词?
输出数据框实际上应该是这样的
Feature 1 Feature 2 Feature 3 Feature 4 Label
10 20 0 0 1
2 3 0 1 0
8 2 1 2 0
【问题讨论】:
标签: python text-classification