Temporal Features

flood_forecast.preprocessing.temporal_feats.make_temporal_features(features_list: Dict, dt_column: str, df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

A function that creates temporal features

Parameters
  • features_list (Dict) – A list of features in the form of a dictionary

  • dt_column (str) – [description]

  • df (pd.DataFrame) – A data frame with a datetime column

Returns

The DF with several new columns added

Return type

pd.DataFrame

flood_forecast.preprocessing.temporal_feats.create_feature(key: str, value: str, df: pandas.core.frame.DataFrame, dt_column: str)[source]

Function to create temporal feature. Uses dict to make val.

Parameters
  • key (str) – The datetime feature you would like to create

  • value (str) – The type of feature you would like to create (cyclical or numerical)

  • df (pd.DataFrame) – The Pandas dataframe with the datetime

  • dt_column (str) – The name of the datetime column

Returns

The dataframe with the newly added column

Return type

pd.DataFrame

flood_forecast.preprocessing.temporal_feats.feature_fix(preprocess_params: Dict, dt_column: str, df: pandas.core.frame.DataFrame)[source]

Adds temporal features

Parameters
  • preprocess_params (Dict) – Dictionary of temporal parameters e.g. {“day”:”numerical”}

  • dt_column – The column name of the data

  • df (pd.DataFrame) – The dataframe to add the temporal features to

Returns

Returns the new data-frame and a list of the new column names

Return type

Tuple(pd.Dataframe, List[str])

flood_forecast.preprocessing.temporal_feats.cyclical(df: pandas.core.frame.DataFrame, feature_column: str) pandas.core.frame.DataFrame[source]

A function to create cyclical encodings for Pandas data-frames.

Parameters
  • df (pd.DataFrame) – A Pandas Dataframe where you want the dt encoded

  • feature_column (str) – The name of the feature column. Should be either (day_of_week, hour, month, year)

Returns

The dataframe with three new columns: norm_feature, cos_feature, sin_feature

Return type

pd.DataFrame