Skip to content

Commit

Permalink
revert changes for PR creation
Browse files Browse the repository at this point in the history
refine test cases

relax tolerance from 1e-4 to 1e-3 for comparing intercept_ when standardization is true in test_compat

relax tolerance for the second place comparing intercept
  • Loading branch information
lijinf2 committed Dec 10, 2024
1 parent f35ed2a commit 3593202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions python/tests/test_logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,12 @@ def to_sparse_func(v: Union[SparseVector, DenseVector]) -> SparseVector:


@pytest.mark.compat
#@pytest.mark.parametrize("fit_intercept", [True, False])
@pytest.mark.parametrize("fit_intercept", [False])
#@pytest.mark.parametrize("standardization", [True, False])
@pytest.mark.parametrize("standardization", [True])
@pytest.mark.parametrize("fit_intercept", [True, False])
@pytest.mark.parametrize("standardization", [True, False])
@pytest.mark.parametrize(
"lr_types",
[
#(SparkLogisticRegression, SparkLogisticRegressionModel),
(SparkLogisticRegression, SparkLogisticRegressionModel),
(LogisticRegression, LogisticRegressionModel),
],
)
Expand Down Expand Up @@ -545,7 +543,7 @@ def test_compat(

assert _LogisticRegression().getRegParam() == 0.0
blor = _LogisticRegression(
verbose=True, regParam=0.1, fitIntercept=fit_intercept, standardization=standardization
regParam=0.1, fitIntercept=fit_intercept, standardization=standardization
)

assert blor.getRegParam() == 0.1
Expand Down Expand Up @@ -582,7 +580,7 @@ def test_compat(
else [-2.42377087, 2.42377087]
)
assert array_equal(blor_model.coefficients.toArray(), coef_gnd, tolerance)
assert blor_model.intercept == pytest.approx(0, abs=1e-4)
assert blor_model.intercept == pytest.approx(0, abs=tolerance)

assert isinstance(blor_model.coefficientMatrix, DenseMatrix)
assert array_equal(
Expand All @@ -591,7 +589,7 @@ def test_compat(
tolerance,
)
assert isinstance(blor_model.interceptVector, DenseVector)
assert array_equal(blor_model.interceptVector.toArray(), [0.0])
assert array_equal(blor_model.interceptVector.toArray(), [0.0], tolerance)

example = bdf.head()
if example:
Expand Down Expand Up @@ -2240,10 +2238,10 @@ def test_sparse_all_zeroes(

with CleanSparkSession() as spark:
data = [
Row(label=1.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=1.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=0.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=0.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=1.0, features=Vectors.sparse(2, {})),
Row(label=1.0, features=Vectors.sparse(2, {})),
Row(label=0.0, features=Vectors.sparse(2, {})),
Row(label=0.0, features=Vectors.sparse(2, {})),
]

bdf = spark.createDataFrame(data)
Expand Down Expand Up @@ -2283,10 +2281,10 @@ def test_sparse_one_gpu_all_zeroes(

with CleanSparkSession() as spark:
data = [
Row(label=1.0, weight=1.0, features=Vectors.sparse(2, {0: 10.0, 1: 20.0})),
Row(label=1.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=0.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=0.0, weight=1.0, features=Vectors.sparse(2, {})),
Row(label=1.0, features=Vectors.sparse(2, {0: 10.0, 1: 20.0})),
Row(label=1.0, features=Vectors.sparse(2, {})),
Row(label=0.0, features=Vectors.sparse(2, {})),
Row(label=0.0, features=Vectors.sparse(2, {})),
]

bdf = spark.createDataFrame(data)
Expand Down
2 changes: 1 addition & 1 deletion python/tests_large/test_large_logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def test_sparse_int64(multi_gpus: bool = False) -> None:
"""
This test requires minimum 256G CPU memory, 32 GB GPU memory
This test requires minimum 128G CPU memory, 32 GB GPU memory
TODO: move generated dataset to a unified place
"""
gpu_number = 2 if multi_gpus else 1
Expand Down

0 comments on commit 3593202

Please sign in to comment.