Skip to content
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

WIP for blog post #1027

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions examples/due_date_probabilities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Predicting due date using Hamilton

This is a fun example of a simple script in a jupyter notebook using Hamilton.

The goal is to predict the probability of delivery for an expecting mother, given:
1. The start date of the pregnancy
2. The current date

We want to answer the questions:
1. What is the probability that she will give birth on date X?
2. What is the probability that she will give birth before date X?

You can follow along in the [jupyter notebook](./notebook.ipynb) -- the entire dataflow is written/documented there.

For a guideline of using Hamilton in a jupyter notebook, see this [page](https://hamilton.dagworks.io/en/latest/how-tos/use-in-jupyter-notebook/)
21 changes: 21 additions & 0 deletions examples/due_date_probabilities/base_dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import datetime

import pandas as pd


def due_date(start_date: datetime.datetime) -> datetime.datetime:
"""The due date is start_date + 40 weeks. Start date is the date of the expecting mother's last period"""
return start_date + datetime.timedelta(weeks=40)


def possible_dates(
due_date: datetime.datetime,
buffer_before_due_date: int = 8 * 7,
buffer_after_due_date: int = 4 * 7,
) -> pd.Series:
"""Gets all the reasonably possible dates (-8 weeks, + 4 weeks) of delivery"""
idx = pd.date_range(
due_date - datetime.timedelta(days=buffer_before_due_date),
due_date + datetime.timedelta(days=buffer_after_due_date),
)
return pd.Series(data=idx, index=idx)
Loading