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

    https://github.com/apache/spark/pull/15211#discussion_r93980975
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/classification/LinearSVC.scala ---
    @@ -0,0 +1,558 @@
    +/*
    + * 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, DiffFunction, OWLQN => 
BreezeOWLQN}
    +import org.apache.hadoop.fs.Path
    +
    +import org.apache.spark.SparkException
    +import org.apache.spark.annotation.{Experimental, Since}
    +import org.apache.spark.broadcast.Broadcast
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.ml.feature.Instance
    +import org.apache.spark.ml.linalg._
    +import org.apache.spark.ml.linalg.BLAS._
    +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}
    +
    +/** Params for linear SVM Classifier. */
    +private[classification] trait LinearSVCParams extends ClassifierParams 
with HasRegParam
    +  with HasMaxIter with HasFitIntercept with HasTol with HasStandardization 
with HasWeightCol
    +  with HasThreshold with HasAggregationDepth {
    +
    +}
    +
    +/**
    + * :: Experimental ::
    + * Linear SVM Classifier with Hinge Loss and OWLQN optimizer
    + */
    +@Since("2.2.0")
    +@Experimental
    +class LinearSVC @Since("2.2.0") (
    +    @Since("2.2.0") override val uid: String)
    +  extends Classifier[Vector, LinearSVC, LinearSVCModel]
    +  with LinearSVCParams with DefaultParamsWritable {
    +
    +  @Since("2.2.0")
    +  def this() = this(Identifiable.randomUID("linearsvc"))
    +
    +  /**
    +   * Set the regularization parameter.
    +   * Default is 0.0.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setRegParam(value: Double): this.type = set(regParam, value)
    +  setDefault(regParam -> 0.0)
    +
    +  /**
    +   * Set the maximum number of iterations.
    +   * Default is 100.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setMaxIter(value: Int): this.type = set(maxIter, value)
    +  setDefault(maxIter -> 100)
    +
    +  /**
    +   * Whether to fit an intercept term.
    +   * Default is true.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setFitIntercept(value: Boolean): this.type = set(fitIntercept, value)
    +  setDefault(fitIntercept -> true)
    +
    +  /**
    +   * Set the convergence tolerance of iterations.
    +   * Smaller value will lead to higher accuracy at the cost of more 
iterations.
    +   * Default is 1E-6.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setTol(value: Double): this.type = set(tol, value)
    +  setDefault(tol -> 1E-6)
    +
    +  /**
    +   * whether to standardize the training features before fitting the model.
    +   * Default is true.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setStandardization(value: Boolean): this.type = set(standardization, 
value)
    +  setDefault(standardization -> true)
    +
    +  /**
    +   * Sets the value of param [[weightCol]].
    +   * If this is not set or empty, we treat all instance weights as 1.0.
    +   * Default is not set, so all instances have weight one.
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setWeightCol(value: String): this.type = set(weightCol, value)
    +
    +  /**
    +   * Set threshold in binary classification, in range [0, 1].
    +   *
    +   * @group setParam
    +   */
    +  @Since("2.2.0")
    +  def setThreshold(value: Double): this.type = set(threshold, value)
    +  setDefault(threshold -> 0.0)
    +
    +  /**
    +   * Suggested depth for treeAggregate (greater than or equal to 2).
    +   * If the dimensions of features or the number of partitions are large,
    +   * this param could be adjusted to a larger size.
    +   * Default is 2.
    +   *
    +   * @group expertSetParam
    +   */
    +  @Since("2.2.0")
    +  def setAggregationDepth(value: Int): this.type = set(aggregationDepth, 
value)
    +  setDefault(aggregationDepth -> 2)
    +
    +  @Since("2.2.0")
    +  override def copy(extra: ParamMap): LinearSVC = defaultCopy(extra)
    +
    +  /**
    +   *
    +   * Linear SVM Classifier 
(https://en.wikipedia.org/wiki/Support_vector_machine#Linear_SVM)
    +   *
    +   * This binary classifier optimizes the Hinge Loss using the OWLQN 
optimizer.
    +   *
    +   * @param dataset Training dataset
    +   * @return Fitted model
    +   */
    +  override protected def train(dataset: Dataset[_]): LinearSVCModel = {
    +    val w = if (!isDefined(weightCol) || $(weightCol).isEmpty) lit(1.0) 
else col($(weightCol))
    +    val instances: RDD[Instance] =
    +      dataset.select(col($(labelCol)), w, col($(featuresCol))).rdd.map {
    +        case Row(label: Double, weight: Double, features: Vector) =>
    +          Instance(label, weight, features)
    +      }
    +
    +    val instr = Instrumentation.create(this, instances)
    +    instr.logParams(params: _*)
    --- End diff --
    
    Write out the params explicitly.  This is to avoid accidentally serializing 
a big object in the future.


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

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

Reply via email to