-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-11207][ML] Add test cases for solver selection of LinearRegres… #9180
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
Changes from 1 commit
11cd9c1
28427d2
f85bca6
22ba64e
f6b2256
2082d47
003d3bd
0a43033
59383fd
888b216
c27a4c3
97c76c9
74de81e
241ec72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,26 +103,10 @@ object LinearDataGenerator { | |
| nPoints: Int, | ||
| seed: Int, | ||
| eps: Double): Seq[LabeledPoint] = { | ||
|
|
||
| val rnd = new Random(seed) | ||
| val x = Array.fill[Array[Double]](nPoints)( | ||
| Array.fill[Double](weights.length)(rnd.nextDouble())) | ||
|
|
||
| x.foreach { v => | ||
| var i = 0 | ||
| val len = v.length | ||
| while (i < len) { | ||
| v(i) = (v(i) - 0.5) * math.sqrt(12.0 * xVariance(i)) + xMean(i) | ||
| i += 1 | ||
| } | ||
| } | ||
|
|
||
| val y = x.map { xi => | ||
| blas.ddot(weights.length, xi, 1, weights, 1) + intercept + eps * rnd.nextGaussian() | ||
| } | ||
| y.zip(x).map(p => LabeledPoint(p._1, Vectors.dense(p._2))) | ||
| generateLinearInputInternal(intercept, weights, xMean, xVariance, nPoints, seed, eps, 0.0) | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @param intercept Data intercept | ||
| * @param weights Weights to be applied. | ||
|
|
@@ -133,10 +117,12 @@ object LinearDataGenerator { | |
| * @param nPoints Number of points in sample. | ||
| * @param seed Random seed | ||
| * @param eps Epsilon scaling factor. | ||
| * @return Seq of LabeledPoint includes sparse vectors.. | ||
| * @param sparcity The ratio of zero elements. If it is 0.0, LabeledPoints with | ||
| * DenseVector is returned. | ||
| * @return Seq of input. | ||
| */ | ||
|
Member
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. How about consolidate with
Contributor
Author
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. Yes, I also thought it is good idea. But
Member
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. Let's modify the JIRA and do it here. Basically, you can create a |
||
| @Since("1.6.0") | ||
| def generateLinearSparseInput( | ||
| def generateLinearInputInternal( | ||
|
Member
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. Just call it |
||
| intercept: Double, | ||
| weights: Array[Double], | ||
| xMean: Array[Double], | ||
|
|
@@ -168,13 +154,19 @@ object LinearDataGenerator { | |
| } | ||
|
|
||
|
Member
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. To simplify the following code, do y.zip(x).map { p =>
if (sparsity == 0.0) {
LabeledPoint(p._1, Vectors.dense(p._2))
} else {
LabeledPoint(p._1, Vectors.dense(p._2).toSparse)
}
} |
||
| val sparseX = x.map { (v: Array[Double]) => | ||
| v.zipWithIndex.filter{ | ||
| v.zipWithIndex.filter { | ||
| case (d: Double, i: Int) => d != 0.0 | ||
| }.map { | ||
| case (d: Double, i: Int) => (i, d) | ||
| } | ||
| } | ||
| y.zip(sparseX).map(p => LabeledPoint(p._1, Vectors.sparse(weights.length, p._2))) | ||
| if (sparcity == 0.0) { | ||
| // Return LabeledPoints with DenseVector | ||
| y.zip(x).map(p => LabeledPoint(p._1, Vectors.dense(p._2))) | ||
| } else { | ||
| // Return LabeledPoints with SparseVector | ||
| y.zip(sparseX).map(p => LabeledPoint(p._1, Vectors.sparse(weights.length, p._2))) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Typo:
sparsity