Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
a2299e50
Commit
a2299e50
authored
Oct 24, 2019
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
implemented inverse transform and it's tests in statistics module
parent
608d219d
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!6
updated inception model and data prep class
,
!4
data prep class
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/statistics.py
+21
-2
21 additions, 2 deletions
src/statistics.py
test/test_statistics.py
+20
-3
20 additions, 3 deletions
test/test_statistics.py
with
41 additions
and
5 deletions
src/statistics.py
+
21
−
2
View file @
a2299e50
...
@@ -21,10 +21,20 @@ def standardise(data: Data, dim: Union[str, int]) -> Tuple[Data, Data, Data]:
...
@@ -21,10 +21,20 @@ def standardise(data: Data, dim: Union[str, int]) -> Tuple[Data, Data, Data]:
#. std: Standard deviation of data
#. std: Standard deviation of data
#. data: Standardised data
#. data: Standardised data
"""
"""
return
data
.
mean
(
dim
),
data
.
std
(
dim
),
(
data
-
data
.
mean
(
dim
))
/
data
.
std
(
dim
)
return
data
.
mean
(
dim
),
data
.
std
(
dim
),
(
data
-
data
.
mean
(
dim
))
/
data
.
std
(
dim
)
def
standardise_inverse
(
data
:
Data
,
mean
:
Data
,
std
:
Data
)
->
Data
:
"""
This is the inverse function of `standardise` and therefore vanishes the standardising.
:param data:
:param mean:
:param std:
:return:
"""
return
data
*
std
+
mean
def
centre
(
data
:
Data
,
dim
:
Union
[
str
,
int
])
->
Tuple
[
Data
,
None
,
Data
]:
def
centre
(
data
:
Data
,
dim
:
Union
[
str
,
int
])
->
Tuple
[
Data
,
None
,
Data
]:
"""
"""
This function centres a xarray.dataarray (along dim) or pandas.DataFrame (along axis) to mean=0
This function centres a xarray.dataarray (along dim) or pandas.DataFrame (along axis) to mean=0
...
@@ -37,5 +47,14 @@ def centre(data: Data, dim: Union[str, int]) -> Tuple[Data, None, Data]:
...
@@ -37,5 +47,14 @@ def centre(data: Data, dim: Union[str, int]) -> Tuple[Data, None, Data]:
#. std: Standard deviation of data
#. std: Standard deviation of data
#. data: Standardised data
#. data: Standardised data
"""
"""
return
data
.
mean
(
dim
),
None
,
data
-
data
.
mean
(
dim
)
return
data
.
mean
(
dim
),
None
,
data
-
data
.
mean
(
dim
)
def
centre_inverse
(
data
:
Data
,
mean
:
Data
)
->
Data
:
"""
This function is the inverse function of `centre` and therefore adds the given values of mean to the data.
:param data:
:param mean:
:return:
"""
return
data
+
mean
This diff is collapsed.
Click to expand it.
test/test_statistics.py
+
20
−
3
View file @
a2299e50
...
@@ -2,7 +2,7 @@ import pytest
...
@@ -2,7 +2,7 @@ import pytest
import
xarray
as
xr
import
xarray
as
xr
import
pandas
as
pd
import
pandas
as
pd
import
numpy
as
np
import
numpy
as
np
from
src.statistics
import
standardise
,
centr
e
from
src.statistics
import
standardise
,
standardise_inverse
,
centre
,
centre_invers
e
@pytest.fixture
(
scope
=
'
module
'
)
@pytest.fixture
(
scope
=
'
module
'
)
...
@@ -24,7 +24,8 @@ def xarray(input_data):
...
@@ -24,7 +24,8 @@ def xarray(input_data):
class
TestStandardise
:
class
TestStandardise
:
@pytest.mark.parametrize
(
'
data_org, dim
'
,
[(
pytest
.
lazy_fixture
(
'
pandas
'
),
0
),
(
pytest
.
lazy_fixture
(
'
xarray
'
),
'
index
'
)])
@pytest.mark.parametrize
(
'
data_org, dim
'
,
[(
pytest
.
lazy_fixture
(
'
pandas
'
),
0
),
(
pytest
.
lazy_fixture
(
'
xarray
'
),
'
index
'
)])
def
test_standardise
(
self
,
data_org
,
dim
):
def
test_standardise
(
self
,
data_org
,
dim
):
mean
,
std
,
data
=
standardise
(
data_org
,
dim
)
mean
,
std
,
data
=
standardise
(
data_org
,
dim
)
assert
np
.
testing
.
assert_almost_equal
(
mean
,
[
2
,
-
5
,
10
],
decimal
=
1
)
is
None
assert
np
.
testing
.
assert_almost_equal
(
mean
,
[
2
,
-
5
,
10
],
decimal
=
1
)
is
None
...
@@ -32,12 +33,28 @@ class TestStandardise:
...
@@ -32,12 +33,28 @@ class TestStandardise:
assert
np
.
testing
.
assert_almost_equal
(
data
.
mean
(
dim
),
[
0
,
0
,
0
])
is
None
assert
np
.
testing
.
assert_almost_equal
(
data
.
mean
(
dim
),
[
0
,
0
,
0
])
is
None
assert
np
.
testing
.
assert_almost_equal
(
data
.
std
(
dim
),
[
1
,
1
,
1
])
is
None
assert
np
.
testing
.
assert_almost_equal
(
data
.
std
(
dim
),
[
1
,
1
,
1
])
is
None
@pytest.mark.parametrize
(
'
data_org, dim
'
,
[(
pytest
.
lazy_fixture
(
'
pandas
'
),
0
),
(
pytest
.
lazy_fixture
(
'
xarray
'
),
'
index
'
)])
def
test_standardise_inverse
(
self
,
data_org
,
dim
):
mean
,
std
,
data
=
standardise
(
data_org
,
dim
)
data_recovered
=
standardise_inverse
(
data
,
mean
,
std
)
assert
np
.
testing
.
assert_array_almost_equal
(
data_org
,
data_recovered
)
is
None
class
TestCentre
:
class
TestCentre
:
@pytest.mark.parametrize
(
'
data_org, dim
'
,
[(
pytest
.
lazy_fixture
(
'
pandas
'
),
0
),
(
pytest
.
lazy_fixture
(
'
xarray
'
),
'
index
'
)])
@pytest.mark.parametrize
(
'
data_org, dim
'
,
[(
pytest
.
lazy_fixture
(
'
pandas
'
),
0
),
(
pytest
.
lazy_fixture
(
'
xarray
'
),
'
index
'
)])
def
test_centre
(
self
,
data_org
,
dim
):
def
test_centre
(
self
,
data_org
,
dim
):
mean
,
std
,
data
=
centre
(
data_org
,
dim
)
mean
,
std
,
data
=
centre
(
data_org
,
dim
)
assert
np
.
testing
.
assert_almost_equal
(
mean
,
[
2
,
-
5
,
10
],
decimal
=
1
)
is
None
assert
np
.
testing
.
assert_almost_equal
(
mean
,
[
2
,
-
5
,
10
],
decimal
=
1
)
is
None
assert
std
is
None
assert
std
is
None
assert
np
.
testing
.
assert_almost_equal
(
data
.
mean
(
dim
),
[
0
,
0
,
0
])
is
None
assert
np
.
testing
.
assert_almost_equal
(
data
.
mean
(
dim
),
[
0
,
0
,
0
])
is
None
@pytest.mark.parametrize
(
'
data_org, dim
'
,
[(
pytest
.
lazy_fixture
(
'
pandas
'
),
0
),
(
pytest
.
lazy_fixture
(
'
xarray
'
),
'
index
'
)])
def
test_centre_inverse
(
self
,
data_org
,
dim
):
mean
,
_
,
data
=
centre
(
data_org
,
dim
)
data_recovered
=
centre_inverse
(
data
,
mean
)
assert
np
.
testing
.
assert_array_almost_equal
(
data_org
,
data_recovered
)
is
None
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