-
Notifications
You must be signed in to change notification settings - Fork 5
Improved GP fitness to use NRMSE #300
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ae844dd
Improved GP fitness to use NRMSE
jmafoster1 a85e6a1
black
jmafoster1 9111bda
pylint
jmafoster1 279f462
Removed debugging assertion
jmafoster1 ec079b4
Added extra tests to please codecov
jmafoster1 5066e4f
Another test
jmafoster1 262ec46
Modified the test
jmafoster1 9973f1f
assertEquals -> assertEqual
jmafoster1 4bc7607
Found a test input for the weird edge case
jmafoster1 8fb7224
assertEquals again
jmafoster1 b55c764
renamed test
jmafoster1 9bb78f1
Removed typo
jmafoster1 f22af96
More detailed comment
jmafoster1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/estimation_tests/test_genetic_programming_regression_fitter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,43 @@ | ||
import unittest | ||
import pandas as pd | ||
from operator import sub | ||
|
||
from causal_testing.estimation.genetic_programming_regression_fitter import GP | ||
|
||
|
||
def root(x): | ||
return x**0.5 | ||
|
||
|
||
class TestGP(unittest.TestCase): | ||
def test_init_invalid_fun_name(self): | ||
with self.assertRaises(ValueError): | ||
GP(df=pd.DataFrame(), features=[], outcome="", max_order=2, sympy_conversions={"power_1": ""}) | ||
|
||
def test_simplify_string(self): | ||
gp = GP( | ||
df=None, | ||
features=["x1"], | ||
outcome=None, | ||
max_order=1, | ||
) | ||
self.assertEqual(str(gp.simplify("power_1(x1)")), "x1") | ||
|
||
def test_fitness(self): | ||
gp = GP( | ||
df=pd.DataFrame({"x1": [1, 2, 3], "outcome": [2, 3, 4]}), | ||
features=["x1"], | ||
outcome="outcome", | ||
max_order=0, | ||
) | ||
self.assertEqual(gp.fitness("add(x1, 1)"), (0,)) | ||
|
||
def test_fitness_inf(self): | ||
gp = GP( | ||
df=pd.DataFrame({"x1": [1, 2, 3], "outcome": [2, 3, 4]}), | ||
features=["x1"], | ||
outcome="outcome", | ||
max_order=0, | ||
extra_operators=[(root, 1)], | ||
) | ||
self.assertEqual(gp.fitness("root(-1)"), (float("inf"),)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.