Skip to content

Commit

Permalink
drop tmp col from OneVsRest output
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxr committed Jun 2, 2015
1 parent ad06727 commit 6ee70de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ final class OneVsRestModel private[ml] (
// output label and label metadata as prediction
val labelUdf = callUDF(label, DoubleType, col(accColName))
aggregatedDataset.withColumn($(predictionCol), labelUdf.as($(predictionCol), labelMetadata))
.drop(accColName)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

package org.apache.spark.ml.classification

import org.apache.spark.SparkFunSuite
import org.scalatest.FunSuite

import org.apache.spark.ml.attribute.NominalAttribute
import org.apache.spark.ml.util.MetadataUtils
import org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS
Expand All @@ -29,7 +30,7 @@ import org.apache.spark.mllib.util.TestingUtils._
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.DataFrame

class OneVsRestSuite extends SparkFunSuite with MLlibTestSparkContext {
class OneVsRestSuite extends FunSuite with MLlibTestSparkContext {

@transient var dataset: DataFrame = _
@transient var rdd: RDD[LabeledPoint] = _
Expand Down Expand Up @@ -93,6 +94,15 @@ class OneVsRestSuite extends SparkFunSuite with MLlibTestSparkContext {
val datasetWithLabelMetadata = dataset.select(labelWithMetadata, features)
ova.fit(datasetWithLabelMetadata)
}

test("SPARK-8049: OneVsRest shouldn't output temp columns") {
val logReg = new LogisticRegression()
.setMaxIter(1)
val ovr = new OneVsRest()
.setClassifier(logReg)
val output = ovr.fit(dataset).transform(dataset)
assert(output.schema.fieldNames.toSet === Set("label", "features", "prediction"))
}
}

private class MockLogisticRegression(uid: String) extends LogisticRegression(uid) {
Expand Down

0 comments on commit 6ee70de

Please sign in to comment.