Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add root mean square feature #813

Merged
merged 6 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
Binary file added notebooks/examples/pipeline.pkl
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/units/feature_extraction/test_feature_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ def test_kurtosis(self):
self.assertAlmostEqualOnAllArrayTypes(kurtosis, [1, 1, 1, 1], 0)
self.assertIsNanOnAllArrayTypes(kurtosis, [1, 1, 1])

def test_root_mean_square(self):
self.assertAlmostEqualOnAllArrayTypes(root_mean_square, [1, 1, 1, 2, 2], 1.48324)
self.assertAlmostEqualOnAllArrayTypes(root_mean_square, [0], 0)
self.assertAlmostEqualOnAllArrayTypes(root_mean_square, [], 0)
self.assertAlmostEqualOnAllArrayTypes(root_mean_square, [1], 1)
self.assertAlmostEqualOnAllArrayTypes(root_mean_square, [-1], 1)

def test_absolute_sum_of_changes(self):
self.assertEqualOnAllArrayTypes(absolute_sum_of_changes, [1, 1, 1, 1, 2, 1], 2)
self.assertEqualOnAllArrayTypes(absolute_sum_of_changes, [1, -1, 1, -1], 6)
Expand Down
14 changes: 14 additions & 0 deletions tsfresh/feature_extraction/feature_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,20 @@ def kurtosis(x):
return pd.Series.kurtosis(x)


@set_property("fctype", "simple")
@set_property("minimal", True)
def root_mean_square(x):
"""
Returns the root mean square (rms) of the time series.

:param x: the time series to calculate the feature of
:type x: numpy.ndarray
:return: the value of this feature
:return type: float
"""
return np.sqrt(np.mean(x**2))


@set_property("fctype", "simple")
def absolute_sum_of_changes(x):
"""
Expand Down