Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mllib/src/main/scala/org/apache/spark/ml/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Pipeline @Since("1.4.0") (
override def copy(extra: ParamMap): Pipeline = {
val map = extractParamMap(extra)
val newStages = map(stages).map(_.copy(extra))
new Pipeline().setStages(newStages)
new Pipeline(uid).setStages(newStages)
}

@Since("1.2.0")
Expand Down
22 changes: 20 additions & 2 deletions mllib/src/test/scala/org/apache/spark/ml/PipelineSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,31 @@ class PipelineSuite extends SparkFunSuite with MLlibTestSparkContext with Defaul
}
}

test("Pipeline.copy") {
val hashingTF = new HashingTF()
.setNumFeatures(100)
val pipeline = new Pipeline("pipeline").setStages(Array[Transformer](hashingTF))
val copied = pipeline.copy(ParamMap(hashingTF.numFeatures -> 10))

assert(copied.uid === pipeline.uid,
"copy should create an instance with the same UID")
assert(copied.getStages(0).asInstanceOf[HashingTF].getNumFeatures === 10,
"copy should handle extra stage params")
}

test("PipelineModel.copy") {
val hashingTF = new HashingTF()
.setNumFeatures(100)
val model = new PipelineModel("pipeline", Array[Transformer](hashingTF))
val model = new PipelineModel("pipelineModel", Array[Transformer](hashingTF))
.setParent(new Pipeline())
val copied = model.copy(ParamMap(hashingTF.numFeatures -> 10))
require(copied.stages(0).asInstanceOf[HashingTF].getNumFeatures === 10,

assert(copied.uid === model.uid,
"copy should create an instance with the same UID")
assert(copied.stages(0).asInstanceOf[HashingTF].getNumFeatures === 10,
"copy should handle extra stage params")
assert(copied.parent === model.parent,
"copy should create an instance with the same parent")
}

test("pipeline model constructors") {
Expand Down