Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé
Module « scipy.cluster.hierarchy »

Fonction optimal_leaf_ordering - module scipy.cluster.hierarchy

Signature de la fonction optimal_leaf_ordering

def optimal_leaf_ordering(Z, y, metric='euclidean') 

Description

help(scipy.cluster.hierarchy.optimal_leaf_ordering)

Given a linkage matrix Z and distance, reorder the cut tree.

Parameters
----------
Z : ndarray
    The hierarchical clustering encoded as a linkage matrix. See
    `linkage` for more information on the return structure and
    algorithm.
y : ndarray
    The condensed distance matrix from which Z was generated.
    Alternatively, a collection of m observation vectors in n
    dimensions may be passed as an m by n array.
metric : str or function, optional
    The distance metric to use in the case that y is a collection of
    observation vectors; ignored otherwise. See the ``pdist``
    function for a list of valid distance metrics. A custom distance
    function can also be used.

Returns
-------
Z_ordered : ndarray
    A copy of the linkage matrix Z, reordered to minimize the distance
    between adjacent leaves.

Examples
--------
>>> import numpy as np
>>> from scipy.cluster import hierarchy
>>> rng = np.random.default_rng()
>>> X = rng.standard_normal((10, 10))
>>> Z = hierarchy.ward(X)
>>> hierarchy.leaves_list(Z)
array([0, 3, 1, 9, 2, 5, 7, 4, 6, 8], dtype=int32)
>>> hierarchy.leaves_list(hierarchy.optimal_leaf_ordering(Z, X))
array([3, 0, 2, 5, 7, 4, 8, 6, 9, 1], dtype=int32)



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé