Skip to content

FEAT Introduce StreamingMetricFrame to accumulate batches - #942

Closed
Dref360 wants to merge 3 commits into
fairlearn:mainfrom
Dref360:streaming_v2
Closed

Dref360 wants to merge 3 commits into
fairlearn:mainfrom
Dref360:streaming_v2

Conversation

@Dref360

@Dref360 Dref360 commented Sep 6, 2021

Copy link
Copy Markdown
Contributor

Introduce StreamingMetricFrame to accumulate batches and enable batch evaluation.

This version focuses on maintainability and is much easier to work with than the previous one. Most checks are now done by MetricFrame.

Fixes #655

Notes

In the previous PR (#670), we mentioned that converting everything to pandas would be valuable.
I think this would be useful, but this approach gets complicated with nested dict found in sample_params. I am open to propositions on how to fix that and maybe get rid of StreamingMetricFrame._concat_batches.

@riedgar-ms riedgar-ms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for trying again at this!

self._sample_params = self._concat_if_not_none(self._sample_params,
sample_params)

def get_metric(self) -> MetricFrame:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps evaluate_metrics() ? @MiroDudik @hildeweerts @adrinjalali ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good question. Somehow I was thinking of this being sth that I could add data to, and then call .evaluate() which either returns nothing or self, and it would have all the features like MetrifFrame. If we don't want to go down that path, I think get_metricframe would be what this does?

check_consistent_length(y_true, y_pred)
self._y_true = self._concat_if_not_none(self._y_true, y_true)
self._y_pred = self._concat_if_not_none(self._y_pred, y_pred)
self._sensitive_features = self._concat_if_not_none(self._sensitive_features,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should sensitive features be checked for consistent length?


if sample_params is not None:
self._sample_params = self._concat_if_not_none(self._sample_params,
sample_params)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this have an else clause like the control features? And a consistent length check?

self._sensitive_features = self._concat_if_not_none(self._sensitive_features,
sensitive_features)
if control_features is not None:
self._control_features = self._concat_if_not_none(self._control_features,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent length?

@riedgar-ms
riedgar-ms requested a review from a team September 10, 2021 14:37
@romanlutz romanlutz changed the title Introduce StreamingMetricFrame to accumulate batches FEAT Introduce StreamingMetricFrame to accumulate batches Sep 15, 2021
@hildeweerts

Copy link
Copy Markdown
Contributor

At a first glance it seems like @Dref360 has processed al requested changes from @riedgar-ms. Is there anything else that's blocking this PR from getting merged?

Tagging @fairlearn/fairlearn-maintainers

@adrinjalali adrinjalali left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM, except that I'm not happy that we don't have codecov and I can't check if tests cover the new code. I guess I should set it up.

" because it was initialized as such.")

# A TypeVar to express possible batch types.
B = TypeVar('B', Dict, np.ndarray, List, pd.Series, pd.DataFrame)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then call it a BachtType maybe?

self._control_features = None
self._sample_params = None

def reset(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would the user not create a new StreamingMetricFrame instead?

Comment on lines +78 to +79
sensitive_features : (List, pandas.Series, dict of 1d arrays,
numpy.ndarray, pandas.DataFrame)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could just 1D or 2D say array-like instead?

Comment on lines +109 to +110
check_consistent_length(y_true, y_pred)
check_consistent_length(y_true, sensitive_features)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could merge these calls and pass the three objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for streaming metrics

4 participants