Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Fractalis
fractalis
Commits
be7cd03e
Commit
be7cd03e
authored
Jun 11, 2018
by
Sascha Herzinger
Browse files
Some tests and fixed a bug in kaplan meier plot
parent
805292b4
Pipeline
#5333
failed with stages
in 2 minutes and 52 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
fractalis/analytics/tasks/kaplan_meier_survival/main.py
View file @
be7cd03e
...
...
@@ -11,7 +11,6 @@ from fractalis.analytics.task import AnalyticTask
from
fractalis.analytics.tasks.shared
import
utils
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -54,7 +53,7 @@ class KaplanMeierSurvivalTask(AnalyticTask):
E
=
None
# default is nothing is censored
if
event_observed
:
# find observation boolean value for every duration
E
=
event_observed
[
0
].
merge
(
sub_df
,
how
=
'
lef
t'
,
on
=
'id'
)
E
=
event_observed
[
0
].
merge
(
sub_df
,
how
=
'
righ
t'
,
on
=
'id'
)
E
=
[
bool
(
x
)
and
not
np
.
isnan
(
x
)
for
x
in
E
[
'value'
]]
assert
len
(
E
)
==
len
(
T
)
kmf
.
fit
(
durations
=
T
,
event_observed
=
E
)
...
...
tests/unit/analytics/kaplan_meier_survival/test_main.py
View file @
be7cd03e
"""This module contains tests for the kaplan_meier_survival module."""
from
lifelines.datasets
import
load_waltons
from
fractalis.analytics.tasks.kaplan_meier_survival.main
\
import
KaplanMeierSurvivalTask
class
TestKaplanMeierSurvivalTask
:
task
=
KaplanMeierSurvivalTask
()
def
test_correct_output_for_simple_input
(
self
):
df
=
load_waltons
()
df
.
insert
(
0
,
'id'
,
df
.
index
)
duration
=
df
[[
'id'
,
'T'
]].
copy
()
duration
.
insert
(
1
,
'feature'
,
'duration'
)
duration
.
columns
.
values
[
2
]
=
'value'
results
=
self
.
task
.
main
(
durations
=
[
duration
],
categories
=
[],
event_observed
=
[],
id_filter
=
[],
subsets
=
[])
assert
'timeline'
in
results
[
'stats'
][
''
][
0
]
assert
'median'
in
results
[
'stats'
][
''
][
0
]
assert
'survival_function'
in
results
[
'stats'
][
''
][
0
]
assert
'confidence_interval'
in
results
[
'stats'
][
''
][
0
]
def
test_correct_output_for_complex_input
(
self
):
df
=
load_waltons
()
df
.
insert
(
0
,
'id'
,
df
.
index
)
duration
=
df
[[
'id'
,
'T'
]].
copy
()
duration
.
insert
(
1
,
'feature'
,
'duration'
)
duration
.
columns
.
values
[
2
]
=
'value'
event_observed
=
df
[[
'id'
,
'E'
]].
copy
()
event_observed
.
insert
(
1
,
'feature'
,
'was_observed'
)
categories
=
df
[[
'id'
,
'group'
]].
copy
()
categories
.
insert
(
1
,
'feature'
,
'group'
)
results
=
self
.
task
.
main
(
durations
=
[
duration
],
categories
=
[
categories
],
event_observed
=
[
event_observed
],
id_filter
=
[],
subsets
=
[])
assert
results
[
'stats'
][
'control'
]
assert
results
[
'stats'
][
'miR-137'
]
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment