Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sryza committed May 4, 2015
1 parent 7c539cf commit 6e257b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import org.apache.spark.sql.types.{DataType, DoubleType, StructType}
* 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.
* of 0.0 would map to a vector of all zeros. Including the first category makes the vector columns
* linearly dependent because they sum up to one.
*/
@AlphaComponent
class OneHotEncoder extends UnaryTransformer[Double, Vector, OneHotEncoder]
Expand All @@ -43,8 +43,8 @@ class OneHotEncoder extends UnaryTransformer[Double, Vector, OneHotEncoder]
* 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")
final val includeFirst: BooleanParam =
new BooleanParam(this, "includeFirst", "include first category")
setDefault(includeFirst -> true)

/**
Expand All @@ -59,7 +59,7 @@ class OneHotEncoder extends UnaryTransformer[Double, Vector, OneHotEncoder]
def setIncludeFirst(value: Boolean): this.type = set(includeFirst, value)

/** @group setParam */
def setLabelNames(value: Array[String]): this.type = set(labelNames, value)
def setLabelNames(attr: NominalAttribute): this.type = set(labelNames, attr.values.get)

/** @group setParam */
override def setInputCol(value: String): this.type = set(inputCol, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.ml.feature

import org.apache.spark.ml.attribute.{NominalAttribute, Attribute}
import org.apache.spark.ml.attribute.{Attribute, NominalAttribute}
import org.apache.spark.mllib.linalg.Vector
import org.apache.spark.mllib.util.MLlibTestSparkContext

Expand Down Expand Up @@ -49,7 +49,7 @@ class OneHotEncoderSuite extends FunSuite with MLlibTestSparkContext {
test("OneHotEncoder includeFirst = true") {
val (transformed, attr) = stringIndexed()
val encoder = new OneHotEncoder()
.setLabelNames(attr.values.get)
.setLabelNames(attr)
.setInputCol("labelIndex")
.setOutputCol("labelVec")
val encoded = encoder.transform(transformed)
Expand All @@ -68,7 +68,7 @@ class OneHotEncoderSuite extends FunSuite with MLlibTestSparkContext {
val (transformed, attr) = stringIndexed()
val encoder = new OneHotEncoder()
.setIncludeFirst(false)
.setLabelNames(attr.values.get)
.setLabelNames(attr)
.setInputCol("labelIndex")
.setOutputCol("labelVec")
val encoded = encoder.transform(transformed)
Expand Down

0 comments on commit 6e257b9

Please sign in to comment.