Skip to content

Commit

Permalink
LibSVMRelation is registered into META-INF
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewuathe committed Sep 7, 2015
1 parent 4f40891 commit 0ea1c1c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ private[ml] class LibSVMRelation(val path: String, val numFeatures: Int, val vec

}

/**
* This is used for creating DataFrame from LibSVM format file.
* The LibSVM file path must be specified to DefaultSource.
*/
class DefaultSource extends RelationProvider with DataSourceRegister {

override def shortName(): String = "libsvm"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void tearDown() {

@Test
public void verifyLibSVMDF() {
dataset = jsql.read().format("org.apache.spark.ml.source.libsvm").option("vectorType", "dense")
.load(path.getPath());
dataset = jsql.read().format("libsvm").option("vectorType", "dense").load(path.getPath());
Assert.assertEquals("label", dataset.columns()[0]);
Assert.assertEquals("features", dataset.columns()[1]);
Row r = dataset.first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LibSVMRelationSuite extends SparkFunSuite with MLlibTestSparkContext {
}

test("select as sparse vector") {
val df = sqlContext.read.libsvm(path)
val df = sqlContext.read.format("libsvm").load(path)
assert(df.columns(0) == "label")
assert(df.columns(1) == "features")
val row1 = df.first()
Expand All @@ -55,8 +55,8 @@ class LibSVMRelationSuite extends SparkFunSuite with MLlibTestSparkContext {
}

test("select as dense vector") {
val df = sqlContext.read.options(Map("vectorType" -> "dense"))
.libsvm(path)
val df = sqlContext.read.format("libsvm").options(Map("vectorType" -> "dense"))
.load(path)
assert(df.columns(0) == "label")
assert(df.columns(1) == "features")
assert(df.count() == 3)
Expand All @@ -75,7 +75,8 @@ class LibSVMRelationSuite extends SparkFunSuite with MLlibTestSparkContext {
val tempDir = Utils.createTempDir()
val file = new File(tempDir.getPath, "part-00001")
Files.write(lines, file, Charsets.US_ASCII)
val df = sqlContext.read.option("numFeatures", "100").libsvm(tempDir.toURI.toString)
val df = sqlContext.read.option("numFeatures", "100").format("libsvm")
.load(tempDir.toURI.toString)
val row1 = df.first()
val v = row1.getAs[SparseVector](1)
assert(v == Vectors.sparse(100, Seq((0, 1.0), (9, 2.0), (19, 3.0), (29, 4.0), (39, 5.0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.apache.spark.sql.execution.datasources.jdbc.DefaultSource
org.apache.spark.sql.execution.datasources.json.DefaultSource
org.apache.spark.sql.execution.datasources.parquet.DefaultSource
org.apache.spark.ml.source.libsvm.DefaultSource

0 comments on commit 0ea1c1c

Please sign in to comment.