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 #15415: [SPARK-14503][ML] spark.ml API for FPGrowth
Date Wed, 22 Feb 2017 23:14:18 GMT
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15415#discussion_r102535151
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/fpm/FPGrowthSuite.scala ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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.fpm
    +
    +import org.apache.spark.SparkFunSuite
    +import org.apache.spark.ml.util.DefaultReadWriteTest
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession}
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.types._
    +
    +class FPGrowthSuite extends SparkFunSuite with MLlibTestSparkContext with DefaultReadWriteTest
{
    +
    +  @transient var dataset: Dataset[_] = _
    +
    +  override def beforeAll(): Unit = {
    +    super.beforeAll()
    +    dataset = FPGrowthSuite.getFPGrowthData(spark)
    +  }
    +
    +  test("FPGrowth fit and transform with different data types") {
    +    Array(IntegerType, StringType, ShortType, LongType, ByteType).foreach { dt =>
    +      val intData = dataset.withColumn("features", col("features").cast(ArrayType(dt)))
    +      val model = new FPGrowth().setMinSupport(0.5).fit(intData)
    +      val generatedRules = model.setMinConfidence(0.5).getAssociationRules
    +      val expectedRules = spark.createDataFrame(Seq(
    +        (Array("2"), Array("1"), 1.0),
    +        (Array("1"), Array("2"), 0.75)
    +      )).toDF("antecedent", "consequent", "confidence")
    +        .withColumn("antecedent", col("antecedent").cast(ArrayType(dt)))
    +        .withColumn("consequent", col("consequent").cast(ArrayType(dt)))
    +      assert(expectedRules.sort("antecedent").rdd.collect().sameElements(
    +        generatedRules.sort("antecedent").rdd.collect()))
    +
    +      val transformed = model.transform(intData)
    +      val expectedTransformed = spark.createDataFrame(Seq(
    +        (0, Array("1", "2"), Array.emptyIntArray),
    +        (0, Array("1", "2"), Array.emptyIntArray),
    +        (0, Array("1", "2"), Array.emptyIntArray),
    +        (0, Array("1", "3"), Array(2))
    +      )).toDF("id", "features", "prediction")
    +        .withColumn("features", col("features").cast(ArrayType(dt)))
    +        .withColumn("prediction", col("prediction").cast(ArrayType(dt)))
    +      assert(expectedTransformed.sort("id").rdd.collect().sameElements(
    +        transformed.sort("id").rdd.collect()))
    +    }
    +  }
    +
    +  test("FPGrowth getFreqItems") {
    +    val model = new FPGrowth().setMinSupport(0.7).fit(dataset)
    +    val expectedFreq = spark.createDataFrame(Seq(
    +      (Array("1"), 4L),
    +      (Array("2"), 3L),
    +      (Array("1", "2"), 3L),
    +      (Array("2", "1"), 3L)
    --- End diff --
    
    This is a duplicate, right?  It explains the weird check for count() = 3 below.


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