Skip to content
Snippets Groups Projects
Commit 82870d50 authored by Xiangrui Meng's avatar Xiangrui Meng Committed by DB Tsai
Browse files

[SPARK-8168] [MLLIB] Add Python friendly constructor to PipelineModel

This makes the constructor callable in Python. dbtsai

Author: Xiangrui Meng <meng@databricks.com>

Closes #6709 from mengxr/SPARK-8168 and squashes the following commits:

f871de4 [Xiangrui Meng] Add Python friendly constructor to PipelineModel
parent f3eec92c
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,9 @@
package org.apache.spark.ml
import java.{util => ju}
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
import org.apache.spark.Logging
......@@ -175,6 +178,11 @@ class PipelineModel private[ml] (
val stages: Array[Transformer])
extends Model[PipelineModel] with Logging {
/** A Java/Python-friendly auxiliary constructor. */
private[ml] def this(uid: String, stages: ju.List[Transformer]) = {
this(uid, stages.asScala.toArray)
}
override def validateParams(): Unit = {
super.validateParams()
stages.foreach(_.validateParams())
......
......@@ -17,6 +17,8 @@
package org.apache.spark.ml
import scala.collection.JavaConverters._
import org.mockito.Matchers.{any, eq => meq}
import org.mockito.Mockito.when
import org.scalatest.mock.MockitoSugar.mock
......@@ -81,4 +83,19 @@ class PipelineSuite extends SparkFunSuite {
pipeline.fit(dataset)
}
}
test("pipeline model constructors") {
val transform0 = mock[Transformer]
val model1 = mock[MyModel]
val stages = Array(transform0, model1)
val pipelineModel0 = new PipelineModel("pipeline0", stages)
assert(pipelineModel0.uid === "pipeline0")
assert(pipelineModel0.stages === stages)
val stagesAsList = stages.toList.asJava
val pipelineModel1 = new PipelineModel("pipeline1", stagesAsList)
assert(pipelineModel1.uid === "pipeline1")
assert(pipelineModel1.stages === stages)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment