Skip to main content

DateFeaturesConverter

Converter
DashAI.back.converters.simple_converters.DateFeaturesConverter

Break a Date column into the calendar numbers hidden inside it.

A date is stored as text and a format, which no model can read. What a forecast needs from it is calendar position: which month, which weekday, which week of the year. This converter writes those out as integer columns named <column>_<feature>, one set per Date column in scope, and leaves the original column untouched.

The columns it produces are exactly what ExogenousForecastingTask takes beside the series: variables known for every period being forecast, since a calendar is known in advance. That is what separates them from an exogenous variable such as a price, which has to be planned or forecast first.

Cyclical encoding answers the one problem plain calendar numbers have. Month 12 and month 1 are one step apart in the calendar and eleven apart as integers, so a model reading the integer treats the year end as the furthest point from the year start. Encoding a periodic feature of period p as sin(2*pi*v/p) and cos(2*pi*v/p) puts consecutive values next to each other on a circle, which is where they belong.

Parameters

year : boolean, default=True
Add the calendar year of each date as an integer column.
month : boolean, default=True
Add the month of the year (1 to 12) as an integer column.
day : boolean, default=False
Add the day of the month (1 to 31) as an integer column.
weekday : boolean, default=True
Add the day of the week as an integer column, with Monday as 0 and Sunday as 6.
quarter : boolean, default=False
Add the quarter of the year (1 to 4) as an integer column.
week_of_year : boolean, default=False
Add the ISO week number (1 to 53) as an integer column.
day_of_year : boolean, default=False
Add the day of the year (1 to 366) as an integer column.
cyclical : boolean, default=False
Also encode every periodic feature that is on as a sine and cosine pair, so that December sits next to January instead of eleven units away from it.

Methods

fit(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DateFeaturesConverter'

Defined on DateFeaturesConverter

Find the Date columns in scope and name the columns to be added.

Parameters

x : DashAIDataset
The scoped columns.
y : DashAIDataset, optional
Ignored. Defaults to None.

Returns

DateFeaturesConverter
The fitted converter instance (self).

get_output_type(self, column_name: str = None) -> DashAI.back.types.dashai_data_type.DashAIDataType

Defined on DateFeaturesConverter

Return the type of one extracted column.

Parameters

column_name : str, optional
Name of the output column, such as "date_month" or "date_month_sin". Defaults to None.

Returns

DashAIDataType
Float for a sine or cosine column, Integer for every plain calendar feature.

transform(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DashAIDataset'

Defined on DateFeaturesConverter

Append the selected calendar features of every fitted date column.

Parameters

x : DashAIDataset
The dataset to transform.
y : DashAIDataset, optional
Ignored. Defaults to None.

Returns

DashAIDataset
The dataset with one integer column per selected feature and date column, plus a sine and cosine column per periodic feature when cyclical encoding is on. A row whose date is missing gets a null in every one of them.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_metadata(cls) -> 'Dict[str, Any]'

Defined on BaseConverter

Get metadata for the converter, used by the DashAI frontend.

Parameters

cls : type
The converter class (injected automatically by Python for classmethods).

Returns

Dict[str, Any]
Dictionary containing display name, short description, image preview path, category, icon, color, and whether the converter is supervised.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.