This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| @author: Sparkle Russell-Puleri | |
| ''' | |
| -- Avg events within an hour | |
| --4.--Avg measurements done in the same hour and remove dupes all at once ################ | |
| DROP MATERIALIZED VIEW IF EXISTS mimiciii.timseries_table_avg CASCADE; | |
| CREATE MATERIALIZED VIEW mimiciii.timseries_table_avg as( | |
| with hours_entered as( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| @author: Sparkle Russell-Puleri | |
| ''' | |
| --3. Labs | |
| DROP MATERIALIZED VIEW IF EXISTS mimiciii.timeseries_table CASCADE; | |
| CREATE MATERIALIZED VIEW mimiciii.timeseries_table as( | |
| with labs as | |
| (select a.subject_id, a.hadm_id, a.charttime, a.valuenum, | |
| a.charttime::date as date_entered, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| @author: Sparkle Russell-Puleri | |
| ''' | |
| -- 2. Comorbities: | |
| -- 1. Heart Failure | |
| -- 2. COPD | |
| -- 3. Renal Disease | |
| -- 4. Cancer (with and without metastasis) | |
| -- 5. Diabetes mellitus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| @author: Sparkle Russell-Puleri | |
| ''' | |
| DROP MATERIALIZED VIEW IF EXISTS mimiciii.readmission CASCADE; | |
| create materialized view mimiciii.readmission as ( | |
| with | |
| first_discharge as( | |
| select subject_id, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| import matplotlib.pyplot as plt | |
| import torch | |
| import torch.nn as nn | |
| import numpy as np | |
| from torch.autograd import Variable | |
| ### Checking for GPU availability | |
| This model was trained on a GPU enabled system...highly recommended. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| optimizer = torch.optim.Adadelta(model.parameters(), lr = 0.01, rho=0.95) | |
| epochs = 10 | |
| counter = 0 | |
| for e in range(epochs): | |
| for x, y in train_dl: | |
| x, y , mask, lengths = padding(x, y, inputDimSize, numClass) | |
| output, h = model(x, mask) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| train, valid, test = load_data('data/Jan19.seqs', 'data/Jan19.seqs') | |
| train_ds= Dataset(train[0], train[1]) | |
| train_samp = Sampler(train_ds, batchSize, shuffle=True) | |
| train_dl = DataLoader(train_ds, sampler=train_samp, collate_fn=collate) | |
| valid_ds= Dataset(valid[0], valid[1]) | |
| valid_samp = Sampler(valid_ds, batchSize, shuffle=False) | |
| valid_dl = DataLoader(valid_ds, sampler=valid_samp, collate_fn=collate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class cost_function(): | |
| def __init__(self, yhat, y, L_2=0.001, logEps=1e-8): | |
| self.yhat = yhat | |
| self.y = y | |
| self.logEps = logEps | |
| self.L_2 = L_2 | |
| self.W_out = nn.Parameter(torch.randn(hiddenDimSize, numClass)*0.01) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class build_EHR_GRU(EHR_GRU): | |
| def __init__(self, GRUCell, *kwargs): | |
| super().__init__(inputDimSize, hiddenDimSize, embSize, numClass, numLayers) | |
| self.cell = GRUCell(*kwargs) | |
| self.emb = Custom_Embedding(inputDimSize, embSize) | |
| def forward(self, x, mask): | |
| inputVector = self.emb(x) | |
| for i in range(numLayers): | |
| memories = self.cell(inputVector, mask) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EHR_GRU(Custom_Embedding): | |
| def __init__(self, inputDimSize, hiddenDimSize, embSize, numClass, numLayers): | |
| super().__init__(inputDimSize, embSize) | |
| self.numClass = numClass | |
| self.numLayers = numLayers | |
| self.hiddenDimSize = hiddenDimSize | |
| self.emb = Custom_Embedding(inputDimSize, embSize) | |
| self.W_r = nn.Parameter(torch.randn(embSize, hiddenDimSize)* 0.01) |
NewerOlder