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
d6219fd3
Commit
d6219fd3
authored
Jul 27, 2018
by
Sascha Herzinger
Browse files
replaced variance with std
parent
5a33dbf2
Pipeline
#5944
passed with stages
in 37 minutes and 32 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
fractalis/analytics/tasks/histogram/main.py
View file @
d6219fd3
...
...
@@ -25,7 +25,7 @@ class HistogramTask(AnalyticTask):
subsets
:
List
[
List
[
str
]],
data
:
pd
.
DataFrame
,
categories
:
List
[
pd
.
DataFrame
])
->
dict
:
"""Compute several basic statistics such as bin size and
varianc
e.
"""Compute several basic statistics such as bin size and
kd
e.
:param id_filter: If specified use only given ids during the analysis.
:param subsets: List of lists of subset ids.
:param data: Numerical values to create histogram of.
...
...
@@ -54,7 +54,7 @@ class HistogramTask(AnalyticTask):
bin_edges
=
bin_edges
.
tolist
()
mean
=
np
.
mean
(
values
)
median
=
np
.
median
(
values
)
variance
=
np
.
var
(
values
)
std
=
np
.
std
(
values
)
if
not
stats
.
get
(
category
):
stats
[
category
]
=
{}
stats
[
category
][
subset
]
=
{
...
...
@@ -62,7 +62,7 @@ class HistogramTask(AnalyticTask):
'bin_edges'
:
bin_edges
,
'mean'
:
mean
,
'median'
:
median
,
'
variance'
:
variance
'
std'
:
std
}
return
{
'stats'
:
stats
,
...
...
tests/unit/analytics/histogram/test_histogram.py
View file @
d6219fd3
...
...
@@ -43,7 +43,7 @@ class TestHistogramTask:
assert
'B'
in
result
[
'stats'
]
assert
0
in
result
[
'stats'
][
'A'
]
assert
all
([
stat
in
result
[
'stats'
][
'A'
][
0
]
for
stat
in
[
'hist'
,
'bin_edges'
,
'mean'
,
'median'
,
'
variance
'
]])
[
'hist'
,
'bin_edges'
,
'mean'
,
'median'
,
'
std
'
]])
def
test_can_handle_nas
(
self
):
df
=
pd
.
DataFrame
([[
100
,
'foo'
,
float
(
'nan'
)],
...
...
@@ -63,7 +63,6 @@ class TestHistogramTask:
categories
=
[])
assert
result
[
'stats'
][
''
][
0
][
'median'
]
==
6
assert
result
[
'stats'
][
''
][
0
][
'mean'
]
==
6
assert
result
[
'stats'
][
''
][
0
][
'variance'
]
==
8
def
test_can_handle_negatives
(
self
):
df
=
pd
.
DataFrame
([[
100
,
'foo'
,
-
2
],
...
...
@@ -113,7 +112,7 @@ class TestHistogramTask:
categories
=
[
cat_df
])
assert
result
[
'stats'
][
'A'
][
0
][
'median'
]
==
1
assert
result
[
'stats'
][
'A'
][
0
][
'mean'
]
==
1
assert
result
[
'stats'
][
'A'
][
0
][
'
variance
'
]
==
0
assert
result
[
'stats'
][
'A'
][
0
][
'
std
'
]
==
0
def
test_skips_empty_groups
(
self
):
df
=
pd
.
DataFrame
([[
100
,
'foo'
,
float
(
'nan'
)],
...
...
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