Ejemplo n.º 1
0
    def __init__(self,
                 minimum_training_size,
                 validation_window_size=None,
                 padding_between_training_and_validation=0,
                 drop_remainder=False,
                 scoring_function=r2_score,
                 joiner=NumpyConcatenateInnerFeatures()):
        """
        Create a anchored walk forward time series cross validation object.

        The size of the validation split is defined by `validation_window_size`.
        The difference in start position between two consecutive validation split is also equal to
        `validation_window_size`.

        :param minimum_training_size: size of the smallest training split.
        :param validation_window_size: size of each validation split and also the time step taken between each
            forward roll, by default None. If None : It takes the value `minimum_training_size`.
        :param padding_between_training_and_validation: the size of the padding between the end of the training split
            and the start of the validation split, by default 0.
        :param drop_remainder: drop the last split if the last validation split does not coincide
            with a full validation_window_size, by default False.
        :param scoring_function: scoring function use to validate performance if it is not None, by default r2_score,
        :param joiner the joiner callable that can join the different result together.
        :return: WalkForwardTimeSeriesCrossValidation instance.
        """
        BaseCrossValidationWrapper.__init__(self,
                                            scoring_function=scoring_function,
                                            joiner=joiner)
        self.minimum_training_size = minimum_training_size
        # If validation_window_size is None, we give the same value as training_window_size.
        self.validation_window_size = validation_window_size or self.minimum_training_size
        self.padding_between_training_and_validation = padding_between_training_and_validation
        self.drop_remainder = drop_remainder
        self._validation_initial_start = self.minimum_training_size + self.padding_between_training_and_validation
Ejemplo n.º 2
0
def test_feature_union_should_transform_with_concatenate_inner_features():
    p = Pipeline([
        FeatureUnion([
            Identity(),
            Identity(),
        ],
                     joiner=NumpyConcatenateInnerFeatures())
    ])
    data_inputs = np.random.randint((1, 20))

    outputs = p.transform(data_inputs)

    assert np.array_equal(outputs, np.concatenate([data_inputs, data_inputs]))
Ejemplo n.º 3
0
def test_feature_union_should_fit_transform_with_concatenate_inner_features():
    p = Pipeline([
        FeatureUnion([
            Identity(),
            Identity(),
        ],
                     joiner=NumpyConcatenateInnerFeatures())
    ])
    data_inputs = np.random.randint(low=0, high=100, size=(2, 20))
    expected_outputs = None

    p, outputs = p.fit_transform(data_inputs, expected_outputs)

    assert np.array_equal(outputs,
                          np.concatenate([data_inputs, data_inputs], axis=-1))
Ejemplo n.º 4
0
    def __init__(self,
                 steps_as_tuple: NamedTupleList,
                 joiner: NonFittableMixin = NumpyConcatenateInnerFeatures(),
                 n_jobs: int = None,
                 backend: str = "threading"):
        """
        Create a feature union.

        :param steps_as_tuple: the NamedTupleList of steps to process in parallel and to join.
        :param joiner: What will be used to join the features. For example, ``NumpyConcatenateInnerFeatures()``.
        :param n_jobs: The number of jobs for the parallelized ``joblib.Parallel`` loop in fit and in transform.
        :param backend: The type of parallelization to do with ``joblib.Parallel``. Possible values: "loky", "multiprocessing", "threading", "dask" if you use dask, and more.
        """
        TruncableSteps.__init__(self, steps_as_tuple)
        self.joiner = joiner
        self.n_jobs = n_jobs
        self.backend = backend
Ejemplo n.º 5
0
 def __init__(self):
     super().__init__([
         Pipeline([
             NumpyFFT(),
             NumpyAbs(),
             FeatureUnion(
                 [
                     NumpyFlattenDatum(
                     ),  # Reshape from 3D to flat 2D: flattening data except on batch size
                     FFTPeakBinWithValue(
                     )  # Extract 2D features from the 3D FFT bins
                 ],
                 joiner=NumpyConcatenateInnerFeatures())
         ]).set_name('FFT'),
         NumpyMean(),
         NumpyMedian(),
         NumpyMin(),
         NumpyMax()
     ])
Ejemplo n.º 6
0
 def __init__(self,
              steps_as_tuple: NamedTupleList,
              joiner: BaseTransformer = None,
              n_jobs: int = None,
              backend: str = "threading",
              cache_folder_when_no_handle: str = None):
     """
     Create a feature union.
     :param steps_as_tuple: the NamedTupleList of steps to process in parallel and to join.
     :param joiner: What will be used to join the features. ``NumpyConcatenateInnerFeatures()`` is used by default.
     :param n_jobs: The number of jobs for the parallelized ``joblib.Parallel`` loop in fit and in transform.
     :param backend: The type of parallelization to do with ``joblib.Parallel``. Possible values: "loky", "multiprocessing", "threading", "dask" if you use dask, and more.
     """
     if joiner is None:
         joiner = NumpyConcatenateInnerFeatures()
     steps_as_tuple.append(('joiner', joiner))
     TruncableSteps.__init__(self, steps_as_tuple)
     ForceHandleOnlyMixin.__init__(self,
                                   cache_folder=cache_folder_when_no_handle)
     self.n_jobs = n_jobs
     self.backend = backend
Ejemplo n.º 7
0
 def __init__(self):
     super().__init__(
         [NumpyArgMax(axis=-2), NumpyMax(axis=-2)],
         joiner=NumpyConcatenateInnerFeatures())