Ejemplo n.º 1
0
def score_conditional_entropy(km):
    """UNIMPLEMENTED cluster quality measured by conditional entropy"""
    raise NotImplemented

def score_within_cluster_distance(km):
    """UNIMPLEMENTED weighted average within-cluster pairwise distance"""
    raise NotImplemented

score_within_cluster_distance.minimize = True

def score_between_cluster_distance(km):
    """Sum of distances from elements to 'nearest miss' centroids"""
    return sum(min(km.distance(c, d) for j,c in enumerate(km.centroids) if j!=km.clusters[i]) for i,d in enumerate(km.data))

from Orange.misc import deprecated_function_name
score_betweenClusterDistance = deprecated_function_name(score_between_cluster_distance)

def score_silhouette(km, index=None):
    """Returns an average silhouette score of data instances.
    
    :param km: a k-means clustering object.
    :type km: :class:`KMeans`

    :param index: if given, the functon returns just the silhouette score of that particular data instance.
    :type index: integer
    """
    
    if index == None:
        return avg([score_silhouette(km, i) for i in range(len(km.data))])
    cind = km.clusters[index]
    a = avg([km.distance(km.data[index], ex) for i, ex in enumerate(km.data) if
Ejemplo n.º 2
0
        the same experiment always gives the same results, despite
        pseudo-randomness.random seed.
    :type seed: int
    :param call_compare_on_1st: If set, :obj:`BestOnTheFly` will suppose
        that the candidates are lists are tuples, and it will call compare
        with the first element of the tuple.
    :type call_compare_on_1st: bool
    :rtype: object
    
    """
    bs=BestOnTheFly(compare, seed, call_compare_on_1st)
    for i in x:
        bs.candidate(i)
    return bs.winner()

selectBest = deprecated_function_name(select_best)


@deprecated_keywords({"callCompareOn1st": "call_compare_on_1st"})
def select_best_index(x, compare=cmp, seed = 0, call_compare_on_1st = False):
    """Similar to :obj:`selectBest` except that it doesn't return the best object
    but its index in the list x.
    """
    bs=BestOnTheFly(compare, seed, call_compare_on_1st)
    for i in x:
        bs.candidate(i)
    return bs.winner_index()

selectBestIndex = deprecated_function_name(select_best_index)

Ejemplo n.º 3
0
    raise NotImplemented


score_within_cluster_distance.minimize = True


def score_between_cluster_distance(km):
    """Sum of distances from elements to 'nearest miss' centroids"""
    return sum(
        min(
            km.distance(c, d) for j, c in enumerate(km.centroids)
            if j != km.clusters[i]) for i, d in enumerate(km.data))


from Orange.misc import deprecated_function_name
score_betweenClusterDistance = deprecated_function_name(
    score_between_cluster_distance)


def score_silhouette(km, index=None):
    """Returns an average silhouette score of data instances.
    
    :param km: a k-means clustering object.
    :type km: :class:`KMeans`

    :param index: if given, the functon returns just the silhouette score of that particular data instance.
    :type index: integer
    """

    if index == None:
        return avg([score_silhouette(km, i) for i in range(len(km.data))])
    cind = km.clusters[index]
Ejemplo n.º 4
0
        pseudo-randomness.random seed.
    :type seed: int
    :param call_compare_on_1st: If set, :obj:`BestOnTheFly` will suppose
        that the candidates are lists are tuples, and it will call compare
        with the first element of the tuple.
    :type call_compare_on_1st: bool
    :rtype: object
    
    """
    bs = BestOnTheFly(compare, seed, call_compare_on_1st)
    for i in x:
        bs.candidate(i)
    return bs.winner()


selectBest = deprecated_function_name(select_best)


@deprecated_keywords({"callCompareOn1st": "call_compare_on_1st"})
def select_best_index(x, compare=cmp, seed=0, call_compare_on_1st=False):
    """Similar to :obj:`selectBest` except that it doesn't return the best object
    but its index in the list x.
    """
    bs = BestOnTheFly(compare, seed, call_compare_on_1st)
    for i in x:
        bs.candidate(i)
    return bs.winner_index()


selectBestIndex = deprecated_function_name(select_best_index)