Skip to content

Commit

Permalink
FIX: incremental estimators tests (#1998) (#2021)
Browse files Browse the repository at this point in the history
* FIX: incremental  estimators tests

(cherry picked from commit 4fd4568)

Co-authored-by: Samir Nasibli <[email protected]>
  • Loading branch information
mergify[bot] and samir-nasibli authored Sep 2, 2024
1 parent 84666fa commit a205592
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions sklearnex/linear_model/tests/test_incremental_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ def test_sklearnex_fit_on_gold_data(dataframe, queue, fit_intercept, macro_block
inclin.fit(X_df, y_df)

y_pred = inclin.predict(X_df)
np_y_pred = _as_numpy(y_pred)

tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7
tol = 2e-6 if dtype == np.float32 else 1e-7
assert_allclose(inclin.coef_, [1], atol=tol)
if fit_intercept:
assert_allclose(inclin.intercept_, [0], atol=tol)
assert_allclose(_as_numpy(y_pred), y, atol=tol)
assert_allclose(np_y_pred, y, atol=tol)


@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
Expand Down Expand Up @@ -84,14 +85,15 @@ def test_sklearnex_partial_fit_on_gold_data(

X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
y_pred = inclin.predict(X_df)
np_y_pred = _as_numpy(y_pred)

assert inclin.n_features_in_ == 1
tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7
tol = 2e-6 if dtype == np.float32 else 1e-7
assert_allclose(inclin.coef_, [[1]], atol=tol)
if fit_intercept:
assert_allclose(inclin.intercept_, 3, atol=tol)

assert_allclose(_as_numpy(y_pred), y, atol=tol)
assert_allclose(np_y_pred, y, atol=tol)


@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
Expand Down Expand Up @@ -124,14 +126,15 @@ def test_sklearnex_partial_fit_multitarget_on_gold_data(

X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
y_pred = inclin.predict(X_df)
np_y_pred = _as_numpy(y_pred)

assert inclin.n_features_in_ == 2
tol = 7e-6 if y_pred.dtype == np.float32 else 1e-7
tol = 7e-6 if dtype == np.float32 else 1e-7
assert_allclose(inclin.coef_, [1.0, 2.0], atol=tol)
if fit_intercept:
assert_allclose(inclin.intercept_, 3.0, atol=tol)

assert_allclose(_as_numpy(y_pred), y, atol=tol)
assert_allclose(np_y_pred, y, atol=tol)


@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
Expand Down
4 changes: 2 additions & 2 deletions sklearnex/preview/decomposition/tests/test_incremental_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def check_pca_on_gold_data(incpca, dtype, whiten, transformed_data):
)

tol = 1e-7
if transformed_data.dtype == np.float32:
if dtype == np.float32:
tol = 7e-6 if whiten else 1e-6

assert incpca.n_samples_seen_ == expected_n_samples_seen_
Expand Down Expand Up @@ -112,7 +112,7 @@ def check_pca_on_gold_data(incpca, dtype, whiten, transformed_data):


def check_pca(incpca, dtype, whiten, data, transformed_data):
tol = 3e-3 if transformed_data.dtype == np.float32 else 2e-6
tol = 3e-3 if dtype == np.float32 else 2e-6

n_components = incpca.n_components_

Expand Down

0 comments on commit a205592

Please sign in to comment.