Temporal Features

flood_forecast.preprocessing.temporal_feats.create_feature(key: str, value: str, df: 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 from the datetime column.

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

  • df (pd.DataFrame) – The Pandas dataframe with thes 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: 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: DataFrame, feature_column: str) 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