-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from MadDataScience/master
Fix SimpleIndexer fit method to set inputCol and outputCol correctly
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/scala/com/high-performance-spark-examples/ml/CustomPipeline.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Simple tests for our CustomPipeline demo pipeline stage | ||
*/ | ||
package com.highperformancespark.examples.ml | ||
|
||
import com.holdenkarau.spark.testing.DataFrameSuiteBase | ||
import org.apache.spark.sql.Dataset | ||
import org.scalatest.FunSuite | ||
|
||
case class TestRow(id: Int, inputColumn: String) | ||
|
||
class CustomPipelineSuite extends FunSuite with DataFrameSuiteBase { | ||
val d = List( | ||
TestRow(0, "a"), | ||
TestRow(1, "b"), | ||
TestRow(2, "c"), | ||
TestRow(3, "a"), | ||
TestRow(4, "a"), | ||
TestRow(5, "c") | ||
) | ||
|
||
test("test spark context") { | ||
val session = spark | ||
val rdd = session.sparkContext.parallelize(1 to 10) | ||
assert(rdd.sum === 55) | ||
} | ||
|
||
test("simple indexer test") { | ||
val session = spark | ||
import session.implicits._ | ||
val ds: Dataset[TestRow] = session.createDataset(d) | ||
val indexer = new SimpleIndexer() | ||
indexer.setInputCol("inputColumn") | ||
indexer.setOutputCol("categoryIndex") | ||
val model = indexer.fit(ds) | ||
val predicted = model.transform(ds) | ||
assert(predicted.columns.contains("categoryIndex")) | ||
predicted.show() | ||
} | ||
} |