Skip to content

Commit d0d45f9

Browse files
committed
update doc
1 parent e7f41cb commit d0d45f9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

mllib/src/main/scala/org/apache/spark/ml/feature/LabelIndexer.scala

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717

1818
package org.apache.spark.ml.feature
1919

20-
import org.apache.spark.ml.{Estimator, Model}
20+
import org.apache.spark.annotation.AlphaComponent
2121
import org.apache.spark.ml.param._
22+
import org.apache.spark.ml.{Estimator, Model}
2223
import org.apache.spark.sql.DataFrame
2324
import org.apache.spark.sql.functions._
2425
import org.apache.spark.sql.types.{IntegerType, StringType, StructField, StructType}
2526
import org.apache.spark.util.collection.OpenHashMap
2627

28+
/**
29+
* Base trait for [[LabelIndexer]] and [[LabelIndexerModel]].
30+
*/
2731
private[feature] trait LabelIndexerBase extends Params with HasLabelCol with HasOutputCol {
2832

29-
/** Validates and transforms input schema. */
33+
/** Validates and transforms the input schema. */
3034
protected def validateAndTransformSchema(schema: StructType, paramMap: ParamMap): StructType = {
3135
val map = this.paramMap ++ paramMap
3236
val labelType = schema(map(labelCol)).dataType
@@ -41,6 +45,13 @@ private[feature] trait LabelIndexerBase extends Params with HasLabelCol with Has
4145
}
4246
}
4347

48+
/**
49+
* :: AlphaComponent ::
50+
* A label indexer that maps a string column of labels to an integer column of label indices.
51+
* The indices are in [0, numLabels), ordered by label frequencies.
52+
* The most frequent label gets index 0.
53+
*/
54+
@AlphaComponent
4455
class LabelIndexer extends Estimator[LabelIndexerModel] with LabelIndexerBase {
4556

4657
/** @group setParam */
@@ -65,6 +76,11 @@ class LabelIndexer extends Estimator[LabelIndexerModel] with LabelIndexerBase {
6576
}
6677
}
6778

79+
/**
80+
* :: AlphaComponent ::
81+
* Model fitted by [[LabelIndexer]].
82+
*/
83+
@AlphaComponent
6884
class LabelIndexerModel private[ml] (
6985
override val parent: LabelIndexer,
7086
override val fittingParamMap: ParamMap,

mllib/src/test/scala/org/apache/spark/ml/feature/LabelIndexerSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.ml.feature
2020
import org.scalatest.FunSuite
2121

2222
import org.apache.spark.mllib.util.MLlibTestSparkContext
23-
import org.apache.spark.sql.{Row, SQLContext}
23+
import org.apache.spark.sql.SQLContext
2424

2525
class LabelIndexerSuite extends FunSuite with MLlibTestSparkContext {
2626
private var sqlContext: SQLContext = _
@@ -32,7 +32,7 @@ class LabelIndexerSuite extends FunSuite with MLlibTestSparkContext {
3232

3333
test("LabelIndexer") {
3434
val data = sc.parallelize(Seq((0, "a"), (1, "b"), (2, "c"), (3, "a"), (4, "a"), (5, "c")), 2)
35-
val df = sqlContext.createDataFrame(data).toDF("id", "label")
35+
val df = sqlContext.createDataFrame(data).toDF("id", "label")
3636
val indexer = new LabelIndexer()
3737
.setOutputCol("labelIndex")
3838
.fit(df)

0 commit comments

Comments
 (0)