Skip to content

Commit

Permalink
Update tests due to differences in Py 310 and newer Py versions
Browse files Browse the repository at this point in the history
  • Loading branch information
niklases committed Oct 30, 2024
1 parent 4d8a0b8 commit 562118f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pypef/utils/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sklearnex import patch_sklearn
patch_sklearn(verbose=False)
from sklearn.metrics import (
mean_squared_error, r2_score,
root_mean_squared_error, r2_score,
precision_score, accuracy_score, recall_score,
balanced_accuracy_score, f1_score, matthews_corrcoef,
average_precision_score, roc_curve, auc
Expand Down Expand Up @@ -54,7 +54,7 @@ def get_performances(
y_true = list(y_true)
y_pred = list(y_pred)
r_squared = r2_score(y_true, y_pred)
rmse = np.sqrt(mean_squared_error(y_true, y_pred))
rmse = root_mean_squared_error(y_true, y_pred)
stddev = np.std(y_true, ddof=1)
nrmse = rmse / stddev
with warnings.catch_warnings(): # catching RunTime warning when there's no variance in an array,
Expand Down
11 changes: 8 additions & 3 deletions tests/test_api_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def test_gremlin():


def test_dataset_b_results():
train_seqs, train_vars, train_ys = get_sequences_from_file(ls_b)
test_seqs, test_vars, test_ys = get_sequences_from_file(ts_b)
train_seqs, _train_vars, train_ys = get_sequences_from_file(ls_b)
test_seqs, _test_vars, test_ys = get_sequences_from_file(ts_b)
aaindex = "WOLR810101.txt"
x_fft_train, _ = AAIndexEncoding(full_aaidx_txt_path(aaindex), train_seqs).collect_encoded_sequences()
x_fft_test, _ = AAIndexEncoding(full_aaidx_txt_path(aaindex), test_seqs).collect_encoded_sequences()
Expand All @@ -58,4 +58,9 @@ def test_dataset_b_results():
regressor='pls_loocv'
)
# Dataset B PLS_LOOCV results: R², RMSE, NRMSE, Pearson's r, Spearman's rho
np.testing.assert_almost_equal(performances[:5], [0.72, 14.48, 0.52, 0.86, 0.89], decimal=2)
# RMSE, in Python 3.10 14.669 and from Python 3.11 on 14.17:
np.testing.assert_almost_equal(performances[1], 14.48, decimal=0)
# R²
np.testing.assert_almost_equal(performances[0], 0.72, decimal=2)
# NRMSE, Pearson's r, Spearman's rho
np.testing.assert_almost_equal(performances[2:5], [0.52, 0.86, 0.89], decimal=2)

0 comments on commit 562118f

Please sign in to comment.