Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/14547#discussion_r75523869
--- Diff: mllib/src/main/scala/org/apache/spark/ml/tree/treeParams.scala ---
@@ -465,33 +497,64 @@ private[ml] trait GBTParams extends
TreeEnsembleParams with HasMaxIter with HasS
}
private[ml] object GBTClassifierParams {
- // The losses below should be lowercase.
- /** Accessor for supported loss settings: logistic */
- final val supportedLossTypes: Array[String] =
Array("logistic").map(_.toLowerCase)
+ // The values below should be lowercase.
+ /** Accessor for supported loss settings: logistic, bernoulli */
+ final val supportedLossTypes: Array[String] = Array("logistic",
"bernoulli")
+ /** Accessor for support entropy settings: loss-based or variance */
+ final val supportedImpurities: Array[String] = Array("loss-based",
"variance")
+ final def getLossBasedImpurity(loss: String): OldImpurity = loss match {
+ case "logistic" | "bernoulli" => ApproxBernoulliImpurity
+ case _ => throw new RuntimeException(
+ s"GBTClassifier does not have loss-based impurity for loss ${loss}")
+ }
}
private[ml] trait GBTClassifierParams extends GBTParams with
TreeClassifierParams {
/**
+ * Criterion used for information gain calculation (case-insensitive).
+ * Also used for terminal leaf value prediction.
+ * Supported: "loss-based" (default) and "variance"
+ *
+ * @group param
+ */
+ override val impurity: Param[String] = new Param[String](this,
"impurity", "Criterion used for" +
+ " information gain calculation (case-insensitive). Supported options:"
+
+ s" ${GBTClassifierParams.supportedImpurities.mkString(", ")}",
+ (value: String) =>
GBTClassifierParams.supportedImpurities.contains(value.toLowerCase))
+
+ /** (private[ml]) convert new impurity to old impurity */
+ override private[ml] def getOldImpurity: OldImpurity = {
+ getImpurity match {
+ case "loss-based" =>
GBTClassifierParams.getLossBasedImpurity($(lossType))
+ case "variance" => OldVariance
+ case _ =>
+ // Should never happen because of check in setter method.
+ throw new RuntimeException(
+ s"GBTClassifier was given unrecognized impurity: $impurity")
+ }
+ }
+
+ /**
* Loss function which GBT tries to minimize. (case-insensitive)
- * Supported: "logistic"
- * (default = logistic)
+ * Supported: "bernoulli" (default), "logistic" (alias for "bernoulli")
+ *
* @group param
*/
val lossType: Param[String] = new Param[String](this, "lossType", "Loss
function which GBT" +
" tries to minimize (case-insensitive). Supported options:" +
s" ${GBTClassifierParams.supportedLossTypes.mkString(", ")}",
(value: String) =>
GBTClassifierParams.supportedLossTypes.contains(value.toLowerCase))
- setDefault(lossType -> "logistic")
+ setDefault(lossType -> "bernoulli", impurity -> "loss-based")
--- End diff --
I'd prefer to keep "logistic" as the default so that we can use the same
default if we ever generalize GBTs to multiclass.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]