Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update PCA test case
  • Loading branch information
yanboliang committed Nov 19, 2015
commit ec969de60592a92fdb7f7338f7b74d7e144732fe
21 changes: 7 additions & 14 deletions mllib/src/test/scala/org/apache/spark/ml/feature/PCASuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,23 @@ class PCASuite extends SparkFunSuite with MLlibTestSparkContext with DefaultRead
}
}

test("PCA read/write") {
val t = new PCA()
.setInputCol("myInputCol")
.setOutputCol("myOutputCol")
.setK(3)
testDefaultReadWrite(t)
}

test("PCAModel read/write") {
test("read/write") {

def checkModelData(model1: PCAModel, model2: PCAModel): Unit = {
assert(model1.pc === model2.pc)
}

val allParams: Map[String, Any] = Map(
"k" -> 3,
"inputCol" -> "features",
"outputCol" -> "pca_features"
)
val data = Seq(
(0.0, Vectors.sparse(5, Seq((1, 1.0), (3, 7.0)))),
(1.0, Vectors.dense(2.0, 0.0, 3.0, 4.0, 5.0)),
(2.0, Vectors.dense(4.0, 0.0, 0.0, 6.0, 7.0))
)
val df = sqlContext.createDataFrame(data).toDF("id", "features")
val pca = new PCA().setK(3)
val testParams: Map[String, Any] = Map("k" -> 3, "inputCol" -> "features",
"outputCol" -> "pca_features")

testEstimatorAndModelReadWrite(pca, df, testParams, checkModelData)
testEstimatorAndModelReadWrite(pca, df, allParams, checkModelData)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as StandardScalerModel, we can not construct PCAModel directly by specifying the variable k, so test estimator and model in one case with testEstimatorAndModelReadWrite.