def test_distance_on(self, dataset):
        import numpy

        indices = orange.MakeRandomIndices2(dataset, min(20, len(dataset)))
        dataset = dataset.select(indices, 0)
        with member_set(self.distance_constructor, "ignore_class", True):
            mat = distance_matrix(dataset, self.distance_constructor)

        self.assertIsInstance(mat, Orange.misc.SymMatrix)
        self.assertEqual(mat.dim, len(dataset))

        m = numpy.array(list(mat))
        self.assertTrue((m >= 0.0).all())

        if dataset.domain.class_var:
            with member_set(self.distance_constructor, "ignore_class", False):
                try:
                    mat = distance_matrix(dataset, self.distance_constructor)
                except orange.KernelException, ex:
                    if "not supported" in str(ex):
                        return
                    else:
                        raise
            m1 = numpy.array(list(mat))
            self.assertTrue((m1 != m).all() or dataset, "%r does not seem to respect the 'ignore_class' flag")
Ejemplo n.º 2
0
    def test_distance_on(self, dataset):
        import numpy
        indices = orange.MakeRandomIndices2(dataset, min(20, len(dataset)))
        dataset = dataset.select(indices, 0)
        with member_set(self.distance_constructor, "ignore_class", True):
            mat = distance_matrix(dataset, self.distance_constructor)

        self.assertIsInstance(mat, Orange.misc.SymMatrix)
        self.assertEqual(mat.dim, len(dataset))

        m = numpy.array(list(mat))
        self.assertTrue((m >= 0.0).all())

        if dataset.domain.class_var:
            with member_set(self.distance_constructor, "ignore_class", False):
                try:
                    mat = distance_matrix(dataset, self.distance_constructor)
                except orange.KernelException, ex:
                    if "not supported" in str(ex):
                        return
                    else:
                        raise
            m1 = numpy.array(list(mat))
            self.assertTrue(
                (m1 != m).all() or dataset,
                "%r does not seem to respect the 'ignore_class' flag")
Ejemplo n.º 3
0
    def computeMatrix(self):
        if not self.data:
            return

        data = self.data
        if self.Metrics in [1, 2] and self.Absolute:
            if self.Metrics == 1:
                constructor = distance.PearsonRAbsolute()
            else:
                constructor = distance.SpearmanRAbsolute()
        else:
            constructor = self.metrics[self.Metrics][1]()
            constructor.normalize = self.Normalize

        self.error(0)
        self.progressBarInit()
        try:
            matrix = distance.distance_matrix(data, constructor,
                                              self.progressBarSet)
        except Orange.core.KernelException, ex:
            self.error(0, "Could not create distance matrix! %s" % str(ex))
            matrix = None
    def computeMatrix(self):
        if not self.data:
            return

        data = self.data
        if self.Metrics in [1, 2] and self.Absolute:
            if self.Metrics == 1:
                constructor = distance.PearsonRAbsolute()
            else:
                constructor = distance.SpearmanRAbsolute()
        else:
            constructor = self.metrics[self.Metrics][1]()
            constructor.normalize = self.Normalize

        self.error(0)
        self.progressBarInit()
        try:
            matrix = distance.distance_matrix(data, constructor,
                                              self.progressBarSet)
        except Orange.core.KernelException, ex:
            self.error(0, "Could not create distance matrix! %s" % str(ex))
            matrix = None
Ejemplo n.º 5
0
    def computeMatrix(self):
        self.warning(1)

        if not self.data:
            self.matrix = None
            return None

        data = self.data
        domain = data.domain
        metric = METRICS[self.metric]

        constructor = metric.constructor()

        if self.axis:
            if domain_has_discrete_attributes(domain):
                self.warning(1, "Input domain contains discrete attributes.")

            if self.data_t is None:
                self.data_t = transpose(self.data)

            data = self.data_t
        else:
            data = self.data

        if metric.normalize:
            constructor.normalize = bool(self.normalize)

        self.error(0)
        self.progressBarInit()
        try:
            matrix = distance.distance_matrix(
                data, constructor, self.progressBarSet
            )
        except Orange.core.KernelException, ex:
            self.error(0, "Could not create distance matrix! %s" % str(ex))
            matrix = None
Ejemplo n.º 6
0
    def computeMatrix(self):
        self.warning(1)

        if not self.data:
            self.matrix = None
            return None

        data = self.data
        domain = data.domain
        metric = METRICS[self.metric]

        constructor = metric.constructor()

        if self.axis:
            if domain_has_discrete_attributes(domain):
                self.warning(1, "Input domain contains discrete attributes.")

            if self.data_t is None:
                self.data_t = transpose(self.data)

            data = self.data_t
        else:
            data = self.data

        if metric.normalize:
            constructor.normalize = bool(self.normalize)

        self.error(0)
        self.progressBarInit()
        try:
            matrix = distance.distance_matrix(
                data, constructor, self.progressBarSet
            )
        except Orange.core.KernelException, ex:
            self.error(0, "Could not create distance matrix! %s" % str(ex))
            matrix = None
Ejemplo n.º 7
0
 def test_mds_on(self, data):
     matrix = distance_matrix(data, Euclidean)
     self.__mds_test_helper(matrix, proj_dim=1)
     self.__mds_test_helper(matrix, proj_dim=2)
     self.__mds_test_helper(matrix, proj_dim=3)
Ejemplo n.º 8
0
if os.path.exists(f1):
    os.remove(f1)

f2 = 'KMeans.csv'
if os.path.exists(f2):
    os.remove(f2)

data = Orange.data.Table('output.tab')
#matrix = Orange.misc.SymMatrix(len(data))
numDocs = len(data)
print "Count of documents in Reuters dataset: " + str(numDocs) + "\n"
print "1. Constructing Distance Matrices\n"

starter = time.time()
constructorEuclidean = distance.Euclidean()
EuclideanDistanceMat = distance.distance_matrix(
    data, distance_constructor=constructorEuclidean)
euclidean_hierarchical_clustering = clustering.hierarchical.HierarchicalClustering(
)
euclidean_hierarchical_clustering.linkage = clustering.hierarchical.AVERAGE
euclideanRoot = euclidean_hierarchical_clustering(EuclideanDistanceMat)
ender = time.time()
timer = ender - starter

starter1 = time.time()
constructorManhattan = distance.Manhattan()
ManhattanDistanceMat = distance.distance_matrix(
    data, distance_constructor=constructorManhattan)
manhattan_hierarchical_clustering = clustering.hierarchical.HierarchicalClustering(
)
manhattan_hierarchical_clustering.linkage = clustering.hierarchical.AVERAGE
manhattanRoot = manhattan_hierarchical_clustering(ManhattanDistanceMat)
Ejemplo n.º 9
0
 def test_mds_on(self, data):
     matrix = distance_matrix(data, Euclidean)
     self.__mds_test_helper(matrix, proj_dim=1)
     self.__mds_test_helper(matrix, proj_dim=2)
     self.__mds_test_helper(matrix, proj_dim=3)
Ejemplo n.º 10
0
from __future__ import division
import math
import sys
from Orange import data, distance, clustering


iris = data.Table("data1.tab")
arg_list = sys.argv
#matrix = misc.SymMatrix(len(iris))
if arg_list[1] =='0':
	matrix = distance.distance_matrix(iris, distance.Euclidean)
elif arg_list[1] =='1':
	matrix = distance.distance_matrix(iris, distance.Manhattan)
clustering1 = clustering.hierarchical.HierarchicalClustering()
clustering1.linkage = clustering.hierarchical.SINGLE
root = clustering1(matrix)

root.mapping.objects = iris





#===============================================================================
# def dictCreator(node,index):
#     if node.left!=None:
#         temp=node.left
#         list_doc=[]
#         for point in temp:
#             docid=str(point["DocID"])
#             docid=int(docid)