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: [SPARK-14434][ML]:User guide doc and examples ...
Date Wed, 04 May 2016 20:07:49 GMT
Github user sethah commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12788#discussion_r62105335
  
    --- Diff: examples/src/main/scala/org/apache/spark/examples/ml/GaussianMixtureExample.scala
---
    @@ -0,0 +1,79 @@
    +/*
    + * 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.examples.ml
    +
    +// scalastyle:off println
    +
    +import org.apache.spark.{SparkConf, SparkContext}
    +// $example on$
    +import org.apache.spark.ml.clustering.{GaussianMixture, GaussianMixtureSummary}
    +import org.apache.spark.mllib.linalg.Vectors
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +// $example off$
    +
    +/**
    + * An example demonstrating Gaussian Mixture Model (GMM).
    + * Run with
    + * {{{
    + * bin/run-example ml.GaussianMixtureExample
    + * }}}
    + */
    +object GaussianMixtureExample {
    +  def main(args: Array[String]): Unit = {
    +    // Creates a Spark context and a SQL context
    +    val conf = new SparkConf().setAppName(s"${this.getClass.getSimpleName}")
    +    val sc = new SparkContext(conf)
    +    val sqlContext = new SQLContext(sc)
    +
    +    // $example on$
    +    // Crates a DataFrame
    +    val dataset: DataFrame = sqlContext.createDataFrame(Seq(
    +      (1, Vectors.dense(0.0, 0.0, 0.0)),
    +      (2, Vectors.dense(0.1, 0.1, 0.1)),
    +      (3, Vectors.dense(0.2, 0.2, 0.2)),
    +      (4, Vectors.dense(9.0, 9.0, 9.0)),
    +      (5, Vectors.dense(9.1, 9.1, 9.1)),
    +      (6, Vectors.dense(9.2, 9.2, 9.2))
    +    )).toDF("id", "features")
    +
    +    // Trains Gaussian Mixture Model
    +    val gmm = new GaussianMixture()
    +      .setK(2)
    +      .setFeaturesCol("features")
    +      .setPredictionCol("prediction")
    +      .setTol(0.0001)
    +      .setMaxIter(10)
    +      .setSeed(10)
    +    val model = gmm.fit(dataset)
    +
    +    // Shows the result
    +    val summary: GaussianMixtureSummary = model.summary
    +    println("Size of (number of data points in) each cluster: ")
    --- End diff --
    
    How do we decide what to print out here? If we want to keep in line with the mllib example,
we should print out the mean, weight, and covariance of each cluster. I don't see a reason
to show cluster and probability predictions separately, or at all really, since the examples
typically don't. This could be done via a call to transform anyway. Also, the output isn't
clean:
    
    ```
    Size of (number of data points in) each cluster: 
    3
    3
    ()
    Cluster centers of the transformed data:
    +----------+
    |prediction|
    +----------+
    |         1|
    |         1|
    |         1|
    |         0|
    |         0|
    |         0|
    +----------+
    
    Probability of each cluster:
    +--------------------+
    |         probability|
    +--------------------+
    |[2.09399616965883...|
    |[9.89133752129957...|
    |[2.09399616965785...|
    |[0.99999999999999...|
    |[0.99999999999999...|
    |[0.99999999999999...|
    +--------------------+
    ```
    
    If no other motivation, I'd prefer keeping in line with mllib example.


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