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

FIX: incremental estimators tests #1998

Merged
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
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
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