def convert(model, input_features, output_features):
    """Convert a _imputer model to the protobuf spec.

    Parameters
    ----------
    model: Imputer
        A trained Imputer model.

    input_features: str
        Name of the input column.

    output_features: str
        Name of the output column.

    Returns
    -------
    model_spec: An object of type Model_pb.
        Protobuf representation of the model
    """

    _INTERMEDIATE_FEATURE_NAME = "__sparse_vector_features__"

    n_dimensions = len(model.feature_names_)
    input_features = process_or_validate_features(input_features)

    # Ensure that the output_features are also solid.
    output_features = process_or_validate_features(output_features, n_dimensions)

    # The DictVectorizer in the framework outputs a sparse dictionary
    # of index to value due to other considerations, but we are expecting
    # the output of this to be a dense feature vector.  To make that happen,
    # put a feature_vectorizer immediately after the dict vectorizer.
    pline = Pipeline(input_features, output_features)

    # Set the basic model parameters of the dict vectorizer component.
    dv_spec = proto.Model_pb2.Model()
    dv_spec.specificationVersion = SPECIFICATION_VERSION

    # Set up the dict vectorizer parameters
    tr_spec = dv_spec.dictVectorizer
    is_str = None
    for feature_name in model.feature_names_:
        if isinstance(feature_name, str):
            if is_str is False:
                raise ValueError("Mapping of DictVectorizer mixes int and str types.")

            tr_spec.stringToIndex.vector.append(feature_name)
            is_str is True

        if isinstance(feature_name, int):
            if is_str is True:
                raise ValueError("Mapping of DictVectorizer mixes int and str types.")

            tr_spec.int64ToIndex.vector.append(feature_name)
            is_str is False

    intermediate_features = [
        (_INTERMEDIATE_FEATURE_NAME, datatypes.Dictionary(key_type=int))
    ]

    # Set the interface for the dict vectorizer with the input and the
    # intermediate output
    set_transform_interface_params(dv_spec, input_features, intermediate_features)

    pline.add_model(dv_spec)

    # Follow the dict vectorizer by a feature_vectorizer to change the sparse
    # output layer into a dense vector as expected.
    fvec, _num_out_dim = create_feature_vectorizer(
        intermediate_features,
        output_features[0][0],
        {"__sparse_vector_features__": n_dimensions},
    )

    pline.add_model(fvec)

    return _MLModel(pline.spec)
Convert a _imputer model to the protobuf spec.

    Parameters
    ----------
    model: Imputer
        A trained Imputer model.

    input_features: str
        Name of the input column.

    output_features: str
        Name of the output column.

    Returns
    -------
    model_spec: An object of type Model_pb.
        Protobuf representation of the model
    
coremltools/converters/sklearn/_dict_vectorizer.py