spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkbradley <...@git.apache.org>
Subject [GitHub] spark pull request #15211: [SPARK-14709][ML] spark.ml API for linear SVM
Date Thu, 22 Dec 2016 19:51:33 GMT
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15211#discussion_r93686305
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/classification/LinearSVCSuite.scala
---
    @@ -0,0 +1,178 @@
    +/*
    + * 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 breeze.linalg.{DenseVector => BDV}
    +import scala.util.Random
    +
    +import org.apache.spark.SparkFunSuite
    +import org.apache.spark.ml.classification.LinearSVCSuite._
    +import org.apache.spark.ml.feature.LabeledPoint
    +import org.apache.spark.ml.linalg.Vectors
    +import org.apache.spark.ml.param.ParamsSuite
    +import org.apache.spark.ml.util.{DefaultReadWriteTest, MLTestingUtils}
    +import org.apache.spark.ml.util.TestingUtils._
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +import org.apache.spark.sql.{Dataset, Row}
    +
    +
    +class LinearSVCSuite extends SparkFunSuite with MLlibTestSparkContext with DefaultReadWriteTest
{
    +
    +  import testImplicits._
    +
    +  private val nPoints = 50
    +  @transient var smallBinaryDataset: Dataset[_] = _
    +  @transient var smallValidationDataset: Dataset[_] = _
    +  private val eps: Double = 1e-5
    +
    +  override def beforeAll(): Unit = {
    +    super.beforeAll()
    +
    +    // NOTE: Intercept should be small for generating equal 0s and 1s
    +    val A = 0.01
    +    val B = -1.5
    +    val C = 1.0
    +    smallBinaryDataset = generateSVMInput(A, Array[Double](B, C), nPoints, 42).toDF()
    +    smallValidationDataset = generateSVMInput(A, Array[Double](B, C), nPoints, 17).toDF()
    +  }
    +
    +  test("Linear SVC binary classification") {
    +    val svm = new LinearSVC()
    +    val model = svm.fit(smallBinaryDataset)
    +    assert(model.transform(smallValidationDataset)
    +      .where("prediction=label").count() > nPoints * 0.8)
    +  }
    +
    +  test("Linear SVC binary classification with regularization") {
    +    val svm = new LinearSVC()
    +    val model = svm.setRegParam(0.1).fit(smallBinaryDataset)
    +    assert(model.transform(smallValidationDataset)
    +      .where("prediction=label").count() > nPoints * 0.8)
    +  }
    +
    +  test("params") {
    +    ParamsSuite.checkParams(new LogisticRegression)
    +    val model = new LinearSVCModel("linearSVC", Vectors.dense(0.0), 0.0)
    +    ParamsSuite.checkParams(model)
    +  }
    +
    +  test("linear svc: default params") {
    +    val lsvc = new LinearSVC()
    +    assert(lsvc.getLabelCol === "label")
    +    assert(lsvc.getFeaturesCol === "features")
    +    assert(lsvc.getPredictionCol === "prediction")
    +    assert(lsvc.getRawPredictionCol === "rawPrediction")
    +    assert(!lsvc.isDefined(lsvc.weightCol))
    +    assert(lsvc.getFitIntercept)
    +    assert(lsvc.getStandardization)
    +    val model = lsvc.fit(smallBinaryDataset)
    --- End diff --
    
    set maxIter to 2 for speed


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