I have the following code which works ok:
def func1():
return Pipeline([('cont_inf_replacer', replaceInf()),
])
make_column_transformer((func1(), features['cat1']),
(func2(), features['cat2']),
(func3(), features['cat3'])
)
Now, I would like to pass the function argument as a variable
func_dict = {'cat1': func1, 'cat2':func2, 'cat3': func3}
for c in features.keys():
arg_tuple += (func_dict[c], features[c])
make_column_transformer(arg_tuple)
I would expect arg_tuple should expand/unpack into
func1(), features['cat1']),
(func2(), features['cat2']),
(func2(), features['cat3'])
But received the following error. I did a search and could not find the proper solution
ValueError: not enough values to unpack (expected 2, got 1)
This is how make_column_transformer() is defined:
make_column_transformer(*transformers, **kwargs)
Unpack with *arg_tuple seems to work (no error when call make_column_transfer, but the results are different, see below)
make_column_transformer((func1(),features['_cat_'])): output
ColumnTransformer(n_jobs=None, remainder='drop', sparse_threshold=0.3,
transformer_weights=None,
transformers=[('pipeline', Pipeline(memory=None,
steps=[('cont_inf_replacer', <__main__.replaceInf object at 0x7f87d19d6ba8>)]), ['cat1', 'cat2', 'cat3'])])
With *arg_tuple,
make_column_transformer(*arg_tuple)
ColumnTransformer(n_jobs=None, remainder='drop', sparse_threshold=0.3,
transformer_weights=None,
transformers=[('function', <function _pip_cont at 0x7f87d1a006a8>, ['cat1', 'cat2', 'cat3'])])
make_column_transformerwill do?make_column_transformer(*arg_tuple)?func_dicyou havefunc1instead offunc1()etc