File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
mllib/src/main/scala/org/apache/spark/ml/optim Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -472,7 +472,8 @@ private[ml] object WeightedLeastSquares {
472472 while (i < triK) {
473473 val l = j - 2
474474 val aw = aSum(l) / wSum
475- std(l) = math.sqrt(aaValues(i) / wSum - aw * aw)
475+ // We prevent variance from negative value caused by numerical error.
476+ std(l) = math.sqrt(math.max(aaValues(i) / wSum - aw * aw, 0.0 ))
476477 i += j
477478 j += 1
478479 }
@@ -490,7 +491,8 @@ private[ml] object WeightedLeastSquares {
490491 while (i < triK) {
491492 val l = j - 2
492493 val aw = aSum(l) / wSum
493- variance(l) = aaValues(i) / wSum - aw * aw
494+ // We prevent variance from negative value caused by numerical error.
495+ variance(l) = math.max(aaValues(i) / wSum - aw * aw, 0.0 )
494496 i += j
495497 j += 1
496498 }
You can’t perform that action at this time.
0 commit comments