spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sethah <...@git.apache.org>
Subject [GitHub] spark pull request #13796: [SPARK-7159][ML] Add multiclass logistic regressi...
Date Thu, 18 Aug 2016 00:09:19 GMT
Github user sethah commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13796#discussion_r75230184
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/classification/MultinomialLogisticRegression.scala
---
    @@ -0,0 +1,622 @@
    +/*
    + * 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.classification
    +
    +import scala.collection.mutable
    +
    +import breeze.linalg.{DenseVector => BDV}
    +import breeze.optimize.{CachedDiffFunction, LBFGS => BreezeLBFGS, OWLQN => BreezeOWLQN}
    +import org.apache.hadoop.fs.Path
    +
    +import org.apache.spark.SparkException
    +import org.apache.spark.annotation.{Experimental, Since}
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.ml.feature.Instance
    +import org.apache.spark.ml.linalg._
    +import org.apache.spark.ml.param._
    +import org.apache.spark.ml.param.shared._
    +import org.apache.spark.ml.util._
    +import org.apache.spark.mllib.linalg.VectorImplicits._
    +import org.apache.spark.mllib.stat.MultivariateOnlineSummarizer
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.{Dataset, Row}
    +import org.apache.spark.sql.functions.{col, lit}
    +import org.apache.spark.sql.types.DoubleType
    +import org.apache.spark.storage.StorageLevel
    +
    +/**
    + * Params for multinomial logistic regression.
    + */
    +private[classification] trait MultinomialLogisticRegressionParams
    +  extends ProbabilisticClassifierParams with HasRegParam with HasElasticNetParam with
HasMaxIter
    +    with HasFitIntercept with HasTol with HasStandardization with HasWeightCol {
    +
    +  /**
    +   * Set thresholds in multiclass (or binary) classification to adjust the probability
of
    +   * predicting each class. Array must have length equal to the number of classes, with
values >= 0.
    +   * The class with largest value p/t is predicted, where p is the original probability
of that
    +   * class and t is the class' threshold.
    +   *
    +   * @group setParam
    +   */
    +  def setThresholds(value: Array[Double]): this.type = {
    +    set(thresholds, value)
    +  }
    +
    +  /**
    +   * Get thresholds for binary or multiclass classification.
    +   *
    +   * @group getParam
    +   */
    +  override def getThresholds: Array[Double] = {
    +    $(thresholds)
    +  }
    +}
    +
    +/**
    + * :: Experimental ::
    + * Multinomial Logistic regression.
    + */
    +@Since("2.1.0")
    +@Experimental
    +class MultinomialLogisticRegression @Since("2.1.0") (
    +    @Since("2.1.0") override val uid: String)
    +  extends ProbabilisticClassifier[Vector,
    +    MultinomialLogisticRegression, MultinomialLogisticRegressionModel]
    +    with MultinomialLogisticRegressionParams with DefaultParamsWritable with Logging
{
    +
    +  @Since("2.1.0")
    +  def this() = this(Identifiable.randomUID("mlogreg"))
    +
    +  /**
    +   * Set the regularization parameter.
    +   * Default is 0.0.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.1.0")
    +  def setRegParam(value: Double): this.type = set(regParam, value)
    +
    +  setDefault(regParam -> 0.0)
    +
    +  /**
    +   * Set the ElasticNet mixing parameter.
    +   * For alpha = 0, the penalty is an L2 penalty. For alpha = 1, it is an L1 penalty.
    +   * For 0 < alpha < 1, the penalty is a combination of L1 and L2.
    +   * Default is 0.0 which is an L2 penalty.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.1.0")
    +  def setElasticNetParam(value: Double): this.type = set(elasticNetParam, value)
    --- End diff --
    
    done.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message