-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML-177][Native Bayes] Fix error when converting Vector to CSRNumericTable #176
Changes from 6 commits
3ab3707
38243f1
28d82dd
80236dc
1369d8a
6beba07
bd99520
b93f682
f9d184b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.apache.spark.ml | ||
|
||
import com.intel.oap.mllib.OneDAL | ||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.ml.linalg.{Matrices, Vector, Vectors} | ||
import org.apache.spark.sql.Row | ||
|
||
class oneDALSuite extends FunctionsSuite with Logging { | ||
|
||
import testImplicits._ | ||
|
||
test("test sparse vector to CSRNumericTable") { | ||
val data = Seq( | ||
Vectors.sparse(3, Seq((0, 1.0), (1, 2.0), (2, 3.0))), | ||
Vectors.sparse(3, Seq((0, 10.0), (1, 20.0), (2, 30.0))), | ||
Vectors.sparse(3, Seq.empty), | ||
Vectors.sparse(3, Seq.empty), | ||
Vectors.sparse(3, Seq((0, 1.0), (1, 2.0))), | ||
Vectors.sparse(3, Seq((0, 10.0), (2, 20.0))), | ||
) | ||
val df = data.map(Tuple1.apply).toDF("features") | ||
df.show() | ||
val rowsRDD = df.rdd.map { | ||
case Row(features: Vector) => features | ||
} | ||
val results = rowsRDD.coalesce(1).mapPartitions { it: Iterator[Vector] => | ||
val vectors: Array[Vector] = it.toArray | ||
val numColumns = vectors(0).size | ||
val CSRNumericTable = { | ||
OneDAL.vectorsToSparseNumericTable(vectors, numColumns) | ||
} | ||
Iterator(CSRNumericTable.getCNumericTable) | ||
}.collect() | ||
val csr = OneDAL.makeNumericTable(results(0)) | ||
val resultMatrix = OneDAL.numericTableToMatrix(csr) | ||
val matrix = Matrices.fromVectors(data) | ||
|
||
assert((resultMatrix.toArray sameElements matrix.toArray) === true) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,8 @@ suiteArray=( | |
"classification.MLlibNaiveBayesSuite" \ | ||
"regression.MLlibLinearRegressionSuite" \ | ||
"stat.MLlibCorrelationSuite" \ | ||
"stat.MultivariateOnlineSummarizerSuite" | ||
"stat.MultivariateOnlineSummarizerSuite" \ | ||
"oneDALSuite" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you put oneDALSuite in com.intel.oap.mllib namespace to align with oneDAL.scala There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, thanks! |
||
) | ||
|
||
MVN_NO_TRANSFER_PROGRESS= | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls correct code indent