Skip to content

Commit

Permalink
Fix ModelInsightsTest flakiness due to coefficients turning negative (
Browse files Browse the repository at this point in the history
#407)

Take absolute value when calculating ratio of difference between scaled and descaled coefficient
  • Loading branch information
TuanNguyen27 authored and gerashegalov committed Sep 12, 2019
1 parent 0759cb5 commit 0235f26
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/test/scala/com/salesforce/op/ModelInsightsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,9 @@ class ModelInsightsTest extends FlatSpec with PassengerSparkFixtureTest with Dou
val descaledbigCoeff = coeffs(2)
val orginalbigCoeff = coeffs(3)
val absError = math.abs(orginalbigCoeff * math.sqrt(smallFeatureVariance) / labelStd - descaledbigCoeff)
val bigCoeffSum = orginalbigCoeff * math.sqrt(smallFeatureVariance) / labelStd + descaledbigCoeff
val bigCoeffSum = math.abs(orginalbigCoeff * math.sqrt(smallFeatureVariance) / labelStd + descaledbigCoeff)
val absError2 = math.abs(originalsmallCoeff * math.sqrt(bigFeatureVariance) / labelStd - descaledsmallCoeff)
val smallCoeffSum = originalsmallCoeff * math.sqrt(bigFeatureVariance) / labelStd + descaledsmallCoeff
val smallCoeffSum = math.abs(originalsmallCoeff * math.sqrt(bigFeatureVariance) / labelStd + descaledsmallCoeff)
absError should be < tol * bigCoeffSum / 2
absError2 should be < tol * smallCoeffSum / 2
}
Expand All @@ -770,9 +770,9 @@ class ModelInsightsTest extends FlatSpec with PassengerSparkFixtureTest with Dou
val orginalbigCoeff = coeffs(3)
// difference between the real coefficient and the analytical formula
val absError = math.abs(orginalbigCoeff * math.sqrt(smallFeatureVariance) - descaledbigCoeff)
val bigCoeffSum = orginalbigCoeff * math.sqrt(smallFeatureVariance) + descaledbigCoeff
val bigCoeffSum = math.abs(orginalbigCoeff * math.sqrt(smallFeatureVariance) + descaledbigCoeff)
val absError2 = math.abs(originalsmallCoeff * math.sqrt(mediumFeatureVariance) - descaledsmallCoeff)
val smallCoeffSum = originalsmallCoeff * math.sqrt(mediumFeatureVariance) + descaledsmallCoeff
val smallCoeffSum = math.abs(originalsmallCoeff * math.sqrt(mediumFeatureVariance) + descaledsmallCoeff)
absError should be < tol * bigCoeffSum / 2
absError2 should be < tol * smallCoeffSum / 2
}
Expand Down

0 comments on commit 0235f26

Please sign in to comment.