Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
f3f3e92d
Commit
f3f3e92d
authored
Jun 13, 2018
by
wegamekinglc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more tests
parent
e070f6d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
test_standardize.py
alphamind/tests/data/test_standardize.py
+6
-8
test_winsorize.py
alphamind/tests/data/test_winsorize.py
+23
-0
No files found.
alphamind/tests/data/test_standardize.py
View file @
f3f3e92d
...
@@ -12,7 +12,6 @@ from scipy.stats import zscore
...
@@ -12,7 +12,6 @@ from scipy.stats import zscore
from
alphamind.data.standardize
import
standardize
from
alphamind.data.standardize
import
standardize
from
alphamind.data.standardize
import
projection
from
alphamind.data.standardize
import
projection
from
alphamind.data.standardize
import
Standardizer
from
alphamind.data.standardize
import
Standardizer
from
alphamind.data.standardize
import
GroupedStandardizer
class
TestStandardize
(
unittest
.
TestCase
):
class
TestStandardize
(
unittest
.
TestCase
):
...
@@ -55,17 +54,16 @@ class TestStandardize(unittest.TestCase):
...
@@ -55,17 +54,16 @@ class TestStandardize(unittest.TestCase):
exp_zscore
=
standardize
(
self
.
x
)
exp_zscore
=
standardize
(
self
.
x
)
np
.
testing
.
assert_array_almost_equal
(
calc_zscore
,
exp_zscore
)
np
.
testing
.
assert_array_almost_equal
(
calc_zscore
,
exp_zscore
)
np
.
testing
.
assert_array_almost_equal
(
s
(
self
.
x
),
exp_zscore
)
def
test_groupedstandardizer
(
self
):
def
test_grouped_standardizer
(
self
):
s
=
Standardizer
()
x
=
np
.
concatenate
([
self
.
groups
.
reshape
((
-
1
,
1
)),
self
.
x
],
axis
=
1
)
s
.
fit
(
self
.
x
,
self
.
groups
)
calc_zscore
=
s
.
transform
(
self
.
x
,
self
.
groups
)
s
=
GroupedStandardizer
()
s
.
fit
(
x
)
calc_zscore
=
s
.
transform
(
x
)
exp_zscore
=
standardize
(
self
.
x
,
self
.
groups
)
exp_zscore
=
standardize
(
self
.
x
,
self
.
groups
)
np
.
testing
.
assert_array_almost_equal
(
calc_zscore
,
exp_zscore
)
np
.
testing
.
assert_array_almost_equal
(
calc_zscore
,
exp_zscore
)
np
.
testing
.
assert_array_almost_equal
(
s
(
self
.
x
,
self
.
groups
),
exp_zscore
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
alphamind/tests/data/test_winsorize.py
View file @
f3f3e92d
...
@@ -9,6 +9,7 @@ import unittest
...
@@ -9,6 +9,7 @@ import unittest
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
from
alphamind.data.winsorize
import
winsorize_normal
from
alphamind.data.winsorize
import
winsorize_normal
from
alphamind.data.winsorize
import
NormalWinsorizer
class
TestWinsorize
(
unittest
.
TestCase
):
class
TestWinsorize
(
unittest
.
TestCase
):
...
@@ -52,6 +53,28 @@ class TestWinsorize(unittest.TestCase):
...
@@ -52,6 +53,28 @@ class TestWinsorize(unittest.TestCase):
exp_winsorized
=
pd
.
DataFrame
(
self
.
x
)
.
groupby
(
self
.
groups
)
.
transform
(
impl
)
.
values
exp_winsorized
=
pd
.
DataFrame
(
self
.
x
)
.
groupby
(
self
.
groups
)
.
transform
(
impl
)
.
values
np
.
testing
.
assert_array_almost_equal
(
cal_winsorized
,
exp_winsorized
)
np
.
testing
.
assert_array_almost_equal
(
cal_winsorized
,
exp_winsorized
)
def
test_normal_winsorizer
(
self
):
s
=
NormalWinsorizer
(
num_stds
=
self
.
num_stds
)
s
.
fit
(
self
.
x
)
calc_winsorized1
=
s
.
transform
(
self
.
x
)
calc_winsorized2
=
s
(
self
.
x
)
std_values
=
self
.
x
.
std
(
axis
=
0
,
ddof
=
1
)
mean_value
=
self
.
x
.
mean
(
axis
=
0
)
lower_bound
=
mean_value
-
self
.
num_stds
*
std_values
upper_bound
=
mean_value
+
self
.
num_stds
*
std_values
for
i
in
range
(
np
.
size
(
calc_winsorized1
,
1
)):
col_data
=
self
.
x
[:,
i
]
col_data
[
col_data
>
upper_bound
[
i
]]
=
upper_bound
[
i
]
col_data
[
col_data
<
lower_bound
[
i
]]
=
lower_bound
[
i
]
calculated_col
=
calc_winsorized1
[:,
i
]
np
.
testing
.
assert_array_almost_equal
(
col_data
,
calculated_col
)
calculated_col
=
calc_winsorized2
[:,
i
]
np
.
testing
.
assert_array_almost_equal
(
col_data
,
calculated_col
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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