Skip to content
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

Make tests a little less flaky #221

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ class OpMultiClassificationEvaluatorTest extends FlatSpec with TestSparkContext

it should "work on randomly generated probabilities" in {
val numClasses = 100
val numRows = 10000

val vectors = RandomVector.dense(RandomReal.uniform[Real](0.0, 1.0), numClasses).limit(numRows)
val vectors = RandomVector.dense(RandomReal.uniform[Real](0.0, 1.0), numClasses).limit(numRows.toInt)
val probVectors = vectors.map(v => {
val expArray = v.value.toArray.map(math.exp)
val denom = expArray.sum
Expand All @@ -144,7 +143,7 @@ class OpMultiClassificationEvaluatorTest extends FlatSpec with TestSparkContext
Prediction(prediction = prob.v.argmax.toDouble, rawPrediction = raw.v.toArray, probability = prob.v.toArray)
}

val labels = RandomIntegral.integrals(from = 0, to = numClasses).limit(numRows)
val labels = RandomIntegral.integrals(from = 0, to = numClasses).limit(numRows.toInt)
.map(x => x.value.get.toDouble.toRealNN)

val generatedData: Seq[(RealNN, Prediction)] = labels.zip(predictions)
Expand Down Expand Up @@ -176,12 +175,11 @@ class OpMultiClassificationEvaluatorTest extends FlatSpec with TestSparkContext

it should "work on probability vectors where there are many ties (low unique score cardinality)" in {
val numClasses = 200
val numRows = 1000
val correctProb = 0.3

// Try and make the score one large number for a random class, and equal & small probabilities for all other ones
val truePredIndex = math.floor(math.random * numClasses).toInt
val vectors = Seq.fill[OPVector](numRows){
val vectors = Seq.fill[OPVector](numRows.toInt){
val truePredIndex = math.floor(math.random * numClasses).toInt
val myVector = Array.fill(numClasses)(1e-10)
myVector.update(truePredIndex, 4.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class RecordInsightsLOCOTest extends FlatSpec with TestSparkContext {

// Compare the ratio of importances between "important" and "other" features in both paradigms
assert(math.abs(avgRecordInsightRatio - featureImportanceRatio)*2 /
(avgRecordInsightRatio + featureImportanceRatio) < 0.5, "The ratio of feature strengths between important and" +
(avgRecordInsightRatio + featureImportanceRatio) < 0.8, "The ratio of feature strengths between important and" +
"other features should be similar to the ratio of feature importances from Spark's RandomForest")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class RegressionModelSelectorTest extends FlatSpec with TestSparkContext
val testCount = test.count()
val totalCount = rawData.length

assert(math.abs(testCount - 0.2 * totalCount) <= 10)
assert(math.abs(trainCount - 0.8 * totalCount) <= 10)
assert(math.abs(testCount - 0.2 * totalCount) <= 15)
assert(math.abs(trainCount - 0.8 * totalCount) <= 15)

trainCount + testCount shouldBe totalCount
}
Expand Down