Skip to content

Fix the type of return value from R2 Score Evaluator #339

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 2 commits into from
Mar 11, 2019
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
4 changes: 2 additions & 2 deletions chainer_chemistry/training/extensions/r2_score_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ def r2_score(self, pred, true, sample_weight=None,
ret = xp.where(
SS_tot_iszero, 0.0, 1 - SS_res / SS_tot).astype(pred.dtype)
if self.multioutput == 'uniform_average':
return xp.asarray(ret.mean()),
return xp.asarray(ret.mean())
elif self.multioutput == 'raw_values':
return ret,
return ret
16 changes: 8 additions & 8 deletions tests/training_tests/extensions_tests/test_r2_score_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def _test_r2_score_evaluator(inputs):
observation = evaluator.evaluate()

expected = r2_score(x0, x1)
pytest.approx(observation['target/r2_score'][0], expected)
pytest.approx(observation['target/r2_score'], expected)

# --- test __call__ ---
result = evaluator()
pytest.approx(result['train/main/r2_score'][0], expected)
pytest.approx(result['train/main/r2_score'], expected)


def _test_r2_score_evaluator_ignore_nan(inputs):
Expand All @@ -114,11 +114,11 @@ def _test_r2_score_evaluator_ignore_nan(inputs):
observation = evaluator.evaluate()

expected = r2_score(x0, x2, ignore_nan=True)
pytest.approx(observation['target/r2_score'][0], expected)
pytest.approx(observation['target/r2_score'], expected)

# --- test __call__ ---
result = evaluator()
pytest.approx(result['train/main/r2_score'][0], expected)
pytest.approx(result['train/main/r2_score'], expected)


def _test_r2_score_evaluator_ignore_nan_with_nonnan_value(inputs):
Expand All @@ -135,11 +135,11 @@ def _test_r2_score_evaluator_ignore_nan_with_nonnan_value(inputs):
observation = evaluator.evaluate()

expected = r2_score(x0, x1, ignore_nan=True)
pytest.approx(observation['target/r2_score'][0], expected)
pytest.approx(observation['target/r2_score'], expected)

# --- test __call__ ---
result = evaluator()
pytest.approx(result['train/main/r2_score'][0], expected)
pytest.approx(result['train/main/r2_score'], expected)


def _test_r2_score_evaluator_raw_values(inputs):
Expand All @@ -156,11 +156,11 @@ def _test_r2_score_evaluator_raw_values(inputs):
observation = evaluator.evaluate()

expected = r2_score(x0, x1, multioutput='raw_values')
pytest.approx(observation['target/r2_score'][0], expected)
pytest.approx(observation['target/r2_score'], expected)

# --- test __call__ ---
result = evaluator()
pytest.approx(result['train/main/r2_score'][0], expected)
pytest.approx(result['train/main/r2_score'], expected)


if __name__ == '__main__':
Expand Down