You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by jk...@apache.org on 2015/08/14 20:22:14 UTC
spark git commit: [SPARK-8744] [ML] Add a public constructor to
StringIndexer
Repository: spark
Updated Branches:
refs/heads/master 7ecf0c469 -> a7317ccdc
[SPARK-8744] [ML] Add a public constructor to StringIndexer
It would be helpful to allow users to pass a pre-computed index to create an indexer, rather than always going through StringIndexer to create the model.
Author: Holden Karau <ho...@pigscanfly.ca>
Closes #7267 from holdenk/SPARK-8744-StringIndexerModel-should-have-public-constructor.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/a7317ccd
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/a7317ccd
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/a7317ccd
Branch: refs/heads/master
Commit: a7317ccdc20d001e5b7f5277b0535923468bfbc6
Parents: 7ecf0c4
Author: Holden Karau <ho...@pigscanfly.ca>
Authored: Fri Aug 14 11:22:10 2015 -0700
Committer: Joseph K. Bradley <jo...@databricks.com>
Committed: Fri Aug 14 11:22:10 2015 -0700
----------------------------------------------------------------------
.../main/scala/org/apache/spark/ml/feature/StringIndexer.scala | 4 +++-
.../scala/org/apache/spark/ml/feature/StringIndexerSuite.scala | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/a7317ccd/mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala
----------------------------------------------------------------------
diff --git a/mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala b/mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala
index 9f6e7b6..6347578 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala
@@ -102,10 +102,12 @@ class StringIndexer(override val uid: String) extends Estimator[StringIndexerMod
* This is a temporary fix for the case when target labels do not exist during prediction.
*/
@Experimental
-class StringIndexerModel private[ml] (
+class StringIndexerModel (
override val uid: String,
labels: Array[String]) extends Model[StringIndexerModel] with StringIndexerBase {
+ def this(labels: Array[String]) = this(Identifiable.randomUID("strIdx"), labels)
+
private val labelToIndex: OpenHashMap[String, Double] = {
val n = labels.length
val map = new OpenHashMap[String, Double](n)
http://git-wip-us.apache.org/repos/asf/spark/blob/a7317ccd/mllib/src/test/scala/org/apache/spark/ml/feature/StringIndexerSuite.scala
----------------------------------------------------------------------
diff --git a/mllib/src/test/scala/org/apache/spark/ml/feature/StringIndexerSuite.scala b/mllib/src/test/scala/org/apache/spark/ml/feature/StringIndexerSuite.scala
index fa918ce..0b4c8ba 100644
--- a/mllib/src/test/scala/org/apache/spark/ml/feature/StringIndexerSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/ml/feature/StringIndexerSuite.scala
@@ -30,7 +30,9 @@ class StringIndexerSuite extends SparkFunSuite with MLlibTestSparkContext {
test("params") {
ParamsSuite.checkParams(new StringIndexer)
val model = new StringIndexerModel("indexer", Array("a", "b"))
+ val modelWithoutUid = new StringIndexerModel(Array("a", "b"))
ParamsSuite.checkParams(model)
+ ParamsSuite.checkParams(modelWithoutUid)
}
test("StringIndexer") {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org