tensortrade.pipeline.transformers.mutual_information module¶
- class tensortrade.pipeline.transformers.mutual_information.MutualInformationTransformer(num_features: int = 20, seed: int = 42, *, target_column: str = 'close', target_shift: int = 3, n_jobs: int = -1)[source]¶
Bases:
AbstractTransformer
Transformer for selecting top features based on mutual information with a target variable.
- Parameters:
num_features (int) – The number of top features to select based on mutual information scores. (Default = 20)
seed (int) – The seed used for the mutual information regression. (Default = 42)
target_column (str) – The name of the target column on which the mutual information score should be calculated. (Default = ‘close’)
target_shift (int) – The number of periods to shift the target column to create the prediction target. (Default = 3)
n_jobs (int) – The number of parallel jobs to run. If -1, all processors are used. (Default = -1)
- transform(df: DataFrame) DataFrame [source]¶
Transforms the input DataFrame by selecting the top features based on mutual information with the target variable.
- Parameters:
df (DataFrame) – The input DataFrame containing the features and target column.
- Returns:
A DataFrame reduced to the top features based on mutual information scores.
- Return type:
DataFrame
- Raises:
ValueError – If the number of values in the DataFrame is less than 5 after shifting.