Example #1
0
 def cbShowDistributions(self):
     for ti in range(self.tabs.count()):
         color_schema = self.discPalette if self.colorByClass else None
         delegate = OWGUI.TableBarItem(self, color=self.distColor,
                                       color_schema=color_schema) \
                    if self.showDistributions else QStyledItemDelegate(self)
         self.tabs.widget(ti).setItemDelegate(delegate)
     tab = self.tabs.currentWidget()
     if tab:
         tab.reset()
 def setDataModel(self, data):
     if data is not None and self.outvar is not None:
         if self.ShowAttributeMethod == 1: # Show only the class column
             data = orange.ExampleTable(orange.Domain([self.outvar]), data)
         elif not data.domain.classVar: # add outVar as class (all unknown values) to data
             domain = orange.Domain(data.domain.attributes + [self.outvar])
             domain.addmetas(data.domain.getmetas())
             data = orange.ExampleTable(domain, data)
             
         dist = getCached(data, orange.DomainBasicAttrStat, (data,))
         self.dataModel = ExampleTableModel(data, dist, None)
         self.dataView.setModel(self.dataModel)
         self.dataView.setItemDelegate(OWGUI.TableBarItem(self, data, color = Qt.lightGray))
         count = self.dataModel.columnCount()
         if count:
             self.dataView.scrollTo(self.dataModel.index(0, count - 1))
         self.dataView.show()
     else:
         self.clear()
     self.updateSpliter()
Example #3
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "Predictions")

        self.callbackDeposit = []
        self.inputs = [("Examples", ExampleTable, self.setData),
                       ("Predictors", orange.Classifier, self.setPredictor,
                        Multiple)]
        self.outputs = [("Predictions", ExampleTable)]
        self.predictors = {}

        # saveble settings
        self.showProb = 1
        self.showClass = 1
        self.ShowAttributeMethod = 0
        self.sendOnChange = 1
        self.classes = []
        self.selectedClasses = []
        self.loadSettings()
        self.datalabel = "N/A"
        self.predictorlabel = "N/A"
        self.tasklabel = "N/A"
        self.precision = 2
        self.outvar = None  # current output variable (set by the first predictor/data set send in)

        self.data = None

        # GUI - Options

        # Options - classification
        ibox = OWGUI.widgetBox(self.controlArea, "Info")
        OWGUI.label(ibox, self, "Data: %(datalabel)s")
        OWGUI.label(ibox, self, "Predictors: %(predictorlabel)s")
        OWGUI.label(ibox, self, "Task: %(tasklabel)s")
        OWGUI.separator(self.controlArea)

        self.copt = OWGUI.widgetBox(self.controlArea,
                                    "Options (classification)")
        self.copt.setDisabled(1)
        OWGUI.checkBox(self.copt,
                       self,
                       'showProb',
                       "Show predicted probabilities",
                       callback=self.updateTableOutcomes)

        #        self.lbClasses = OWGUI.listBox(self.copt, self, selectionMode = QListWidget.MultiSelection, callback = self.updateTableOutcomes)

        self.lbcls = OWGUI.listBox(
            self.copt,
            self,
            "selectedClasses",
            "classes",
            callback=[self.updateTableOutcomes, self.checksendpredictions],
            selectionMode=QListWidget.MultiSelection)
        self.lbcls.setFixedHeight(50)

        OWGUI.spin(self.copt,
                   self,
                   "precision",
                   1,
                   6,
                   label="No. of decimals: ",
                   orientation=0,
                   callback=self.updateTableOutcomes)

        OWGUI.checkBox(
            self.copt,
            self,
            'showClass',
            "Show predicted class",
            callback=[self.updateTableOutcomes, self.checksendpredictions])

        # Options - regression
        # self.ropt = QVButtonGroup("Options (regression)", self.controlArea)
        # OWGUI.checkBox(self.ropt, self, 'showClass', "Show predicted class",
        #                callback=[self.updateTableOutcomes, self.checksendpredictions])
        # self.ropt.hide()

        OWGUI.separator(self.controlArea)

        self.att = OWGUI.widgetBox(self.controlArea, "Data attributes")
        OWGUI.radioButtonsInBox(self.att,
                                self,
                                'ShowAttributeMethod',
                                ['Show all', 'Hide all'],
                                callback=self.updateAttributes)
        self.att.setDisabled(1)
        OWGUI.rubber(self.controlArea)

        OWGUI.separator(self.controlArea)
        self.outbox = OWGUI.widgetBox(self.controlArea, "Output")

        self.commitBtn = OWGUI.button(self.outbox,
                                      self,
                                      "Send Predictions",
                                      callback=self.sendpredictions)
        OWGUI.checkBox(self.outbox, self, 'sendOnChange', 'Send automatically')

        self.outbox.setDisabled(1)

        # GUI - Table
        self.table = OWGUI.table(self.mainArea,
                                 selectionMode=QTableWidget.NoSelection)

        self.table.setItemDelegate(OWGUI.TableBarItem(self))

        self.header = self.table.horizontalHeader()
        self.vheader = self.table.verticalHeader()
        # manage sorting (not correct, does not handle real values)
        self.connect(self.header, SIGNAL("sectionPressed(int)"), self.sort)
        self.sortby = -1
        self.resize(800, 600)
Example #4
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'k-Means Clustering')

        self.inputs = [("Examples", ExampleTable, self.setData)]
        self.outputs = [("Examples", ExampleTable),
                        ("Centroids", ExampleTable)]

        #set default settings
        self.K = 2
        self.optimized = True
        self.optimizationFrom = 2
        self.optimizationTo = 5
        self.scoring = 0
        self.distanceMeasure = 0
        self.initializationType = 0
        self.restarts = 1
        self.classifySelected = 1
        self.addIdAs = 0
        self.runAnyChange = 1
        self.classifyName = "Cluster"

        self.settingsChanged = False

        self.loadSettings()

        self.data = None  # holds input data
        self.km = None  # holds clustering object

        # GUI definition
        # settings

        box = OWGUI.widgetBox(self.controlArea, "Clusters (k)")
        bg = OWGUI.radioButtonsInBox(box,
                                     self,
                                     "optimized", [],
                                     callback=self.setOptimization)
        fixedBox = OWGUI.widgetBox(box, orientation="horizontal")
        button = OWGUI.appendRadioButton(bg,
                                         self,
                                         "optimized",
                                         "Fixed",
                                         insertInto=fixedBox,
                                         tooltip="Fixed number of clusters")
        self.fixedSpinBox = OWGUI.spin(OWGUI.widgetBox(fixedBox),
                                       self,
                                       "K",
                                       min=2,
                                       max=30,
                                       tooltip="Fixed number of clusters",
                                       callback=self.update,
                                       callbackOnReturn=True)
        OWGUI.rubber(fixedBox)

        optimizedBox = OWGUI.widgetBox(box)
        button = OWGUI.appendRadioButton(bg,
                                         self,
                                         "optimized",
                                         "Optimized",
                                         insertInto=optimizedBox)
        option = QStyleOptionButton()
        option.initFrom(button)
        box = OWGUI.indentedBox(
            optimizedBox,
            qApp.style().subElementRect(QStyle.SE_CheckBoxIndicator, option,
                                        button).width() - 3)
        self.optimizationBox = box
        OWGUI.spin(box,
                   self,
                   "optimizationFrom",
                   label="From",
                   min=2,
                   max=99,
                   tooltip="Minimum number of clusters to try",
                   callback=self.updateOptimizationFrom,
                   callbackOnReturn=True)
        b = OWGUI.spin(box,
                       self,
                       "optimizationTo",
                       label="To",
                       min=3,
                       max=100,
                       tooltip="Maximum number of clusters to try",
                       callback=self.updateOptimizationTo,
                       callbackOnReturn=True)
        #        b.control.setLineEdit(OWGUI.LineEditWFocusOut(b))
        OWGUI.comboBox(box,
                       self,
                       "scoring",
                       label="Scoring",
                       orientation="horizontal",
                       items=[m[0] for m in self.scoringMethods],
                       callback=self.update)

        box = OWGUI.widgetBox(self.controlArea, "Settings", addSpace=True)
        #        OWGUI.spin(box, self, "K", label="Number of clusters"+"  ", min=1, max=30, step=1,
        #                   callback = self.initializeClustering)
        OWGUI.comboBox(box,
                       self,
                       "distanceMeasure",
                       label="Distance measures",
                       items=[name for name, _ in self.distanceMeasures],
                       tooltip=None,
                       indent=20,
                       callback=self.update)
        cb = OWGUI.comboBox(box,
                            self,
                            "initializationType",
                            label="Initialization",
                            items=[name for name, _ in self.initializations],
                            tooltip=None,
                            indent=20,
                            callback=self.update)
        OWGUI.spin(cb.box,
                   self,
                   "restarts",
                   label="Restarts",
                   orientation="horizontal",
                   min=1,
                   max=100,
                   callback=self.update,
                   callbackOnReturn=True)

        box = OWGUI.widgetBox(self.controlArea, "Cluster IDs")
        cb = OWGUI.checkBox(box, self, "classifySelected",
                            "Append cluster indices")
        box = OWGUI.indentedBox(box)
        form = QWidget()
        le = OWGUI.lineEdit(
            form,
            self,
            "classifyName",
            None,  #"Name" + "  ",
            orientation="horizontal",  #controlWidth=100, 
            valueType=str,
            #                            callback=self.sendData,
            #                            callbackOnReturn=True
        )

        cc = OWGUI.comboBox(
            form,
            self,
            "addIdAs",
            label=" ",  #"Place" + "  ",
            orientation="horizontal",
            items=["Class attribute", "Attribute", "Meta attribute"],
        )

        layout = QFormLayout()
        layout.setSpacing(8)
        layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
        layout.setLabelAlignment(Qt.AlignLeft | Qt.AlignJustify)
        layout.addRow("Name  ", le)
        layout.addRow("Place  ", cc)
        #        le.setFixedWidth(cc.sizeHint().width())
        form.setLayout(layout)
        box.layout().addWidget(form)
        cb.disables.append(box)
        #        cb.disables.append(cc.box)
        cb.makeConsistent()
        #        OWGUI.separator(box)

        box = OWGUI.widgetBox(self.controlArea, "Run", addSpace=True)
        cb = OWGUI.checkBox(box, self, "runAnyChange", "Run after any change")
        self.runButton = b = OWGUI.button(box,
                                          self,
                                          "Run Clustering",
                                          callback=self.run)
        OWGUI.setStopper(self, b, cb, "settingsChanged", callback=self.run)

        OWGUI.rubber(self.controlArea)
        # display of clustering results

        self.optimizationReportBox = OWGUI.widgetBox(self.mainArea)
        tableBox = OWGUI.widgetBox(self.optimizationReportBox,
                                   "Optimization Report")
        self.table = OWGUI.table(tableBox,
                                 selectionMode=QTableWidget.SingleSelection)
        self.table.setHorizontalScrollMode(QTableWidget.ScrollPerPixel)
        self.table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setColumnCount(3)
        self.table.setHorizontalHeaderLabels(["k", "Best", "Score"])
        self.table.verticalHeader().hide()
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.setItemDelegateForColumn(
            2, OWGUI.TableBarItem(self, self.table))
        self.table.setItemDelegateForColumn(1,
                                            OWGUI.IndicatorItemDelegate(self))
        self.table.setSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.MinimumExpanding)
        self.table.hide()

        self.connect(self.table, SIGNAL("itemSelectionChanged()"),
                     self.tableItemSelected)

        self.setSizePolicy(QSizePolicy.MinimumExpanding,
                           QSizePolicy.MinimumExpanding)
        self.mainArea.setSizePolicy(QSizePolicy.MinimumExpanding,
                                    QSizePolicy.MinimumExpanding)

        OWGUI.rubber(self.topWidgetPart)

        self.updateOptimizationGui()
Example #5
0
    def setTable(self, table, data):
        if data==None:
            return
        qApp.setOverrideCursor(Qt.WaitCursor)
        vars = data.domain.variables
        m = data.domain.getmetas(False)
        ml = [(k, m[k]) for k in m]
        ml.sort(lambda x,y: cmp(y[0], x[0]))
        metas = [x[1] for x in ml]
        metaKeys = [x[0] for x in ml]

        mo = data.domain.getmetas(True).items()
        if mo:
            mo.sort(lambda x,y: cmp(x[1].name.lower(),y[1].name.lower()))
            metas.append(None)
            metaKeys.append(None)

        varsMetas = vars + metas

        numVars = len(data.domain.variables)
        numMetas = len(metas)
        numVarsMetas = numVars + numMetas
        numEx = len(data)
        numSpaces = int(math.log(max(numEx,1), 10))+1

#        table.clear()
        table.oldSortingIndex = -1
        table.oldSortingOrder = 1
#        table.setColumnCount(numVarsMetas)
#        table.setRowCount(numEx)

        dist = getCached(data, orange.DomainBasicAttrStat, (data,))
        
        datamodel = ExampleTableModel(data, dist, self)
        
#        proxy = QSortFilterProxyModel(self)
#        proxy.setSourceModel(datamodel)
        
        color_schema = self.discPalette if self.colorByClass else None
        table.setItemDelegate(OWGUI.TableBarItem(self, color=self.distColor, color_schema=color_schema) \
                              if self.showDistributions else QStyledItemDelegate(self)) #TableItemDelegate(self, table))
        
        table.setModel(datamodel)
        def p():
            try:
                table.updateGeometries()
                table.viewport().update()
            except RuntimeError:
                pass
        
        size = table.verticalHeader().sectionSizeHint(0)
        table.verticalHeader().setDefaultSectionSize(size)
        
        self.connect(datamodel, SIGNAL("layoutChanged()"), lambda *args: QTimer.singleShot(50, p))
        
        id = self.table2id.get(table, None)

        # set the header (attribute names)

        self.drawAttributeLabels(table)

        self.showMetas[id][1].extend([i for i, attr in enumerate(table.model().all_attrs) if attr in table.model().metas])
        self.connect(table.horizontalHeader(), SIGNAL("sectionClicked(int)"), self.sortByColumn)
        self.connect(table.selectionModel(), SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.updateSelection)
        #table.verticalHeader().setMovable(False)

        qApp.restoreOverrideCursor() 
Example #6
0
 def cbShowDistributions(self):
     table = self.tabs.currentWidget()
     if table:
         table.setItemDelegate(OWGUI.TableBarItem(self, color=self.distColor) if self.showDistributions else \
                               QStyledItemDelegate(self))
         table.reset()