我是ml的新手,我正在使用Spark ML构建一个预测系统。我读到特征工程的一个主要部分是找到每个特征在进行所需预测时的重要性。在我的问题中,我有三个分类特征和两个字符串特征。我使用OneHotEncoding技术来转换分类特征,使用简单的HashingTF机制来转换字符串特征。然后,这些作为管道的各个阶段输入,包括ml NaiveBayes和VectorAssembler (将所有特征组装到单个列中),分别使用训练和测试数据集进行拟合和转换。
一切都很好,除了我如何确定每个特性的重要性?我知道我现在只有几个功能,但我很快会添加更多的功能。我遇到的最接近的是带有spark ml模块的ChiSqSelector,但它似乎只适用于分类功能。
谢谢,任何线索都很感谢!
发布于 2016-08-22 22:17:34
您可以看到以下示例:
在问题的comment Information Gain based feature selection in Spark’s MLlib
:
发布于 2016-08-22 21:58:29
使用ChiSqSelector是可以的,你可以简单地离散化你的连续特征( HashingTF值)。http://spark.apache.org/docs/latest/mllib-feature-extraction.html中提供了一个示例,我将感兴趣的部分复制到这里:
// Discretize data in 16 equal bins since ChiSqSelector requires categorical features
// Even though features are doubles, the ChiSqSelector treats each unique value as a category
val discretizedData = data.map { lp =>
LabeledPoint(lp.label, Vectors.dense(lp.features.toArray.map { x => (x / 16).floor })) }发布于 2017-11-24 22:28:24
L1监管也是一种选择。
您可以使用L1从系数中获取特征重要性,并相应地决定将哪些特征用于贝叶斯训练。
Example of getting coefficients
更新:Some conditions under which coefficients not work very well
https://stackoverflow.com/questions/39076943
复制相似问题