我必须对一些json格式的文档进行集群。我想修改特性哈希来减少维度。首先,我的意见是:
doc_a = { "category": "election, law, politics, civil, government",
"expertise": "political science, civics, republican"
}
doc_b = { "category": "Computers, optimization",
"expertise": "computer science, graphs, optimization"
}
doc_c = { "category": "Election, voting",
"expertise": "political science, republican"
}
doc_d = { "category": "Engineering, Software, computers",
"expertise": "computers, programming, optimization"
}
doc_e = { "category": "International trade, politics",
"expertise": "civics, political activist"
}
如何创建相似性,然后使用散列来创建每个文档的相似性?读了http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.FeatureHasher.html我有点迷路了。 我不确定是否必须使用“dict”或将数据转换为具有一些整数,然后将“pair”用于featureHasher的“input_type”。我应该如何解释featureHasher的输出?例如,示例http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.FeatureHasher.html输出一个numpy数组。在
^{pr2}$我认为行是文档,列值是。。?比方说,如果我想聚类或查找这些向量之间的相似性(使用余弦或Jaccard),不确定是否必须进行项目比较?在
预期输出:doc_a、doc_cc和doc_e应该在一个集群中,其余的在另一个集群中。在
谢谢!在
如果您使用
HashingVectorizer
而不是FeatureHasher
来解决这个问题,您会使事情变得更简单。HashingVectorizer
负责将输入数据标记化,并可以接受字符串列表。在这个问题的主要挑战是您实际上有两种文本特征,}。这种情况下的诀窍是为这两个特性安装一个哈希向量器,然后组合输出:
category
和{相关问题 更多 >
编程相关推荐