Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SWEMLS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Belfiore, Asia
SWEMLS
Commits
feaee054
Commit
feaee054
authored
1 month ago
by
Asia Belfiore
Browse files
Options
Downloads
Patches
Plain Diff
Removed redundant code.
parent
21d7ba7b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data_processing.py
+0
-132
0 additions, 132 deletions
data_processing.py
nhs_aki_algo.py
+0
-29
0 additions, 29 deletions
nhs_aki_algo.py
with
0 additions
and
161 deletions
data_processing.py
deleted
100644 → 0
+
0
−
132
View file @
21d7ba7b
import
pandas
as
pd
# add to requirements.txt
import
numpy
as
np
# add to requirements.txt
def
format_data
(
dataframe
):
"""
Format the data in the dataframe, converting the columns
to the appropriate types and returning the processed dataframe
inputs:
- dataframe: the source dataframe
output:
- dataframe: the formatted DataFrame with the following columns:
- age
- sex
- n
'
creatinine_result_i
'
columns
- n-1
'
elapsed_exam_i-(i+1)
'
columns
- min_creatinine
- avg_creatinine
- max_creatinine
- aki_values: the binary aki values of the original dataframe
"""
# Convert
aki_values
=
dataframe
[
'
aki
'
]
dataframe
.
drop
(
columns
=
[
'
aki
'
],
inplace
=
True
)
return
(
dataframe
,
aki_values
)
def
process_data
(
dataframe
):
"""
Process the data in the dataframe, converting the columns
to the appropriate types and returning the processed dataframe
inputs:
- dataframe: the source dataframe
output:
- dataframe: the formatted dataframe with the following columns:
- age
- sex
- n
'
creatinine_result_i
'
columns
- n-1
'
elapsed_exam_i-(i+1)
'
columns
- min_creatinine
- avg_creatinine
- max_creatinine
- aki_values: the binary aki values of the original dataframe
"""
# Preprocess the data
(
dataframe
,
aki_values
)
=
format_data
(
dataframe
)
return
(
dataframe
,
aki_values
)
def
calculate_elapsed_time
(
dataframe
,
total_tests
):
"""
Calculate the elapsed days between each blood test
inputs:
- dataframe: the source dataframe
output:
- elapsed_days: dataframe with n-1 columns corresponding to the
elapsed days between each n blood test
"""
columns
=
get_creatinine_dataframe_columns
(
total_tests
,
'
date
'
)
exams_time_difference
=
{}
prev
=
0
for
next
in
range
(
1
,
total_tests
):
exams_time_difference
[
f
'
elapsed_exam_
{
prev
}
-
{
next
}
'
]
=
(
dataframe
.
loc
[:][
columns
[
next
]]
-
dataframe
.
loc
[:][
columns
[
prev
]])
prev
=
next
elapsed_days
=
pd
.
DataFrame
(
exams_time_difference
).
astype
(
'
timedelta64[ns]
'
).
apply
(
lambda
x
:
x
.
dt
.
days
)
return
elapsed_days
def
get_creatinine_stats
(
dataframe
,
total_tests
):
columns
=
get_creatinine_dataframe_columns
(
total_tests
,
'
result
'
)
creatinine_stats
=
{}
creatinine_stats
[
'
min_creatinine
'
]
=
dataframe
.
loc
[:][
columns
].
min
(
axis
=
1
)
creatinine_stats
[
'
avg_creatinine
'
]
=
dataframe
.
loc
[:][
columns
].
mean
(
axis
=
1
)
creatinine_stats
[
'
max_creatinine
'
]
=
dataframe
.
loc
[:][
columns
].
max
(
axis
=
1
)
creatine_ds
=
pd
.
DataFrame
(
creatinine_stats
)
return
creatine_ds
def
get_creatinine_dataframe_columns
(
total_tests
,
col_type
):
"""
Return a list of creatinine columns in the dataset in the
form
'
creatinine_x_5
'
, with x equal to:
-
'
result
'
, if col_type is the result of the test
-
'
date
'
, if col_type is the date of the test
inputs:
- total_tests: the maximum number of creatinine tests taken by any patient
- col_type: the type of the column, either
'
result
'
or
'
date
'
output:
- creatinine_columns: list of column names
"""
creatinine_columns
=
[]
for
i
in
range
(
total_tests
):
creatinine_columns
.
append
(
f
'
creatinine_
{
col_type
}
_
{
i
}
'
)
return
creatinine_columns
def
convert_to_datetime
(
dataframe
,
columns
):
"""
Convert the given dataframe columns in the list
'
columns
'
to datetime type
inputs:
- dataframe: the source dataframe
- columns: list of column names to convert
output:
- dataframe: the processed dataframe
"""
for
column
in
columns
:
dataframe
[
column
]
=
pd
.
to_datetime
(
dataframe
[
column
])
return
dataframe
def
to_binary
(
x
):
"""
Map the aki and sex columns of the dataframe
to binary values
output:
- 0: if the aki value is
'
n
'
or if the sex value is
'
m
'
- 1: if the aki value is
'
y
'
or if the sex value is
'
f
'
"""
if
x
==
'
y
'
:
return
1
elif
x
==
'
f
'
:
return
1
else
:
return
0
\ No newline at end of file
This diff is collapsed.
Click to expand it.
nhs_aki_algo.py
deleted
100644 → 0
+
0
−
29
View file @
21d7ba7b
import
pandas
as
pd
from
utils
import
*
def
nhs_aki_algo
(
patient
,
data_type
=
'
train
'
):
"""
"""
[
sex
,
age
,
c1
,
rv1
,
rv2
,
rv_ratio
,
D
]
=
process_patient_data
(
patient
,
data_type
)
(
low_ri
,
high_ri
)
=
get_reference_interval
(
sex
,
age
)
elapsed_days
=
0
if
elapsed_days
<=
0
:
print
(
"
Error: invalid elapsed time between most recent creatinine test results.
"
)
return
0
elif
(
elapsed_days
>
0
)
and
(
elapsed_days
<=
7
):
rv_ratio
=
c1
/
rv1
elif
(
elapsed_days
>
7
)
and
(
elapsed_days
<=
365
):
rv_ratio
=
c1
/
rv2
elif
elapsed_days
>
365
:
return
0
if
rv_ratio
>=
1.5
:
return
1
elif
D
>
26
:
return
1
else
:
return
0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment