Exemple #1
0
    def __init__(self, wrapped, max_plotted_predictions=None):
        if max_plotted_predictions is None:
            max_plotted_predictions = 10

        FeatureUnion.__init__(self, [Identity(), wrapped],
                              joiner=PlotPredictionsJoiner(
                                  plot_predictions, max_plotted_predictions),
                              n_jobs=1)
Exemple #2
0
    def __init__(self, steps, hyperparams=None):
        FeatureUnion.__init__(self, steps, joiner=SelectNonEmptyDataInputs())

        self._make_all_steps_optional()

        if hyperparams is None:
            choices = list(self.keys())[:-1]
            self.set_hyperparams({CHOICE_HYPERPARAM: choices[0]})
            self.set_hyperparams_space({CHOICE_HYPERPARAM: Choice(choices)})
Exemple #3
0
    def __init__(self, steps, hyperparams=None):
        FeatureUnion.__init__(self, steps)

        if hyperparams is None:
            self.set_hyperparams(HyperparameterSamples({}))
        else:
            self.set_hyperparams(hyperparams)

        self._make_all_steps_optional()
Exemple #4
0
    def __init__(self, steps, hyperparams=None):
        FeatureUnion.__init__(self, steps)

        self._make_all_steps_optional()

        if hyperparams is None:
            self.set_hyperparams(HyperparameterSamples({
                CHOICE_HYPERPARAM: list(self.keys())[0]
            }))
Exemple #5
0
    def __init__(self, column_chooser_steps_as_tuple: ColumnChooserTupleList, n_dimension: int = 3):
        # Make unique names from the indices in case we have many steps for transforming the same column(s).
        self.string_indices = [
            str(name) + "_" + str(step.__class__.__name__)
            for name, step in column_chooser_steps_as_tuple
        ]

        FeatureUnion.__init__(self, [
            (string_indices, Pipeline([
                ColumnsSelectorND(indices, n_dimension=n_dimension),
                step
            ]))
            for string_indices, (indices, step) in zip(self.string_indices, column_chooser_steps_as_tuple)
        ])
Exemple #6
0
    def __init__(self, steps, hyperparams=None):
        FeatureUnion.__init__(self, steps, joiner=SelectNonEmptyDataInputs())

        self._make_all_steps_optional()

        choices = list(self.keys())[:-1]

        if hyperparams is None:
            self.update_hyperparams(
                {ChooseOneStepOf.CHOICE_HYPERPARAM: choices[0]})
        else:
            self.update_hyperparams(
                {ChooseOneStepOf.CHOICE_HYPERPARAM: hyperparams})
        self.update_hyperparams_space(
            {ChooseOneStepOf.CHOICE_HYPERPARAM: Choice(choices)})
Exemple #7
0
def test_feature_union_should_transform_with_zip_features():
    p = Pipeline(
        [FeatureUnion([
            Identity(),
            Identity(),
        ], joiner=ZipFeatures())])
    data_inputs = np.random.randint(low=0, high=100, size=(2, 20))

    outputs = p.transform(data_inputs)

    assert np.array_equal(outputs, np.stack([data_inputs, data_inputs],
                                            axis=1))
Exemple #8
0
def test_feature_union_should_transform_with_numpy_transpose():
    p = Pipeline(
        [FeatureUnion([
            Identity(),
            Identity(),
        ], joiner=NumpyTranspose())])
    data_inputs = np.random.randint((1, 20))

    outputs = p.transform(data_inputs)

    assert np.array_equal(outputs,
                          np.array([data_inputs, data_inputs]).transpose())
Exemple #9
0
def test_feature_union_should_fit_transform_with_numpy_transpose():
    p = Pipeline(
        [FeatureUnion([
            Identity(),
            Identity(),
        ], joiner=NumpyTranspose())])
    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.array([data_inputs, data_inputs]).transpose())
Exemple #10
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]))
Exemple #11
0
def test_feature_union_should_apply_to_self_and_sub_steps():
    p = Pipeline(
        [FeatureUnion([
            Identity(),
            Identity(),
        ], joiner=NumpyTranspose())])

    p.apply(lambda step: step._set_hyperparams(
        HyperparameterSamples({'applied': True})))

    assert p.hyperparams['applied']
    assert p['FeatureUnion'].hyperparams['applied']
    assert p['FeatureUnion'][0].hyperparams['applied']
    assert p['FeatureUnion'][1].hyperparams['applied']
    assert p['FeatureUnion'][2].hyperparams['applied']
Exemple #12
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))
Exemple #13
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()
     ])
Exemple #14
0
    ColumnTransformer([
        ("hour", periodic_spline_transformer(24, n_splines=8)),
        ("workingday", FunctionTransformer(lambda x: x == "True")),
    ],
                      n_dimension=2),
    PolynomialFeatures(degree=2, interaction_only=True, include_bias=False)
])

# %%
# Those features are then combined with the ones already computed in the
# previous spline-base pipeline. We can observe a nice performance improvemnt
# by modeling this pairwise interaction explicitly:

cyclic_spline_interactions_pipeline = Pipeline([
    FeatureUnion([
        cyclic_spline_transformer,
        hour_workday_interaction,
    ]),
    RidgeCV(alphas=alphas),
])
evaluate(cyclic_spline_interactions_pipeline, X, y, cv=ts_cv)

# %%
# Modeling non-linear feature interactions with kernels
# -----------------------------------------------------
#
# The previous analysis highlighted the need to model the interactions between
# `"workingday"` and `"hours"`. Another example of a such a non-linear
# interaction that we would like to model could be the impact of the rain that
# might not be the same during the working days and the week-ends and holidays
# for instance.
#
Exemple #15
0
 def __init__(self, steps, joiner: NonFittableMixin = None):
     if joiner is None:
         joiner = NumpyConcatenateOnCustomAxisIfNotEmpty(axis=-1)
     FeatureUnion.__init__(self, steps_as_tuple=steps, joiner=joiner)
     self.set_hyperparams(HyperparameterSamples({}))
     self._make_all_steps_optional()
Exemple #16
0
 def __init__(self, steps):
     FeatureUnion.__init__(self, steps_as_tuple=steps, joiner=NumpyConcatenateOnCustomAxisIfNotEmpty(axis=-1))
     self.set_hyperparams(HyperparameterSamples({}))
     self._make_all_steps_optional()
Exemple #17
0
 def __init__(self, steps):
     FeatureUnion.__init__(self, steps)
     self.set_hyperparams(HyperparameterSamples({}))
     self._make_all_steps_optional()