Skip to content

Commit 52fd3e2

Browse files
committed
update breeze test
1 parent 04f8cfd commit 52fd3e2

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/main/scala/com/hyzs/spark/ml/MatrixOpsInSpark.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.apache.spark.ml.classification.{BinaryLogisticRegressionSummary, Logi
1414
*/
1515
object MatrixOpsInSpark {
1616

17+
import spark.implicits._
1718

1819
def importDataset(): Unit ={
1920
val data: Dataset[Row] = spark.read
@@ -62,6 +63,8 @@ object MatrixOpsInSpark {
6263
println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}")
6364

6465
val trainingSummary = lrModel.summary
66+
println(s"training summary objectiveHistory: ${trainingSummary.objectiveHistory.mkString(",")}")
67+
println(s"training summary totalIterations: ${trainingSummary.totalIterations}")
6568
val binarySummary = trainingSummary.asInstanceOf[BinaryLogisticRegressionSummary]
6669
val roc = binarySummary.roc
6770
roc.show()

src/main/scala/com/hyzs/spark/utils/SparkUtils.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ object SparkUtils {
3737
// NOTE: not serializable, cannot initialize class.
3838
//mapper.registerModule(DefaultScalaModule)
3939
val broadMapper: Broadcast[ObjectMapper] = sc.broadcast(mapper)
40-
import spark.implicits._
41-
import spark.sqlContext.implicits._
4240

4341
def checkHDFileExist(filePath: String): Boolean = {
4442
val path = new Path(filePath)

src/test/scala/BreezeTest.scala

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import org.scalatest.FunSuite
2+
3+
/**
4+
* Created by xk on 2018/6/1.
5+
*/
6+
7+
import breeze.linalg._
8+
import breeze.numerics._
9+
import breeze.stats.distributions._
10+
import breeze.stats.DescriptiveStats._
11+
import breeze.stats._
12+
13+
class BreezeTest extends FunSuite{
14+
15+
16+
17+
test("test breeze algebra"){
18+
val v1 = DenseVector.zeros[Double](5)
19+
println(v1)
20+
v1(1 to 2) := .5
21+
println(v1)
22+
v1(0 to 1) := DenseVector(.1,.2)
23+
println(v1)
24+
val m = DenseMatrix.zeros[Int](5,5)
25+
26+
val v2 = DenseVector(.1, .2, .3, .4, .5)
27+
val m2 = DenseMatrix(v1, v2)
28+
m2(0 to 1, 0 to 2) := DenseMatrix((1.1,1.2,1.3),(2.1,2.2,2.3))
29+
30+
}
31+
32+
test("test distribution"){
33+
val gaussian = Gaussian(0.0, 1.0)
34+
val g_samples = gaussian.sample(100)
35+
println(mean(g_samples))
36+
println(meanAndVariance(g_samples))
37+
println(stddev(g_samples))
38+
val poi = Poisson(3.0)
39+
val p_sample = poi.sample(50)
40+
println(p_sample)
41+
42+
val gau_matrix = new DenseMatrix(100, 10, gaussian.sample(1000).toArray)
43+
println(gau_matrix)
44+
}
45+
46+
47+
}

0 commit comments

Comments
 (0)