Skip to content

Class TypicalValue

  • Jump right in for a hands-on Open In Colab

Import

from NitroFE import TypicalValue

TypicalValue

Typical value is calculated as

\[ Typical\_Value[t]= \frac{ \max{(dataframe[t-lookback\_period \to t])} +\min{(dataframe[t-lookback\_period \to t])} + dataframe[t] }{3} \]

Methods

__init__(self, lookback_period=6, min_periods=None) special

Parameters:

Name Type Description Default
lookback_period int

Size of the rolling window for lookback, by default 6

6
min_periods int

Minimum number of observations in window required to have a value, by default None

None
Source code in nitrofe\time_based_features\indicator_features\_typicalvalue.py
def __init__(self, lookback_period: int = 6, min_periods: int = None):
    """
    Parameters
    ----------
    lookback_period : int, optional
        Size of the rolling window for lookback, by default 6
    min_periods : int, optional
        Minimum number of observations in window required to have a value, by default None
    """
    self.lookback_period = lookback_period
    self.min_periods = min_periods

fit(self, dataframe, first_fit=True)

For your training/initial fit phase (very first fit) use fit_first=True, and for any production/test implementation pass fit_first=False

Parameters:

Name Type Description Default
dataframe Union[pandas.core.frame.DataFrame, pandas.core.series.Series]

dataframe containing column values to create feature over

required
first_fit bool

Indicator features require past values for calculation. Use True, when calculating for training data (very first fit) Use False, when calculating for subsequent testing/production data { in which case the values, which were saved during the last phase, will be utilized for calculation }, by default True

True
Source code in nitrofe\time_based_features\indicator_features\_typicalvalue.py
def fit(self, dataframe: Union[pd.DataFrame, pd.Series], first_fit: bool = True):
    """
    For your training/initial fit phase (very first fit) use fit_first=True, and for any production/test implementation pass fit_first=False

    Parameters
    ----------
    dataframe : Union[pd.DataFrame, pd.Series]
        dataframe containing column values to create feature over
    first_fit : bool, optional
        Indicator features require past values for calculation.
        Use True, when calculating for training data (very first fit)
        Use False, when calculating for subsequent testing/production data { in which case the values, which
        were saved during the last phase, will be utilized for calculation }, by default True

    """

    if first_fit:
        self._typical_value_object = weighted_window_features()

    _typical_value = self._typical_value_object._template_feature_calculation(
        function_name="typical_value",
        win_function=_identity_window,
        first_fit=first_fit,
        dataframe=dataframe,
        window=self.lookback_period,
        min_periods=self.min_periods,
        symmetric=None,
        operation=self._calculate_typical_value,
        operation_args=(),
    )

    return _typical_value

References