-
-
Notifications
You must be signed in to change notification settings - Fork 269
Reliability and Calibrated Prediction #491
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
Reliability and Calibrated Prediction #491
Conversation
…n branch Signed-off-by: Nathaniel <[email protected]>
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Hi @drbenvincent and @OriolAbril I think this is ready for review now. It's longer than i anticipated and i've cut out the idea to compare against conformal prediction as there is already quite a bit of detail in there. The broader structure has three parts: In the first part i'm just introducing time-to-failure data and the descriptive statistical analogues of survival and cdf functions. I follow a trajectory of first showing how we can analyse this kind of data with MLE or bootstrap style inference and then show on a trickier example with sparser data why the ability to add Bayesian priors to help calibrate the risk the profile is useful. Then i conclude with a "lets all be friends" kind of ending. I'm not sure who is best placed to review, but since i deal with censored data and I know @drbenvincent recently updated the censored data notebook, i thought you might find it interesting? Curious about what you think too @OriolAbril? Happy to take any feedback on the content or structure... |
…ied priors. Signed-off-by: Nathaniel <[email protected]>
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.
I have commented on the myst file, but the changes should be done in ipynb and then use pre-commit to update myst one.
General comment: I would use https://myst-nb.readthedocs.io/en/latest/render/hiding.html to hide the source of some of the code. i.e. the stringIO ones can be hidden, we would only need to split them so the df_name
to show the rendered table is in its own cell right below (not hidden so readers can follow the notebook and get the variable name even without expanding the cell). Some of the plots I think could also have their source hidden.
We'll use the posterior predictive distribution of the uniformative model. We show here how to derive the uncertainty in the estimates of the 95% prediction interval for the number of failures in a time interval. | ||
|
||
```{code-cell} ipython3 | ||
def PI_failures(joint_draws, lp, up, n_at_risk): |
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.
I'll update the code to use xarray-einstats, the inputs are xarray dataset and scalars IIUC, so there should be no need for looping in order to use scipy distributions. I can also try rerunning the notebook and finding other similar instances.
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.
On this one... i think i kind of disagree. While it's not the most efficient way to do this operation, i wanted the parallel with the bootstrapping looping procedures to be clear. We're instantiating in a loop a reasonable model fit to the data in each iteration of the loop, and seeing the variation induced in downstream statistics... i think pedagogically this is simpler than hiding the similarity of the procedure in more efficient code....
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.
Oops I think I misread this comment yesterday, did you want to try and streamline the loop? My only point was that I'd like to keep the analogy with the bootstrap procedure clear....
But I think I could just add more text explaining that too.
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.
Ok, i've added some more text to highlight the relationship between the bootstrap and posterior predictive distributions if you want to work some xarray magic, that'd be cool! Thanks!
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.
Updated, and found a bug in xarray-einstats while doing it 😄 (I have fixed it already)
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.
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.
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.
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.
I still have one PR I to get into 0.5 release, but I plan to release it soon. We can wait until I actually make the release one of these days, with the watermark having the 0.5.0dev flag though I don't think it is a deal breaker to merge it even before that.
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.
OK, cool! Let's do it. Thanks again for all your help on this one! I'm happy with it now if you are.
examples/case_studies/reliability_and_calibrated_prediction.myst.md
Outdated
Show resolved
Hide resolved
examples/case_studies/reliability_and_calibrated_prediction.myst.md
Outdated
Show resolved
Hide resolved
…hide data import and plotting funcs Signed-off-by: Nathaniel <[email protected]>
Thanks so much for the review. @OriolAbril. I've quibbled with one of the requests but i think i've addressed the rest. I've added hide-input tags to a bunch of the data loads and some of the more involved plotting functions. |
…cer in thumbnail Signed-off-by: Nathaniel <[email protected]>
…diction intervals with posterior predictive intervals Signed-off-by: Nathaniel <[email protected]>
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.
I reran the notebook locally to update that sampling snippet. And did a couple extra changes that I have commented here in the review. Let me know what you think, they are all quite minor except for the sampling one.
examples/case_studies/reliability_and_calibrated_prediction.myst.md
Outdated
Show resolved
Hide resolved
joint_draws = az.extract_dataset(idata, group="posterior", num_samples=1000)[ | ||
["alpha", "beta"] | ||
].to_dataframe() | ||
joint_draws = az.extract(idata, num_samples=1000)[["alpha", "beta"]] |
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.
The fact that was a dataframe wasn't being used anywhere, so I changed that because now below we take advantage of the fact joint_draws
is an xarray dataset.
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.
That's fair.
We'll use the posterior predictive distribution of the uniformative model. We show here how to derive the uncertainty in the estimates of the 95% prediction interval for the number of failures in a time interval. | ||
|
||
```{code-cell} ipython3 | ||
def PI_failures(joint_draws, lp, up, n_at_risk): |
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.
Updated, and found a bug in xarray-einstats while doing it 😄 (I have fixed it already)
Thanks @OriolAbril I'm fine with all the changes you made, i understand the logic of the xarray-einstats version too. I think the code is fine, just using the dev version of xarray-einstats makes reproducibility harder. We could add a note to the effect that this uses a dev version of xarrray. What do you think? |
Signed-off-by: Nathaniel <[email protected]>
Fixed typo on myst too
Just fixing a typo at the beginning. |
Woop, woop! Thanks 😊! |
This will be an example notebook demonstrating the techniques of survival analysis used in reliability context with a focus on the predictive distribution and calibrated prediction intervals from a Bayesian and MLE perspective. Relates to issue: #474
Adding this draft version here, because i'm having a little trouble with the pre-commit checks