Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
175b024
1
Parent(s):
ed5b70a
Add unit-test for all selection strategies
Browse files- test/test.py +15 -0
test/test.py
CHANGED
@@ -9,6 +9,7 @@ from pysr.sr import (
|
|
9 |
run_feature_selection,
|
10 |
_handle_feature_selection,
|
11 |
_csv_filename_to_pkl_filename,
|
|
|
12 |
)
|
13 |
from sklearn.utils.estimator_checks import check_estimator
|
14 |
import sympy
|
@@ -403,6 +404,20 @@ class TestBest(unittest.TestCase):
|
|
403 |
for f in [self.model.predict, self.equations_.iloc[-1]["lambda_format"]]:
|
404 |
np.testing.assert_almost_equal(f(X), y, decimal=3)
|
405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
407 |
class TestFeatureSelection(unittest.TestCase):
|
408 |
def setUp(self):
|
|
|
9 |
run_feature_selection,
|
10 |
_handle_feature_selection,
|
11 |
_csv_filename_to_pkl_filename,
|
12 |
+
idx_model_selection,
|
13 |
)
|
14 |
from sklearn.utils.estimator_checks import check_estimator
|
15 |
import sympy
|
|
|
404 |
for f in [self.model.predict, self.equations_.iloc[-1]["lambda_format"]]:
|
405 |
np.testing.assert_almost_equal(f(X), y, decimal=3)
|
406 |
|
407 |
+
def test_all_selection_strategies(self):
|
408 |
+
equations = pd.DataFrame(
|
409 |
+
dict(
|
410 |
+
loss=[1.0, 0.1, 0.01, 0.001 * 1.4, 0.001],
|
411 |
+
score=[0.5, 1.0, 0.5, 0.5, 0.3],
|
412 |
+
)
|
413 |
+
)
|
414 |
+
idx_accuracy = idx_model_selection(equations, "accuracy")
|
415 |
+
self.assertEqual(idx_accuracy, 4)
|
416 |
+
idx_best = idx_model_selection(equations, "best")
|
417 |
+
self.assertEqual(idx_best, 3)
|
418 |
+
idx_score = idx_model_selection(equations, "score")
|
419 |
+
self.assertEqual(idx_score, 1)
|
420 |
+
|
421 |
|
422 |
class TestFeatureSelection(unittest.TestCase):
|
423 |
def setUp(self):
|