-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add counterfactual analysis for regression models (What-If Tool) #2647
Add counterfactual analysis for regression models (What-If Tool) #2647
Conversation
When computing closest counterfactuals, we need to evaluate if two datapoints are in the same class or not. For regression, this is more than ordinary comparison. Let's move this evaluation to a separate method to be able to keep the logics clear.
For regression, we add a way to specify the distance in inferred value above which the points can be considered counterfactual. Also adding a small explanation in the information dialog.
Set the maximum slider value for the datapoint when calculating nearest counterfactuals. Since the counterfactual threshold is based on the distance between inferred values, we calculate the maximum value distance between the selected point and the others.
Ignore the example itself when looking for counterfactuals, since a 0 threshold in regression would mean that the closest counterfactual is always the example itself, which gives no information. By skipping the example, the 0 threshold means looking for the closest [different] example, regardless of the difference in inferred values.
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
e54b2df
to
e5ed88e
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting this out so quickly! Some small comments.
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Show resolved
Hide resolved
Instead of 0, use the standard deviation of the inferred values as the initial value for the counterfactual delta.
Fixed vertical alignment.
@stephanwlee please review. |
adjustMaxCounterfactualValueDist_: function(selected, valueStr) { | ||
this.maxCounterfactualValueDist = Math.max( | ||
this.distanceStats_[valueStr].max - | ||
this.visdata[selected][valueStr], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not know about the nature of distanceStats
and visData
: can all of these values be negative? Can visData
be lower than both max and min of the distanceStats
? Can this be doing Math.max on, for example, Math.max(-2, -3)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
distanceStats_
is based on the visData
data, so that:
distanceStats_[valueStr].min
<= visdata[selected][valueStr]
<= distanceStats_[valueStr].max
This Math.max
op then receives only non-negative values.
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Outdated
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Outdated
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Outdated
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Show resolved
Hide resolved
Addressing PR conversations.
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Outdated
Show resolved
Hide resolved
...ractive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html
Show resolved
Hide resolved
One-way binding is enough.
Add the ability to show nearest counterfactual example in regression models.
The feature and its use are analogous to the existing counterfactual analysis available in non-regression models.
There is one fundamental difference in the way we compare inference classes. In binary classification, the counterfactual examples are the ones belonging to the alternative class. In regression, we will define them as the ones whose inferred values are farther from the original example than a given delta, which will be defined by the user.
For example, if delta is set to 2 and the inferred value of the selected example is 7, then we'll be looking for most similar example with an inferred value outside of the (5, 9) interval.
For regression only:
Plotting Distance to datapoint vs Inference value also helps to confirm that the counterfactual found is reasonable.
Some other ways of defining the nearest counterfactual example:
These alternative ways could be added in the future.
cc @jameswex @tolga-b