(y_true, y_pred, graph)
Helper context manager for using the hierarchical evaluation metrics
    defined in this model.

    Briefly, the evaluation metrics expect data in a binarized multi-label format,
    the same as returned when using scikit-learn's MultiLabelBinarizer.

    This method therefore encapsulate the boilerplate required to fit such a
    label transformation on the data we wish to evaluate (y_true, y_pred) as well as
    applying it to the class hierarchy itself (graph), by relabeling the nodes.

    See the examples/classify_digits.py file for example usage.

    Parameters
    ----------
    y_true : array-like, shape = [n_samples, 1].
        ground truth targets

    y_pred : array-like, shape = [n_samples, 1].
        predicted targets

    graph : the class hierarchy graph, given as a `networkx.DiGraph` instance

    Returns
    -------
    y_true_ : array-like, shape = [n_samples, n_classes].
        ground truth targets, transformed to a binary multi-label matrix format.
    y_pred_ : array-like, shape = [n_samples, n_classes].
        predicted targets, transformed to a binary multi-label matrix format.
    graph_ : the class hierarchy graph, given as a `networkx.DiGraph` instance,
        transformed to use the (integer) IDs fitted by the multi label binarizer.
Helper context manager for using the hierarchical evaluation metrics
    defined in this model.
Helper context manager for using the hierarchical evaluation metrics defined in this model .
def multi_labeled(y_true, y_pred, graph):
    """
    Helper context manager for using the hierarchical evaluation metrics
    defined in this model.

    Briefly, the evaluation metrics expect data in a binarized multi-label format,
    the same as returned when using scikit-learn's MultiLabelBinarizer.

    This method therefore encapsulate the boilerplate required to fit such a
    label transformation on the data we wish to evaluate (y_true, y_pred) as well as
    applying it to the class hierarchy itself (graph), by relabeling the nodes.

    See the examples/classify_digits.py file for example usage.

    Parameters
    ----------
    y_true : array-like, shape = [n_samples, 1].
        ground truth targets

    y_pred : array-like, shape = [n_samples, 1].
        predicted targets

    graph : the class hierarchy graph, given as a `networkx.DiGraph` instance

    Returns
    -------
    y_true_ : array-like, shape = [n_samples, n_classes].
        ground truth targets, transformed to a binary multi-label matrix format.
    y_pred_ : array-like, shape = [n_samples, n_classes].
        predicted targets, transformed to a binary multi-label matrix format.
    graph_ : the class hierarchy graph, given as a `networkx.DiGraph` instance,
        transformed to use the (integer) IDs fitted by the multi label binarizer.

    """
    mlb = MultiLabelBinarizer()
    all_classes = [
        node
        for node in graph.nodes
        if node != ROOT
    ]
    # Nb. we pass a (singleton) list-within-a-list as fit() expects an iterable-of-iterables
    mlb.fit([all_classes])

    node_label_mapping = {
        old_label: new_label
        for new_label, old_label in enumerate(list(mlb.classes_))
    }

    yield (
        mlb.transform(y_true),
        mlb.transform(y_pred),
        relabel_nodes(graph, node_label_mapping),
    )
def multi_labeled ( y_true , y_pred , graph ) : mlb = MultiLabelBinarizer ( ) all_classes = [ node for node in graph . nodes if node != ROOT ] # Nb. we pass a (singleton) list-within-a-list as fit() expects an iterable-of-iterables mlb . fit ( [ all_classes ] ) node_label_mapping = { old_label : new_label for new_label , old_label in enumerate ( list ( mlb . classes_ ) ) } yield ( mlb . transform ( y_true ) , mlb . transform ( y_pred ) , relabel_nodes ( graph , node_label_mapping ) , )