我正在准备来自网站的数据库分析:
https://www.kaggle.com/c/predicting-loan-default/data
我的变量emp_length大约有3000个不同的值。有些值是相同的或具有相同的关键词(例如account, accountant, accounting, account specialist, acct.)。有些词包含错误或缩写。我想减少这些值以简化名称并编码为数值。我尝试在R中使用文本挖掘来查找关键词,但我并不确信这是正确的方法。有人对此有任何想法吗?
回答:
尝试适应这种“数据科学”方法:
示例输入数据:
emp_length<-c("account","accountant","accounting","account specialist","Data Scientist","Data Science Expert")
字符串距离 + 聚类
cluster<-kmeans(stringdistmatrix(emp_length,emp_length,method="jw"),centers=2)cluster_n<-cluster$cluster
可能的标签分组
cbind(emp_length,cluster_n) emp_length cluster_n[1,] "account" "2" [2,] "accountant" "2" [3,] "accounting" "2" [4,] "account specialist" "2" [5,] "Data Scientist" "1" [6,] "Data Science Expert" "1"
这有助于检测标签以进行分组并转换为数值格式。