def explain_weights_pipeline(estimator, feature_names=None, **kwargs):
    last_estimator = estimator.steps[-1][1]
    transform_pipeline = Pipeline(estimator.steps[:-1])
    if 'vec' in kwargs:
        feature_names = get_feature_names(feature_names, vec=kwargs.pop('vec'))
    feature_names = transform_feature_names(transform_pipeline, feature_names)
    out = explain_weights(last_estimator,
                          feature_names=feature_names,
                          **kwargs)
    out.estimator = repr(estimator)
    return out
Esempio n. 2
0
def _union_names(est, in_names=None):
    return [
        '{}:{}'.format(trans_name, feat_name)
        for trans_name, trans, _ in est._iter()
        for feat_name in transform_feature_names(trans, in_names)
    ]
Esempio n. 3
0
def _pipeline_names(est, in_names=None):
    names = in_names
    for name, trans in est.steps:
        if trans is not None:
            names = transform_feature_names(trans, names)
    return names