Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8611#discussion_r39811301
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/regression/AFTSurvivalRegression.scala 
---
    @@ -0,0 +1,447 @@
    +/*
    + * 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.regression
    +
    +import scala.collection.mutable
    +
    +import breeze.linalg.{DenseVector => BDV}
    +import breeze.optimize.{CachedDiffFunction, DiffFunction, LBFGS => 
BreezeLBFGS}
    +
    +import org.apache.spark.{SparkException, Logging}
    +import org.apache.spark.annotation.{Since, Experimental}
    +import org.apache.spark.ml.{Model, Estimator}
    +import org.apache.spark.ml.param._
    +import org.apache.spark.ml.param.shared._
    +import org.apache.spark.ml.util.{SchemaUtils, Identifiable}
    +import org.apache.spark.mllib.linalg.{Vector, Vectors, VectorUDT}
    +import org.apache.spark.mllib.linalg.BLAS
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.{Row, DataFrame}
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.types.{DoubleType, StructType}
    +import org.apache.spark.storage.StorageLevel
    +
    +/**
    + * Params for accelerated failure time (AFT) regression.
    + */
    +private[regression] trait AFTSurvivalRegressionParams extends Params
    +  with HasFeaturesCol with HasLabelCol with HasPredictionCol with 
HasMaxIter
    +  with HasTol with HasFitIntercept {
    +
    +  /**
    +   * Param for censored column name.
    +   * The value of this column could be 0 or 1.
    +   * If the value is 1, it means the event has occurred i.e. uncensored; 
otherwise it censored.
    +   * @group param
    +   */
    +  @Since("1.6.0")
    +  final val censoredCol: Param[String] = new Param(this, "censoredCol", 
"censored column name")
    +
    +  /** @group getParam */
    +  @Since("1.6.0")
    +  def getCensoredCol: String = $(censoredCol)
    +
    +  /**
    +   * Param for quantile probabilities array.
    +   * Values of the quantile probabilities array should be in the range [0, 
1].
    +   * @group param
    +   */
    +  @Since("1.6.0")
    +  final val quantileProbabilities: DoubleArrayParam = new 
DoubleArrayParam(this, "quantile",
    +    "quantile probabilities array", (t: Array[Double]) => 
t.forall(ParamValidators.inRange(0, 1)))
    +
    +  /** @group getParam */
    +  @Since("1.6.0")
    +  def getQuantileProbabilities: Array[Double] = $(quantileProbabilities)
    +
    +  /** Checks whether the input has quantile probabilities array. */
    +  protected[regression] def hasQuantileProbabilities: Boolean = {
    +    isDefined(quantileProbabilities) && $(quantileProbabilities).size != 0
    +  }
    +
    +  /**
    +   * Validates and transforms the input schema with the provided param map.
    +   * @param schema input schema
    +   * @param fitting whether this is in fitting or prediction
    +   * @return output schema
    +   */
    +  protected def validateAndTransformSchema(
    +      schema: StructType,
    +      fitting: Boolean): StructType = {
    +    SchemaUtils.checkColumnType(schema, $(featuresCol), new VectorUDT)
    +    if (fitting) {
    +      SchemaUtils.checkColumnType(schema, $(censoredCol), DoubleType)
    +      SchemaUtils.checkColumnType(schema, $(labelCol), DoubleType)
    +    }
    +    SchemaUtils.appendColumn(schema, $(predictionCol), DoubleType)
    +  }
    +}
    +
    +/**
    + * :: Experimental ::
    + * Fit a parametric survival regression model named accelerated failure 
time (AFT) model
    + * ([[https://en.wikipedia.org/wiki/Accelerated_failure_time_model]])
    + * based on the Weibull distribution of the survival time.
    + */
    +@Experimental
    +@Since("1.6.0")
    +class AFTSurvivalRegression @Since("1.6.0") (@Since("1.6.0") override val 
uid: String)
    +  extends Estimator[AFTSurvivalRegressionModel] with 
AFTSurvivalRegressionParams with Logging {
    +
    +  @Since("1.6.0")
    +  def this() = this(Identifiable.randomUID("aftSurvReg"))
    +
    +  /** @group setParam */
    +  @Since("1.6.0")
    +  def setFeaturesCol(value: String): this.type = set(featuresCol, value)
    +
    +  /** @group setParam */
    +  @Since("1.6.0")
    +  def setLabelCol(value: String): this.type = set(labelCol, value)
    +
    +  /** @group setParam */
    +  @Since("1.6.0")
    +  def setCensoredCol(value: String): this.type = set(censoredCol, value)
    +  setDefault(censoredCol -> "censored")
    +
    +  /** @group setParam */
    +  @Since("1.6.0")
    +  def setPredictionCol(value: String): this.type = set(predictionCol, 
value)
    +
    +  /**
    +   * Set if we should fit the intercept
    +   * Default is true.
    +   * @group setParam
    +   */
    +  @Since("1.6.0")
    +  def setFitIntercept(value: Boolean): this.type = set(fitIntercept, value)
    +  setDefault(fitIntercept -> true)
    +
    +  /**
    +   * Set the maximum number of iterations.
    +   * Default is 100.
    +   * @group setParam
    +   */
    +  @Since("1.6.0")
    +  def setMaxIter(value: Int): this.type = set(maxIter, value)
    +  setDefault(maxIter -> 100)
    +
    +  /**
    +   * Set the convergence tolerance of iterations.
    +   * Smaller value will lead to higher accuracy with the cost of more 
iterations.
    +   * Default is 1E-6.
    +   * @group setParam
    +   */
    +  @Since("1.6.0")
    +  def setTol(value: Double): this.type = set(tol, value)
    +  setDefault(tol -> 1E-6)
    +
    +  /**
    +   * Extract [[featuresCol]], [[labelCol]] and [[censoredCol]] from input 
dataset,
    +   * and put it in an RDD with strong types.
    +   */
    +  protected[ml] def extractAFTPoints(
    +      dataset: DataFrame): RDD[AFTPoint] = {
    --- End diff --
    
    Should fit into one line.


---
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]

Reply via email to