def runCA(self): self.contColAttr = colAttr = self.allAttrs[self.colAttr] self.contRowAttr = rowAttr = self.allAttrs[self.rowAttr] self.contingency = orange.ContingencyAttrAttr(rowAttr, colAttr, self.data) self.error(0) try: self.CA = orngCA.CA([[c for c in row] for row in self.contingency]) except numpy.linalg.LinAlgError: self.error(0, "Could not compute the mapping! " + str(ex)) self.graph.removeDrawingCurves(True, True, True) raise self.rowItems = [ s for s, v in self.contingency.outerDistribution.items() ] self.colItems = [ s for s, v in self.contingency.innerDistribution.items() ] self.xAxisCB.clear() self.yAxisCB.clear() self.axisCount = min(self.CA.D.shape) self.xAxisCB.addItems([str(i + 1) for i in range(self.axisCount)]) self.yAxisCB.addItems([str(i + 1) for i in range(self.axisCount)]) self.xPrincipalAxis = min(self.xPrincipalAxis, self.axisCount - 1) self.yPrincipalAxis = min(self.yPrincipalAxis, self.axisCount - 1) self.updateGraph()
def updateTables(self): if self.textData: if textCorpusModul: data = (self.attrRow == 'document' and [self.data] or [CategoryDocument(self.data).dataCD])[0] else: data = self.data metas = data.domain.getmetas(orngText.TEXTMETAID) lenMetas = len(metas) caList = [] for ex in data: cur = [0] * lenMetas for i, m in zip(range(lenMetas), metas.keys()): try: cur[i] = float(ex[m].native()) except: cur[i] = 0 caList.append(cur) if not self.CAloaded: self.CA = orngCA.CA(caList) hasNameAttribute = 'name' in [ i.name for i in data.domain.attributes ] hasCategoryAttribute = 'category' in [ i.name for i in data.domain.attributes ] if not hasCategoryAttribute: if not hasNameAttribute: self.tipsR = [ex['text'].value[:35] for ex in data] self.rowCategories = [(ex['text'].value[:35], "Row points") for ex in data] self.catColors = {"Row points": 0} else: self.tipsR = [ex['name'].native() for ex in data] self.rowCategories = [(ex['name'].native(), "Row points") for ex in data] self.catColors = {"Row points": 0} try: if hasCategoryAttribute: if not hasNameAttribute: self.tipsR = [ex['text'].value[:35] for ex in data] self.rowCategories = [(ex['text'].value[:35], ex['category'].native()) for ex in data] else: self.tipsR = [ex['name'].native() for ex in data] self.rowCategories = [(ex['name'].native(), ex['category'].native()) for ex in data] self.catColors = {} col = 0 colors = [0, 2, 3, 5, 6, 12] for ex in data: if ex['category'].native() not in list( self.catColors.keys()): self.catColors[ ex['category'].native()] = colors[col] col = (col + 1) % len(colors) except: if hasCategoryAttribute: if not hasNameAttribute: self.tipsR = [ex['text'].value[:35] for ex in data] self.rowCategories = [(ex['text'].value[:35], ex[-1].native()) for ex in data] else: self.tipsR = [ex.name for ex in data] self.rowCategories = [(ex.name, ex[-1].native()) for ex in data] self.catColors = {} col = 0 colors = [0, 2, 3, 5, 6, 12] for ex in data: if ex['category'].native() not in list( self.catColors.keys()): self.catColors[ ex['category'].native()] = colors[col] col = (col + 1) % len(colors) self.tipsC = [ a.name for a in data.domain.getmetas(orngText.TEXTMETAID).values() ] else: ca = orange.ContingencyAttrAttr(self.attrRow, self.attrCol, self.data) caList = [[col for col in row] for row in ca] if not self.CAloaded: self.CA = orngCA.CA(caList) self.tipsR = [s for s, v in ca.outerDistribution.items()] self.tipsC = [s for s, v in ca.innerDistribution.items()] self.rowCategories = [(t, "Row points") for t in self.tipsR] self.catColors = {"Row points": 0} del ca self.rowSlider.setMinimum(1) self.rowSlider.setMaximum(len(self.tipsR)) self.percRow = len(self.tipsR) > 100 and 0.5 * len(self.tipsR) or len( self.tipsR) self.colSlider.setMinimum(1) self.colSlider.setMaximum(len(self.tipsC)) self.percCol = len(self.tipsC) > 100 and 0.5 * len(self.tipsC) or len( self.tipsC) self.initAxesValues() self.tabsMain.setCurrentWidget(self.graph) self.calcRadius() del caList
# Description: Demonstrates the use of correspondence analysis # Category: correspondence, projection # Classes: CA # Uses: bridges.tab import orange import orngCA data = orange.ExampleTable("bridges") cm = orange.ContingencyAttrAttr("PURPOSE", "MATERIAL", data) ca = orngCA.CA([list(col) for col in cm]) def report(coors, labels): for coor, label in zip(coors, labels): print " %-10s (%.3f, %.3f)" % (label + ":", coor[0], coor[1]) print "PURPOSE" report(ca.getPrincipalColProfilesCoordinates(), data.domain["PURPOSE"].values) print print "MATERIAL" report(ca.getPrincipalRowProfilesCoordinates(), data.domain["PURPOSE"].values) print