LGBM 如何在没有规范的情况下处理分类特征

how LGBM handles the categorical features without specification

我正在玩 LGBM 并使用 StingIndexer 为我的分类特征编制索引。但在那之后我还没有告诉我的模型哪些特征是分类特征。所以,我想知道它是如何知道哪些特征是分类特征

这是我初始化 LGBM 模型的方式。

val lgbm = new LightGBMClassifier("lgbm").
  setObjective("binary").
  setFeatureFraction(0.85).
  setFeaturesCol("features").
  setLabelCol("is_booker")

如果您正在使用 mmlspark(您没有提到您如何在 Scala 中使用 LightGBM),LightGBM 会根据列的属性自动确定哪些列应该被视为分类列。

来自 Azure/mmlspark#559:

...if you use string indexer or our value indexer, categorical metadata will be automatically added to the dataframe and lightgbm will actually be able to interpret it and treat those columns as categoricals by splitting on the feature values directly (so you won't need to one-hot-encode them)

完成此操作的方法称为 LightGBMUtils.getCategoricalIndexes(),您可以在 https://github.com/Azure/mmlspark/blob/95c1f8a782191e3578587a49313e1d57abee5da3/src/main/scala/com/microsoft/ml/spark/lightgbm/LightGBMUtils.scala#L74-L104 找到它。

LightGBMBase.getCategoricalIndexes() 在训练期间重复使用该方法:

如果我是正确的,你正在使用 mmlspark,并且你对它的工作原理有进一步的疑问,我建议在 Azure/mmlspark.

中打开问题