(self)
return optimal_count
Returns the optimal number of clusters for this dendrogram.

        If an optimal count hint was given at construction time, this
        property simply returns the hint. If such a count was not given,
        this method calculates the optimal number of clusters by maximizing
        the modularity along all the possible cuts in the dendrogram.
Returns the optimal number of clusters for this dendrogram.
Returns the optimal number of clusters for this dendrogram .
def optimal_count(self):
        """Returns the optimal number of clusters for this dendrogram.

        If an optimal count hint was given at construction time, this
        property simply returns the hint. If such a count was not given,
        this method calculates the optimal number of clusters by maximizing
        the modularity along all the possible cuts in the dendrogram.
        """
        if self._optimal_count is not None:
            return self._optimal_count

        n = self._graph.vcount()
        max_q, optimal_count = 0, 1
        for step in range(min(n - 1, len(self._merges))):
            membs = community_to_membership(self._merges, n, step)
            q = self._graph.modularity(membs, **self._modularity_params)
            if q > max_q:
                optimal_count = n - step
                max_q = q
        self._optimal_count = optimal_count
        return optimal_count
def optimal_count ( self ) : if self . _optimal_count is not None : return self . _optimal_count n = self . _graph . vcount ( ) max_q , optimal_count = 0 , 1 for step in range ( min ( n - 1 , len ( self . _merges ) ) ) : membs = community_to_membership ( self . _merges , n , step ) q = self . _graph . modularity ( membs , * * self . _modularity_params ) if q > max_q : optimal_count = n - step max_q = q self . _optimal_count = optimal_count return optimal_count