You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by sryza <gi...@git.apache.org> on 2015/04/14 01:50:48 UTC

[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

GitHub user sryza opened a pull request:

    https://github.com/apache/spark/pull/5500

    SPARK-5888. [MLLIB]. Add OneHotEncoder as a Transformer

    This patch adds a one hot encoder for categorical features.  Planning to add documentation and another test after getting feedback on the approach.
    
    A couple choices made here:
    * There's an `includeFirst` option which, if false, creates numCategories - 1 columns and, if true, creates numCategories columns.  The default is true, which is the behavior in scikit-learn.
    * The user is expected to pass a `Seq` of category names when instantiating a `OneHotEncoder`.  These can be easily gotten from a `StringIndexer`.  The names are used for the output column names, which take the form colName_categoryName.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sryza/spark sandy-spark-5888

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/5500.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #5500
    
----
commit 04590bc362d011cc92b7ca1e703c15e090805b71
Author: Sandy Ryza <sa...@cloudera.com>
Date:   2015-04-13T23:40:04Z

    SPARK-5888. [MLLIB]. Add OneHotEncoder as a Transformer

----


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by sryza <gi...@git.apache.org>.
Github user sryza commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-97589096
  
    Hey @mengxr this should be ready for review again.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-95038494
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/30725/
    Test PASSed.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5500#discussion_r28827831
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/OneHotEncoder.scala ---
    @@ -0,0 +1,109 @@
    +/*
    + * 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.feature
    +
    +import org.apache.spark.annotation.AlphaComponent
    +import org.apache.spark.ml.UnaryTransformer
    +import org.apache.spark.ml.attribute.NominalAttribute
    +import org.apache.spark.mllib.linalg.{Vector, Vectors, VectorUDT}
    +import org.apache.spark.ml.param._
    +import org.apache.spark.ml.param.shared.{HasInputCol, HasOutputCol}
    +import org.apache.spark.ml.util.SchemaUtils
    +import org.apache.spark.sql.types.{DataType, DoubleType, StructType}
    +
    +/**
    + * A one-hot encoder that maps a column of label indices to a column of binary vectors, with
    + * at most a single one-value. By default, the binary vector has an element for each category, so
    + * with 5 categories, an input value of 2.0 would map to an output vector of
    + * (0.0, 0.0, 1.0, 0.0, 0.0). If includeFirst is set to false, the first category is omitted, so the
    + * output vector for the previous example would be (0.0, 1.0, 0.0, 0.0) and an input value
    + * of 0.0 would map to a vector of all zeros.  Omitting the first category enables the vector
    + * columns to be independent.
    + */
    +@AlphaComponent
    +class OneHotEncoder extends UnaryTransformer[Double, Vector, OneHotEncoder]
    +  with HasInputCol with HasOutputCol {
    +
    +  /**
    +   * Whether to include a component in the encoded vectors for the first category, defaults to true.
    +   * @group param
    +   */
    +  final val includeFirst: Param[Boolean] =
    +    new Param[Boolean](this, "includeFirst", "include first category")
    +  setDefault(includeFirst -> true)
    +
    +  /**
    +   * The names of the categories. Used to identify them in the attributes of the output column.
    +   * This is a required parameter.
    +   * @group param
    +   */
    +  final val labelNames: Param[Array[String]] =
    --- End diff --
    
    Label names should be extracted from the metadata, e.g., generated by `StringIndexer`.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-92553426
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/30206/
    Test PASSed.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5500#discussion_r28827821
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/OneHotEncoder.scala ---
    @@ -0,0 +1,109 @@
    +/*
    + * 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.feature
    +
    +import org.apache.spark.annotation.AlphaComponent
    +import org.apache.spark.ml.UnaryTransformer
    +import org.apache.spark.ml.attribute.NominalAttribute
    +import org.apache.spark.mllib.linalg.{Vector, Vectors, VectorUDT}
    +import org.apache.spark.ml.param._
    +import org.apache.spark.ml.param.shared.{HasInputCol, HasOutputCol}
    +import org.apache.spark.ml.util.SchemaUtils
    +import org.apache.spark.sql.types.{DataType, DoubleType, StructType}
    +
    +/**
    + * A one-hot encoder that maps a column of label indices to a column of binary vectors, with
    + * at most a single one-value. By default, the binary vector has an element for each category, so
    + * with 5 categories, an input value of 2.0 would map to an output vector of
    + * (0.0, 0.0, 1.0, 0.0, 0.0). If includeFirst is set to false, the first category is omitted, so the
    + * output vector for the previous example would be (0.0, 1.0, 0.0, 0.0) and an input value
    + * of 0.0 would map to a vector of all zeros.  Omitting the first category enables the vector
    + * columns to be independent.
    --- End diff --
    
    Without the first category the rest could be still dependent. We should say "Including the first category would make the vector columns linearly dependent because they sum up to one."


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-92539907
  
      [Test build #30206 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/30206/consoleFull) for   PR 5500 at commit [`04590bc`](https://github.com/apache/spark/commit/04590bc362d011cc92b7ca1e703c15e090805b71).


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5500#discussion_r28827864
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/feature/OneHotEncoderSuite.scala ---
    @@ -0,0 +1,86 @@
    +/*
    + * 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.feature
    +
    +import org.apache.spark.ml.attribute.{NominalAttribute, Attribute}
    +import org.apache.spark.mllib.linalg.Vector
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +import org.scalatest.FunSuite
    --- End diff --
    
    organize imports


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-96767787
  
      [Test build #31010 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/31010/consoleFull) for   PR 5500 at commit [`7e53579`](https://github.com/apache/spark/commit/7e535798306719352e65903da44d96aa31cb10e7).


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-95017876
  
      [Test build #30725 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/30725/consoleFull) for   PR 5500 at commit [`7e53579`](https://github.com/apache/spark/commit/7e535798306719352e65903da44d96aa31cb10e7).


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-93842807
  
      [Test build #30436 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/30436/consoleFull) for   PR 5500 at commit [`64da101`](https://github.com/apache/spark/commit/64da101d8fa1676a34ff4ebfb80e1597a3e688fe).


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-97593571
  
    @sryza I think we can add label names later. For this PR, if the input column carries a nominal attribute with values, we can use it for names. Otherwise, we put no names in the output column.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by sryza <gi...@git.apache.org>.
Github user sryza commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-93841917
  
    Updated the patch conform to the approach described above.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-95038490
  
      [Test build #30725 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/30725/consoleFull) for   PR 5500 at commit [`7e53579`](https://github.com/apache/spark/commit/7e535798306719352e65903da44d96aa31cb10e7).
     * This patch **passes all tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.
     * This patch does not change any dependencies.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-92553404
  
      [Test build #30206 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/30206/consoleFull) for   PR 5500 at commit [`04590bc`](https://github.com/apache/spark/commit/04590bc362d011cc92b7ca1e703c15e090805b71).
     * This patch **passes all tests**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `class OneHotEncoder(labelNames: Seq[String], includeFirst: Boolean = true) extends Transformer`
    
     * This patch does not change any dependencies.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-93857048
  
      [Test build #30436 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/30436/consoleFull) for   PR 5500 at commit [`64da101`](https://github.com/apache/spark/commit/64da101d8fa1676a34ff4ebfb80e1597a3e688fe).
     * This patch **passes all tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.
     * This patch does not change any dependencies.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-93565804
  
    @sryza Thanks for adding `OneHotEncoder` to `spark.ml`. One thing I want to discuss is the expected input of `OneHotEncoder`. There are two use cases:
    
    1. input a string column and output a vector column with binary values
    2. input a column with category indices and output a vector column with binary values
    
    The input to 2) would be the output from `StringIndexer` we recently merged. I would call 1) `OneHotEncoder`, which is a `UnaryTransformer`, and 2) `StringVectorizer`, which is a combination of `StringIndexer` and `OneHotEncoder`. If both of us agree on the semantics, we can implement 1) as OneHotEncoder in this PR and add `StringVectorizer` in another PR. Does it sound good to you?


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5500#discussion_r28460811
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/OneHotEncoder.scala ---
    @@ -0,0 +1,66 @@
    +/*
    + * 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.feature
    +
    +import org.apache.spark.annotation.AlphaComponent
    +import org.apache.spark.ml.Transformer
    +import org.apache.spark.ml.attribute.NominalAttribute
    +import org.apache.spark.ml.param._
    +import org.apache.spark.sql.DataFrame
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.types.{StringType, StructType}
    +
    +@AlphaComponent
    +class OneHotEncoder(labelNames: Seq[String], includeFirst: Boolean = true) extends Transformer
    --- End diff --
    
    Need JavaDoc. For pipeline components, we use default constructor and set parameter values in setters. Since OneHotEncoder is a unary transformer, you can extend `UnaryTransformer` directly and then overwrite `createTransformFunc`. Please check the implementation of `StringIndexer` and see how to define parameters and their default values.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by mengxr <gi...@git.apache.org>.
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5500#discussion_r28827825
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/OneHotEncoder.scala ---
    @@ -0,0 +1,109 @@
    +/*
    + * 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.feature
    +
    +import org.apache.spark.annotation.AlphaComponent
    +import org.apache.spark.ml.UnaryTransformer
    +import org.apache.spark.ml.attribute.NominalAttribute
    +import org.apache.spark.mllib.linalg.{Vector, Vectors, VectorUDT}
    +import org.apache.spark.ml.param._
    +import org.apache.spark.ml.param.shared.{HasInputCol, HasOutputCol}
    +import org.apache.spark.ml.util.SchemaUtils
    +import org.apache.spark.sql.types.{DataType, DoubleType, StructType}
    +
    +/**
    + * A one-hot encoder that maps a column of label indices to a column of binary vectors, with
    + * at most a single one-value. By default, the binary vector has an element for each category, so
    + * with 5 categories, an input value of 2.0 would map to an output vector of
    + * (0.0, 0.0, 1.0, 0.0, 0.0). If includeFirst is set to false, the first category is omitted, so the
    + * output vector for the previous example would be (0.0, 1.0, 0.0, 0.0) and an input value
    + * of 0.0 would map to a vector of all zeros.  Omitting the first category enables the vector
    + * columns to be independent.
    + */
    +@AlphaComponent
    +class OneHotEncoder extends UnaryTransformer[Double, Vector, OneHotEncoder]
    +  with HasInputCol with HasOutputCol {
    +
    +  /**
    +   * Whether to include a component in the encoded vectors for the first category, defaults to true.
    +   * @group param
    +   */
    +  final val includeFirst: Param[Boolean] =
    --- End diff --
    
    Use `BooleanParam` instead of `Param[Boolean]` for Java API compatibility.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by sryza <gi...@git.apache.org>.
Github user sryza commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-93802687
  
    @mengxr that makes sense to me, but did you mean to switch 1 and 2?  I.e. in this PR we should implement `OneHotEncoder`, which takes an input column with category indices and outputs a vector column, and in a later PR we can implement `StringVectorizer` which chains `StringIndexer` with `OneHotEncoder`.


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


[GitHub] spark pull request: SPARK-5888. [MLLIB]. Add OneHotEncoder as a Tr...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/5500#issuecomment-93857058
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/30436/
    Test PASSed.


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