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())
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))
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]))
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())
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']
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))
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() ])
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. #