Skip to content
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
8 changes: 6 additions & 2 deletions docs/api/tasks/pyhealth.tasks.drug_recommendation.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyhealth.tasks.drug_recommendation
pyhealth.tasks.drug_recommendation
===================================

Task Classes
Expand All @@ -14,10 +14,14 @@ Task Classes
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.drug_recommendation.DrugRecommendationEICU
:members:
:undoc-members:
:show-inheritance:

Task Functions (Legacy)
------------------------

.. autofunction:: pyhealth.tasks.drug_recommendation.drug_recommendation_mimic3_fn
.. autofunction:: pyhealth.tasks.drug_recommendation.drug_recommendation_mimic4_fn
.. autofunction:: pyhealth.tasks.drug_recommendation.drug_recommendation_eicu_fn
.. autofunction:: pyhealth.tasks.drug_recommendation.drug_recommendation_omop_fn
28 changes: 23 additions & 5 deletions docs/api/tasks/pyhealth.tasks.length_of_stay_prediction.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
pyhealth.tasks.length_of_stay_prediction
pyhealth.tasks.length_of_stay_prediction
===========================================

.. autofunction:: pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_mimic3_fn
.. autofunction:: pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_mimic4_fn
.. autofunction:: pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_eicu_fn
.. autofunction:: pyhealth.tasks.length_of_stay_prediction.length_of_stay_prediction_omop_fn
Task Classes
------------

.. autoclass:: pyhealth.tasks.length_of_stay_prediction.LengthOfStayPredictionMIMIC3
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.length_of_stay_prediction.LengthOfStayPredictionMIMIC4
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.length_of_stay_prediction.LengthOfStayPredictioneICU
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.length_of_stay_prediction.LengthOfStayPredictionOMOP
:members:
:undoc-members:
:show-inheritance:
6 changes: 4 additions & 2 deletions docs/api/tasks/pyhealth.tasks.readmission_prediction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
:undoc-members:
:show-inheritance:

.. autofunction:: pyhealth.tasks.readmission_prediction.readmission_prediction_eicu_fn
.. autofunction:: pyhealth.tasks.readmission_prediction.readmission_prediction_eicu_fn2
.. autoclass:: pyhealth.tasks.readmission_prediction.ReadmissionPredictionEICU
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.tasks.readmission_prediction.ReadmissionPredictionOMOP
:members:
Expand Down
117 changes: 0 additions & 117 deletions examples/drug_recommendation/drug_recommendation_eICU_transformer.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Drug Recommendation on eICU with Transformer

This example demonstrates how to use the modernized eICUDataset with the
DrugRecommendationEICU task class for drug recommendation using a Transformer model.

Features:
- Uses the new BaseDataset-based eICUDataset with YAML configuration
- Uses the new DrugRecommendationEICU BaseTask class
- Demonstrates the standardized PyHealth workflow
"""

import tempfile

from pyhealth.datasets import eICUDataset
from pyhealth.datasets import split_by_patient, get_dataloader
from pyhealth.models import Transformer
from pyhealth.tasks import DrugRecommendationEICU
from pyhealth.trainer import Trainer


if __name__ == "__main__":
# STEP 1: Load dataset
base_dataset = eICUDataset(
root="https://storage.googleapis.com/pyhealth/eicu-demo/",
tables=["diagnosis", "medication", "physicalexam"],
cache_dir=tempfile.TemporaryDirectory().name,
dev=True,
)
base_dataset.stats()

# STEP 2: Set task
task = DrugRecommendationEICU()
sample_dataset = base_dataset.set_task(task)

# STEP 3: Split and create dataloaders
train_dataset, val_dataset, test_dataset = split_by_patient(
sample_dataset, [0.8, 0.1, 0.1]
)
train_dataloader = get_dataloader(train_dataset, batch_size=32, shuffle=True)
val_dataloader = get_dataloader(val_dataset, batch_size=32, shuffle=False)
test_dataloader = get_dataloader(test_dataset, batch_size=32, shuffle=False)

# STEP 4: Define model
model = Transformer(
dataset=sample_dataset,
)

# STEP 5: Train
trainer = Trainer(model=model)
trainer.train(
train_dataloader=train_dataloader,
val_dataloader=val_dataloader,
epochs=1,
monitor="pr_auc_samples",
)

# STEP 6: Evaluate
print(trainer.evaluate(test_dataloader))
7 changes: 4 additions & 3 deletions examples/interpretability/interpret_demo.ipynb

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions examples/length_of_stay/length_of_stay_eicu_rnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Length of Stay Prediction on eICU with RNN

This example demonstrates how to use the modernized eICUDataset with the
LengthOfStayPredictioneICU task class for predicting ICU length of stay
using an RNN model.

Length of stay is categorized into 10 classes:
- 0: < 1 day
- 1: 1 day
- 2: 2 days
- 3: 3 days
- 4: 4 days
- 5: 5 days
- 6: 6 days
- 7: 7 days
- 8: 1-2 weeks
- 9: > 2 weeks

Features:
- Uses the new BaseDataset-based eICUDataset with YAML configuration
- Uses the LengthOfStayPredictioneICU BaseTask class
- Demonstrates the standardized PyHealth workflow
"""

import tempfile

from pyhealth.datasets import eICUDataset
from pyhealth.datasets import split_by_patient, get_dataloader
from pyhealth.models import RNN
from pyhealth.tasks import LengthOfStayPredictioneICU
from pyhealth.trainer import Trainer


if __name__ == "__main__":
# STEP 1: Load dataset
base_dataset = eICUDataset(
root="https://storage.googleapis.com/pyhealth/eicu-demo/",
tables=["diagnosis", "medication", "physicalexam"],
num_workers=4,
cache_dir=tempfile.TemporaryDirectory().name,
dev=True,
)
base_dataset.stats()

# STEP 2: Set task
task = LengthOfStayPredictioneICU()
sample_dataset = base_dataset.set_task(task, num_workers=16)

# STEP 3: Split and create dataloaders
train_dataset, val_dataset, test_dataset = split_by_patient(
sample_dataset, [0.8, 0.1, 0.1]
)
train_dataloader = get_dataloader(train_dataset, batch_size=32, shuffle=True)
val_dataloader = get_dataloader(val_dataset, batch_size=32, shuffle=False)
test_dataloader = get_dataloader(test_dataset, batch_size=32, shuffle=False)

# STEP 4: Define model
model = RNN(
dataset=sample_dataset,
)

# STEP 5: Train
trainer = Trainer(model=model)
trainer.train(
train_dataloader=train_dataloader,
val_dataloader=val_dataloader,
epochs=1,
monitor="accuracy",
)

# STEP 6: Evaluate
print(trainer.evaluate(test_dataloader))
60 changes: 60 additions & 0 deletions examples/mortality_prediction/mortality_prediction_eicu_rnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Mortality Prediction on eICU with RNN

This example demonstrates how to use the modernized eICUDataset with the
MortalityPredictionEICU task class for in-hospital mortality prediction
using an RNN model.

Features:
- Uses the new BaseDataset-based eICUDataset with YAML configuration
- Uses the MortalityPredictionEICU BaseTask class
- Demonstrates the standardized PyHealth workflow
"""

import tempfile

from pyhealth.datasets import eICUDataset
from pyhealth.datasets import split_by_patient, get_dataloader
from pyhealth.models import RNN
from pyhealth.tasks import MortalityPredictionEICU
from pyhealth.trainer import Trainer


if __name__ == "__main__":
# STEP 1: Load dataset
base_dataset = eICUDataset(
root="https://storage.googleapis.com/pyhealth/eicu-demo/",
tables=["diagnosis", "medication", "physicalexam"],
cache_dir=tempfile.TemporaryDirectory().name,
dev=True,
)
base_dataset.stats()

# STEP 2: Set task
task = MortalityPredictionEICU()
sample_dataset = base_dataset.set_task(task)

# STEP 3: Split and create dataloaders
train_dataset, val_dataset, test_dataset = split_by_patient(
sample_dataset, [0.8, 0.1, 0.1]
)
train_dataloader = get_dataloader(train_dataset, batch_size=32, shuffle=True)
val_dataloader = get_dataloader(val_dataset, batch_size=32, shuffle=False)
test_dataloader = get_dataloader(test_dataset, batch_size=32, shuffle=False)

# STEP 4: Define model
model = RNN(
dataset=sample_dataset,
)

# STEP 5: Train
trainer = Trainer(model=model)
trainer.train(
train_dataloader=train_dataloader,
val_dataloader=val_dataloader,
epochs=1,
monitor="roc_auc",
)

# STEP 6: Evaluate
print(trainer.evaluate(test_dataloader))
Loading