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

[SPARK-23091][ML] Incorrect unit test for approxQuantile #20324

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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 @@ -154,24 +154,24 @@ class DataFrameStatSuite extends QueryTest with SharedSQLContext {
val Array(d1, d2) = df.stat.approxQuantile("doubles", Array(q1, q2), epsilon)
val Array(s1, s2) = df.stat.approxQuantile("singles", Array(q1, q2), epsilon)

val error_single = 2 * 1000 * epsilon
val error_double = 2 * 2000 * epsilon
val errorSingle = 1000 * epsilon
val errorDouble = 2.0 * errorSingle

assert(math.abs(single1 - q1 * n) < error_single)
assert(math.abs(double2 - 2 * q2 * n) < error_double)
assert(math.abs(s1 - q1 * n) < error_single)
assert(math.abs(s2 - q2 * n) < error_single)
assert(math.abs(d1 - 2 * q1 * n) < error_double)
assert(math.abs(d2 - 2 * q2 * n) < error_double)
assert(math.abs(single1 - q1 * n) < errorSingle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the intervals are inclusive, so this might be <= instead of <?

assert(math.abs(double2 - 2 * q2 * n) < errorDouble)
assert(math.abs(s1 - q1 * n) < errorSingle)
assert(math.abs(s2 - q2 * n) < errorSingle)
assert(math.abs(d1 - 2 * q1 * n) < errorDouble)
assert(math.abs(d2 - 2 * q2 * n) < errorDouble)

// Multiple columns
val Array(Array(ms1, ms2), Array(md1, md2)) =
df.stat.approxQuantile(Array("singles", "doubles"), Array(q1, q2), epsilon)

assert(math.abs(ms1 - q1 * n) < error_single)
assert(math.abs(ms2 - q2 * n) < error_single)
assert(math.abs(md1 - 2 * q1 * n) < error_double)
assert(math.abs(md2 - 2 * q2 * n) < error_double)
assert(math.abs(ms1 - q1 * n) < errorSingle)
assert(math.abs(ms2 - q2 * n) < errorSingle)
assert(math.abs(md1 - 2 * q1 * n) < errorDouble)
assert(math.abs(md2 - 2 * q2 * n) < errorDouble)
}

// quantile should be in the range [0.0, 1.0]
Expand Down