rebo16v commented on code in PR #48347:
URL: https://github.com/apache/spark/pull/48347#discussion_r1819795209


##########
mllib/src/main/scala/org/apache/spark/ml/feature/TargetEncoder.scala:
##########
@@ -0,0 +1,460 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.ml.feature
+
+import org.apache.hadoop.fs.Path
+
+import org.apache.spark.SparkException
+import org.apache.spark.annotation.Since
+import org.apache.spark.ml.{Estimator, Model}
+import org.apache.spark.ml.attribute.NominalAttribute
+import org.apache.spark.ml.param._
+import org.apache.spark.ml.param.shared._
+import org.apache.spark.ml.util._
+import org.apache.spark.sql.{Column, DataFrame, Dataset, Row}
+import org.apache.spark.sql.functions._
+import org.apache.spark.sql.types._
+
+/** Private trait for params and common methods for TargetEncoder and 
TargetEncoderModel */
+private[ml] trait TargetEncoderBase extends Params with HasLabelCol
+  with HasInputCol with HasInputCols with HasOutputCol with HasOutputCols with 
HasHandleInvalid {
+
+  /**
+   * Param for how to handle invalid data during transform().
+   * Options are 'keep' (invalid data presented as an extra categorical 
feature) or
+   * 'error' (throw an error).
+   * Note that this Param is only used during transform; during fitting, 
invalid data
+   * will result in an error.
+   * Default: "error"
+   * @group param
+   */
+  @Since("4.0.0")
+  override val handleInvalid: Param[String] = new Param[String](this, 
"handleInvalid",
+    "How to handle invalid data during transform(). " +
+      "Options are 'keep' (invalid data presented as an extra categorical 
feature) " +
+      "or 'error' (throw an error). Note that this Param is only used during 
transform; " +
+      "during fitting, invalid data will result in an error.",
+    ParamValidators.inArray(TargetEncoder.supportedHandleInvalids))
+
+  setDefault(handleInvalid -> TargetEncoder.ERROR_INVALID)
+
+  @Since("4.0.0")
+  val targetType: Param[String] = new Param[String](this, "targetType",
+    "Type of label considered during fit(). " +
+      "Options are 'binary' and 'continuous'. When 'binary', estimates are 
calculated as " +
+      "conditional probability of the target given each category. When 
'continuous', " +
+      "estimates are calculated as the average of the target given each 
category" +
+      "Note that this Param is only used during fitting.",
+    ParamValidators.inArray(TargetEncoder.supportedTargetTypes))
+
+  setDefault(targetType -> TargetEncoder.TARGET_BINARY)
+
+  final def getTargetType: String = $(targetType)
+
+  @Since("4.0.0")
+  val smoothing: DoubleParam = new DoubleParam(this, "smoothing",
+    "Smoothing factor for encodings. Smoothing blends in-class estimates with 
overall estimates " +
+      "according to the relative size of the particular class on the whole 
dataset, reducing the " +
+      "risk of overfitting due to unreliable estimates",
+    ParamValidators.gtEq(0.0))
+
+  setDefault(smoothing -> 0.0)
+
+  final def getSmoothing: Double = $(smoothing)
+
+  private[feature] lazy val inputFeatures = if (isSet(inputCol)) 
Array($(inputCol))
+  else if (isSet(inputCols)) $(inputCols)
+  else Array.empty[String]
+
+  private[feature] lazy val outputFeatures = if (isSet(outputCol)) 
Array($(outputCol))
+  else if (isSet(outputCols)) $(outputCols)
+  else inputFeatures.map{field: String => s"${field}_indexed"}
+
+  private[feature] def validateSchema(

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to