Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import abs_energy
class AbsEnergy(AggregationPrimitive):
"""Returns the absolute energy of the time series
which is the sum over the squared values.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.abs_energy
"""
name = "abs_energy"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def get_function(self):
return abs_energy
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import \
energy_ratio_by_chunks
class EnergyRatioByChunks(AggregationPrimitive):
"""Calculates the sum of squares of chunk i out of N chunks expressed as a
ratio with the sum of squares over the whole series.
Args:
num_segments (int) : Number of segments to divide the series into.
segment_focus (int) : Segment number (starting at zero) to return a feature on.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.energy_ratio_by_chunks
"""
name = "energy_ratio_by_chunks"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def __init__(self, num_segments, segment_focus):
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import \
longest_strike_above_mean
class LongestStrikeAboveMean(AggregationPrimitive):
"""Returns the length of the longest consecutive subsequence in x that is
bigger than the mean of x.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.longest_strike_above_mean
"""
name = "longest_strike_above_mean"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def get_function(self):
return longest_strike_above_mean
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import index_mass_quantile
class IndexMassQuantile(AggregationPrimitive):
"""Those apply features calculate the relative index i where q% of the mass
of the time series x lie left of i. For example for q = 50% this feature
calculator will return the mass center of the time series.
Args:
q (float) : Percentage of the mass of the time series.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.index_mass_quantile
"""
name = "index_mass_quantile"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def __init__(self, q):
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import linear_trend
class LinearTrend(AggregationPrimitive):
"""Calculate a linear least-squares regression for the values of the time
series versus the sequence from 0 to length of the time series minus one.
This feature assumes the signal to be uniformly sampled. It will not use
the time stamps to fit the model.
Args:
attr (str) : Controls which of the characteristics are returned.
Possible extracted attributes are:
['pvalue', 'rvalue', 'intercept', 'slope', 'stderr'].
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.linear_trend
"""
name = "linear_trend"
input_types = [Numeric]
return_type = Numeric
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import skewness
class Skewness(AggregationPrimitive):
"""Returns the sample skewness of x (calculated with the adjusted
Fisher-Pearson standardized moment coefficient G1).
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.skewness
"""
name = "skewness"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def get_function(self):
return skewness
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import spkt_welch_density
class SpktWelchDensity(AggregationPrimitive):
"""This feature calculator estimates the cross power spectral density of
the time series at different frequencies. To do so, the time series is
first shifted from the time domain to the frequency domain.
Args:
coeff (int) : Value of coefficient.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.spkt_welch_density
"""
name = "spkt_welch_density"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def __init__(self, coeff):
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import \
first_location_of_maximum
from ..utils import to_array
class FirstLocationOfMaximum(AggregationPrimitive):
"""Returns the first location of the maximum value of x. The position is
calculated relatively to the length of x.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.first_location_of_maximum
"""
name = "first_location_of_maximum"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def get_function(self):
def function(x):
return first_location_of_maximum(to_array(x))
return function
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import \
longest_strike_below_mean
class LongestStrikeBelowMean(AggregationPrimitive):
"""Returns the length of the longest consecutive subsequence in x that is
smaller than the mean of x.
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.longest_strike_below_mean
"""
name = "longest_strike_below_mean"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def get_function(self):
return longest_strike_below_mean
from featuretools.primitives import AggregationPrimitive
from featuretools.variable_types import Numeric
from tsfresh.feature_extraction.feature_calculators import count_above
class CountAbove(AggregationPrimitive):
"""Returns the percentage of values in x that are higher than t
Args:
t (float) : value used as threshold
Docstring source:
https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html#tsfresh.feature_extraction.feature_calculators.count_above
"""
name = "count_above"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False
def __init__(self, t):
self.t = t