Ejemplo n.º 1
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'LearningCurveA')
# [start-snippet-1]
        self.inputs = [("Data", Orange.data.Table, self.set_dataset),
                       ("Learner", Orange.classification.Learner, self.set_learner,
                        Multiple + Default)]
# [end-snippet-1]
        self.folds = 5     # cross validation folds
        self.steps = 10    # points in the learning curve
        self.scoringF = 0  # scoring function
        self.commitOnChange = 1 # compute curve on any change of parameters
        self.loadSettings()
        self.updateCurvePoints() # sets self.curvePoints, self.steps equidistant points from 1/self.steps to 1
# [start-snippet-2]
        self.scoring = [("Classification Accuracy", Orange.evaluation.scoring.CA),
                        ("AUC", Orange.evaluation.scoring.AUC),
                        ("BrierScore", Orange.evaluation.scoring.Brier_score),
                        ("Information Score", Orange.evaluation.scoring.IS),
                        ("Sensitivity", Orange.evaluation.scoring.Sensitivity),
                        ("Specificity", Orange.evaluation.scoring.Specificity)]
# [end-snippet-2]
        self.learners = [] # list of current learners from input channel, tuples (id, learner)
        self.data = None   # data on which to construct the learning curve
        self.curves = []   # list of evaluation results (one per learning curve point)
        self.scores = []   # list of current scores, learnerID:[learner scores]

        # GUI
        box = OWGUI.widgetBox(self.controlArea, "Info")
        self.infoa = OWGUI.widgetLabel(box, 'No data on input.')
        self.infob = OWGUI.widgetLabel(box, 'No learners.')

        OWGUI.separator(self.controlArea)

        box = OWGUI.widgetBox(self.controlArea, "Evaluation Scores")
        scoringNames = [x[0] for x in self.scoring]
        OWGUI.comboBox(box, self, "scoringF", items=scoringNames,
                       callback=self.computeScores)

        OWGUI.separator(self.controlArea)

        box = OWGUI.widgetBox(self.controlArea, "Options")
        OWGUI.spin(box, self, 'folds', 2, 100, step=1,
                   label='Cross validation folds:  ',
                   callback=lambda: self.computeCurve() if self.commitOnChange else None)
        OWGUI.spin(box, self, 'steps', 2, 100, step=1,
                   label='Learning curve points:  ',
                   callback=[self.updateCurvePoints,
                             lambda: self.computeCurve() if self.commitOnChange else None])
        OWGUI.checkBox(box, self, 'commitOnChange', 'Apply setting on any change')
        self.commitBtn = OWGUI.button(box, self, "Apply Setting",
                                      callback=self.computeCurve, disabled=1)

        OWGUI.rubber(self.controlArea)

        # table widget
        self.table = OWGUI.table(self.mainArea,
                                 selectionMode=QTableWidget.NoSelection)

        self.resize(500,200)
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Confusion Matrix", 1)

        # inputs
        self.inputs=[("Evaluation Results", orngTest.ExperimentResults, self.setTestResults, Default)]
        self.outputs=[("Selected Data", ExampleTable, 8)]

        self.selectedLearner = []
        self.learnerNames = []
        self.selectionDirty = 0
        self.autoApply = True
        self.appendPredictions = True
        self.appendProbabilities = False
        self.shownQuantity = 0

        self.learnerList = OWGUI.listBox(self.controlArea, self, "selectedLearner", "learnerNames", box = "Learners", callback = self.learnerChanged)
        self.learnerList.setMinimumHeight(100)
        
        OWGUI.separator(self.controlArea)

        OWGUI.comboBox(self.controlArea, self, "shownQuantity", items = self.quantities, box = "Show", callback=self.reprint)

        OWGUI.separator(self.controlArea)
        
        box = OWGUI.widgetBox(self.controlArea, "Selection") #, addSpace=True)
        OWGUI.button(box, self, "Correct", callback=self.selectCorrect)
        OWGUI.button(box, self, "Misclassified", callback=self.selectWrong)
        OWGUI.button(box, self, "None", callback=self.selectNone)
        
        OWGUI.separator(self.controlArea)

        self.outputBox = box = OWGUI.widgetBox(self.controlArea, "Output")
        OWGUI.checkBox(box, self, "appendPredictions", "Append class predictions", callback = self.sendIf)
        OWGUI.checkBox(box, self, "appendProbabilities", "Append predicted class probabilities", callback = self.sendIf)
        applyButton = OWGUI.button(box, self, "Commit", callback = self.sendData, default=True)
        autoApplyCB = OWGUI.checkBox(box, self, "autoApply", "Commit automatically")
        OWGUI.setStopper(self, applyButton, autoApplyCB, "selectionDirty", self.sendData)

        import sip
        sip.delete(self.mainArea.layout())
        self.layout = QGridLayout(self.mainArea)

        self.layout.addWidget(OWGUI.widgetLabel(self.mainArea, "Prediction"), 0, 1, Qt.AlignCenter)
        
        label = TransformedLabel("Correct Class")
        self.layout.addWidget(label, 2, 0, Qt.AlignCenter)
#        self.layout.addWidget(OWGUI.widgetLabel(self.mainArea, "Correct Class  "), 2, 0, Qt.AlignCenter)
        self.table = OWGUI.table(self.mainArea, rows = 0, columns = 0, selectionMode = QTableWidget.MultiSelection, addToLayout = 0)
        self.layout.addWidget(self.table, 2, 1)
        self.layout.setColumnStretch(1, 100)
        self.layout.setRowStretch(2, 100)
        self.connect(self.table, SIGNAL("itemSelectionChanged()"), self.sendIf)
        
        self.res = None
        self.matrix = None
        self.selectedLearner = None
        self.resize(700,450)
Ejemplo n.º 3
0
    def add_tables(self, networks):
        self.networks = networks
        self.tables = []
        
        if networks is None:
            return
        
        networks.sort(key=lambda net: net.repository)
        for k,g in itertools.groupby(networks, key=lambda net: net.repository):
            network_group = list(g)
        
            if len(network_group) > 0:
                self.network_list.layout().addWidget(QLabel("<h3>" + network_group[0].repository + "</h3>"))
                table = OWGUI.table(self.network_list, rows=len(network_group), columns=5, selectionMode = -1, addToLayout = 1)
                table.setHorizontalHeaderLabels(['Name', 'Type', 'Nodes', 'Edges', 'Description'])
                f = table.font()
                f.setPointSize(9)
                table.setFont(f)
                table.verticalHeader().hide()
                table.setSelectionMode(QAbstractItemView.SingleSelection)
                table.setSelectionBehavior(QAbstractItemView.SelectRows)
                self.connect(table, SIGNAL('itemSelectionChanged()'), lambda table=table: self.select_network(table))
            
                for i, net in enumerate(network_group):
                    lbl = QLabel("<a href='"+ net.link +"'>" + net.name + "</a>")
                    lbl.setOpenExternalLinks(True)
                    table.setCellWidget(i, 0, lbl)
                    OWGUI.tableItem(table, i, 1, net.type)
                    OWGUI.tableItem(table, i, 2, net.nodes)
                    OWGUI.tableItem(table, i, 3, net.edges)
                    OWGUI.tableItem(table, i, 4, net.description)
 
                table.setFixedSize(712, 100)
                table.setColumnWidth(0, 120)
                table.setColumnWidth(1, 80)
                table.setColumnWidth(2, 80)
                table.setColumnWidth(3, 80)
                table.setColumnWidth(4, 350)
                table.resizeRowsToContents()                   
                table.setFixedSize(712, sum(table.rowHeight(i) for i in range(len(networks))) + 27)
                self.tables.append(table)
                
                OWGUI.separator(self.network_list, 10, 10)
Ejemplo n.º 4
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'LearningCurveA')

        self.inputs = [("Data", ExampleTable, self.dataset),
                       ("Learner", orange.Learner, self.learner, Multiple)]
        
        self.folds = 5     # cross validation folds
        self.steps = 10    # points in the learning curve
        self.scoringF = 0  # scoring function
        self.commitOnChange = 1 # compute curve on any change of parameters
        self.loadSettings()
        self.setCurvePoints() # sets self.curvePoints, self.steps equidistantpoints from 1/self.steps to 1
        self.scoring = [("Classification Accuracy", orngStat.CA), ("AUC", orngStat.AUC), ("BrierScore", orngStat.BrierScore), ("Information Score", orngStat.IS), ("Sensitivity", orngStat.sens), ("Specificity", orngStat.spec)]
        self.learners = [] # list of current learners from input channel, tuples (id, learner)
        self.data = None   # data on which to construct the learning curve
        self.curves = []   # list of evaluation results (one per learning curve point)
        self.scores = []   # list of current scores, learnerID:[learner scores]

        # GUI
        box = OWGUI.widgetBox(self.controlArea, "Info")
        self.infoa = OWGUI.widgetLabel(box, 'No data on input.')
        self.infob = OWGUI.widgetLabel(box, 'No learners.')

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Evaluation Scores")
        scoringNames = [x[0] for x in self.scoring]
        OWGUI.comboBox(box, self, "scoringF", items=scoringNames, callback=self.computeScores)

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Options")
        OWGUI.spin(box, self, 'folds', 2, 100, step=1, label='Cross validation folds:  ',
                   callback=lambda: self.computeCurve(self.commitOnChange))
        OWGUI.spin(box, self, 'steps', 2, 100, step=1, label='Learning curve points:  ',
                   callback=[self.setCurvePoints, lambda: self.computeCurve(self.commitOnChange)])

        OWGUI.checkBox(box, self, 'commitOnChange', 'Apply setting on any change')
        self.commitBtn = OWGUI.button(box, self, "Apply Setting", callback=self.computeCurve, disabled=1)

        # table widget
        self.table = OWGUI.table(self.mainArea, selectionMode=QTableWidget.NoSelection)
                
        self.resize(500,200)
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'LearningCurveC')

        self.inputs = [("Data", ExampleTable, self.dataset),
                       ("Learner", orange.Learner, self.learner, Multiple)]

        self.folds = 5  # cross validation folds
        self.steps = 10  # points in the learning curve
        self.scoringF = 0  # scoring function
        self.commitOnChange = 1  # compute curve on any change of parameters
        self.graphPointSize = 5  # size of points in the graphs
        self.graphDrawLines = 1  # draw lines between points in the graph
        self.graphShowGrid = 1  # show gridlines in the graph
        self.selectedLearners = []
        self.loadSettings()

        warnings.filterwarnings("ignore", ".*builtin attribute.*",
                                orange.AttributeWarning)

        self.setCurvePoints(
        )  # sets self.curvePoints, self.steps equidistantpoints from 1/self.steps to 1
        self.scoring = [("Classification Accuracy", orngStat.CA),
                        ("AUC", orngStat.AUC),
                        ("BrierScore", orngStat.BrierScore),
                        ("Information Score", orngStat.IS),
                        ("Sensitivity", orngStat.sens),
                        ("Specificity", orngStat.spec)]
        self.learners = [
        ]  # list of current learners from input channel, tuples (id, learner)
        self.data = None  # data on which to construct the learning curve
        self.curves = [
        ]  # list of evaluation results (one per learning curve point)
        self.scores = []  # list of current scores, learnerID:[learner scores]

        # GUI
        box = OWGUI.widgetBox(self.controlArea, "Info")
        self.infoa = OWGUI.widgetLabel(box, 'No data on input.')
        self.infob = OWGUI.widgetLabel(box, 'No learners.')

        ## class selection (classQLB)
        OWGUI.separator(self.controlArea)
        self.cbox = OWGUI.widgetBox(self.controlArea, "Learners")
        self.llb = OWGUI.listBox(self.cbox,
                                 self,
                                 "selectedLearners",
                                 selectionMode=QListWidget.MultiSelection,
                                 callback=self.learnerSelectionChanged)

        self.llb.setMinimumHeight(50)
        self.blockSelectionChanges = 0

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Evaluation Scores")
        scoringNames = [x[0] for x in self.scoring]
        OWGUI.comboBox(box,
                       self,
                       "scoringF",
                       items=scoringNames,
                       callback=self.computeScores)

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Options")
        OWGUI.spin(box,
                   self,
                   'folds',
                   2,
                   100,
                   step=1,
                   label='Cross validation folds:  ',
                   callback=lambda: self.computeCurve(self.commitOnChange))
        OWGUI.spin(box,
                   self,
                   'steps',
                   2,
                   100,
                   step=1,
                   label='Learning curve points:  ',
                   callback=[
                       self.setCurvePoints,
                       lambda: self.computeCurve(self.commitOnChange)
                   ])

        OWGUI.checkBox(box, self, 'commitOnChange',
                       'Apply setting on any change')
        self.commitBtn = OWGUI.button(box,
                                      self,
                                      "Apply Setting",
                                      callback=self.computeCurve,
                                      disabled=1)

        # start of content (right) area
        tabs = OWGUI.tabWidget(self.mainArea)

        # graph widget
        tab = OWGUI.createTabPage(tabs, "Graph")
        self.graph = OWGraph(tab)
        self.graph.setAxisAutoScale(QwtPlot.xBottom)
        self.graph.setAxisAutoScale(QwtPlot.yLeft)
        tab.layout().addWidget(self.graph)
        self.setGraphGrid()

        # table widget
        tab = OWGUI.createTabPage(tabs, "Table")
        self.table = OWGUI.table(tab, selectionMode=QTableWidget.NoSelection)

        self.resize(550, 200)
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'LearningCurveC')

        self.inputs = [("Data", ExampleTable, self.dataset), ("Learner", orange.Learner, self.learner, 0)]

        self.folds = 5     # cross validation folds
        self.steps = 10    # points in the learning curve
        self.scoringF = 0  # scoring function
        self.commitOnChange = 1 # compute curve on any change of parameters
        self.graphPointSize = 5 # size of points in the graphs
        self.graphDrawLines = 1 # draw lines between points in the graph
        self.graphShowGrid = 1  # show gridlines in the graph
        self.selectedLearners = [] 
        self.loadSettings()

        warnings.filterwarnings("ignore", ".*builtin attribute.*", orange.AttributeWarning)

        self.setCurvePoints() # sets self.curvePoints, self.steps equidistantpoints from 1/self.steps to 1
        self.scoring = [("Classification Accuracy", orngStat.CA), ("AUC", orngStat.AUC), ("BrierScore", orngStat.BrierScore), ("Information Score", orngStat.IS), ("Sensitivity", orngStat.sens), ("Specificity", orngStat.spec)]
        self.learners = [] # list of current learners from input channel, tuples (id, learner)
        self.data = None   # data on which to construct the learning curve
        self.curves = []   # list of evaluation results (one per learning curve point)
        self.scores = []   # list of current scores, learnerID:[learner scores]

        # GUI
        box = OWGUI.widgetBox(self.controlArea, "Info")
        self.infoa = OWGUI.widgetLabel(box, 'No data on input.')
        self.infob = OWGUI.widgetLabel(box, 'No learners.')

        ## class selection (classQLB)
        OWGUI.separator(self.controlArea)
        self.cbox = OWGUI.widgetBox(self.controlArea, "Learners")
        self.llb = OWGUI.listBox(self.cbox, self, "selectedLearners", selectionMode=QListWidget.MultiSelection, callback=self.learnerSelectionChanged)
        
        self.llb.setMinimumHeight(50)
        self.blockSelectionChanges = 0

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Evaluation Scores")
        scoringNames = [x[0] for x in self.scoring]
        OWGUI.comboBox(box, self, "scoringF", items=scoringNames,
                       callback=self.computeScores)

        OWGUI.separator(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Options")
        OWGUI.spin(box, self, 'folds', 2, 100, step=1,
                   label='Cross validation folds:  ',
                   callback=lambda: self.computeCurve(self.commitOnChange))
        OWGUI.spin(box, self, 'steps', 2, 100, step=1,
                   label='Learning curve points:  ',
                   callback=[self.setCurvePoints, lambda: self.computeCurve(self.commitOnChange)])

        OWGUI.checkBox(box, self, 'commitOnChange', 'Apply setting on any change')
        self.commitBtn = OWGUI.button(box, self, "Apply Setting", callback=self.computeCurve, disabled=1)

        # start of content (right) area
        tabs = OWGUI.tabWidget(self.mainArea)

        # graph widget
        tab = OWGUI.createTabPage(tabs, "Graph")
        self.graph = OWPlot(tab)
        self.graph.set_axis_autoscale(xBottom)
        self.graph.set_axis_autoscale(yLeft)
        tab.layout().addWidget(self.graph)
        self.setGraphGrid()

        # table widget
        tab = OWGUI.createTabPage(tabs, "Table")
        self.table = OWGUI.table(tab, selectionMode=QTableWidget.NoSelection)

        self.resize(550,200)
Ejemplo n.º 7
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "Confusion Matrix", 1)

        # inputs
        self.inputs = [("Evaluation Results", orngTest.ExperimentResults,
                        self.setTestResults, Default)]
        self.outputs = [("Selected Examples", ExampleTable, 8)]

        self.selectedLearner = []
        self.learnerNames = []
        self.selectionDirty = 0
        self.autoApply = True
        self.appendPredictions = True
        self.appendProbabilities = False
        self.shownQuantity = 0

        self.learnerList = OWGUI.listBox(self.controlArea,
                                         self,
                                         "selectedLearner",
                                         "learnerNames",
                                         box="Learners",
                                         callback=self.learnerChanged)
        self.learnerList.setMinimumHeight(100)
        OWGUI.separator(self.controlArea)

        OWGUI.comboBox(self.controlArea,
                       self,
                       "shownQuantity",
                       items=self.quantities,
                       box="Show",
                       callback=self.reprint)

        box = OWGUI.widgetBox(self.controlArea, "Selection", addSpace=True)
        OWGUI.button(box, self, "Correct", callback=self.selectCorrect)
        OWGUI.button(box, self, "Misclassified", callback=self.selectWrong)
        OWGUI.button(box, self, "None", callback=self.selectNone)

        box = OWGUI.widgetBox(self.controlArea, "Output")
        OWGUI.checkBox(box,
                       self,
                       "appendPredictions",
                       "Append class predictions",
                       callback=self.sendIf)
        OWGUI.checkBox(box,
                       self,
                       "appendProbabilities",
                       "Append predicted class probabilities",
                       callback=self.sendIf)
        applyButton = OWGUI.button(box, self, "Commit", callback=self.sendData)
        autoApplyCB = OWGUI.checkBox(box, self, "autoApply",
                                     "Commit automatically")
        OWGUI.setStopper(self, applyButton, autoApplyCB, "selectionDirty",
                         self.sendData)

        import sip
        sip.delete(self.mainArea.layout())
        self.layout = QGridLayout(self.mainArea)

        self.layout.addWidget(OWGUI.widgetLabel(self.mainArea, "Prediction"),
                              0, 1, Qt.AlignCenter)
        self.layout.addWidget(
            OWGUI.widgetLabel(self.mainArea, "Correct Class  "), 2, 0,
            Qt.AlignCenter)
        self.table = OWGUI.table(self.mainArea,
                                 rows=0,
                                 columns=0,
                                 selectionMode=QTableWidget.MultiSelection,
                                 addToLayout=0)
        self.layout.addWidget(self.table, 2, 1)
        self.layout.setColumnStretch(1, 100)
        self.layout.setRowStretch(2, 100)
        self.connect(self.table, SIGNAL("itemSelectionChanged()"), self.sendIf)

        self.resize(700, 450)
Ejemplo n.º 8
0
    def defineGUI(self):
        OWGUI.lineEdit(self.controlArea, self, 'name', box='Name', \
                       tooltip='Name to be used by other widgets to identify your classifier.<br>This should be a unique name!')

        # Queue radio buttons
        self.queueBox = OWGUI.radioButtonsInBox(self.controlArea,
                                                self,
                                                "outputSel",
                                                box="Output mode",
                                                btnLabels=self.outputModes,
                                                callback=self.changeOutputMode)

        # Queue radio buttons
        self.queueBox = OWGUI.radioButtonsInBox(self.controlArea,
                                                self,
                                                "queueType",
                                                box="Execution Mode",
                                                btnLabels=self.queueTypes,
                                                callback=None)

        # create table with selectable ML methods
        self.colNames = ["ML method", "Enabled"]
        mainRight = OWGUI.widgetBox(self.controlArea, "ML methods selection")
        mainRight.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))

        self.mlTable = OWGUI.table(self.controlArea,
                                   rows=0,
                                   columns=0,
                                   selectionMode=QTableWidget.MultiSelection,
                                   addToLayout=1)
        self.mlTable.verticalHeader().hide()
        self.mlTable.setSelectionMode(QTableWidget.NoSelection)
        self.mlTable.setColumnCount(len(self.colNames))
        self.mlTable.setHorizontalHeaderLabels(self.colNames)

        # Set location of statistics file
        boxFile = OWGUI.widgetBox(self.controlArea,
                                  "Path for saving the results",
                                  addSpace=True,
                                  orientation=0)
        L1 = OWGUI.lineEdit(
            boxFile,
            self,
            "statPath",
            labelWidth=80,
            orientation="horizontal",
            tooltip="Please use full path to results file to be created.")
        L1.setMinimumWidth(200)
        button = OWGUI.button(boxFile,
                              self,
                              '...',
                              callback=self.setStatSaveDir,
                              disabled=0,
                              tooltip="Choose the dir where to save.")
        button.setMaximumWidth(25)

        # Apply the settings and send the model to the output channel
        OWGUI.button(self.controlArea,
                     self,
                     "&Apply settings",
                     callback=self.Apply)

        # Set location of model file
        self.boxFile = OWGUI.widgetBox(self.controlArea,
                                       "Path for saving Model",
                                       addSpace=True,
                                       orientation=0)
        self.L1 = OWGUI.lineEdit(
            self.boxFile,
            self,
            "modelFile",
            labelWidth=80,
            orientation="horizontal",
            tooltip=
            "Once a model is created (connect this widget with a data widget), \nit can be saved by giving a file name here and clicking the save button."
        )
        self.L1.setMinimumWidth(200)
        self.button = OWGUI.button(
            self.boxFile,
            self,
            '...',
            callback=self.setModelSavePath,
            disabled=0,
            tooltip=
            "Choose the dir where to save. After chosen, add a name for the model file!"
        )
        self.button.setMaximumWidth(25)

        # Save the model
        self.saveButton = OWGUI.button(self.controlArea,
                                       self,
                                       "&Save model",
                                       callback=self.saveModel)

        # Statistics show
        statBox = OWGUI.widgetBox(self.mainArea,
                                  "Statistics",
                                  addSpace=True,
                                  orientation=0)
        self.statInfoBox = OWGUI.widgetLabel(statBox, '')

        # Save the model
        OWGUI.button(self.mainArea,
                     self,
                     "&Save statistics",
                     callback=self.saveStat)

        self.fillMLtable()

        self.changeOutputMode()
        self.adjustSize()
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'k-Means Clustering')

        self.inputs = [("Data", ExampleTable, self.setData)]
        self.outputs = [("Data", 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)",
                              addSpace=True, spacing=0)
#        left, top, right, bottom = box.getContentsMargins()
#        box.setContentsMargins(left, 0, right, 0)
        bg = OWGUI.radioButtonsInBox(box, self, "optimized", [],
                                     callback=self.setOptimization)

        fixedBox = OWGUI.widgetBox(box, orientation="horizontal",
                                   margin=0, spacing=bg.layout().spacing())

        button = OWGUI.appendRadioButton(bg, self, "optimized", "Fixed",
                                         insertInto=fixedBox,
                                         tooltip="Fixed number of clusters")

        button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        fixedBox.layout().setAlignment(button, Qt.AlignLeft)
        self.fixedSpinBox = OWGUI.spin(OWGUI.widgetBox(fixedBox), self, "K",
                                       min=2, max=30,
                                       tooltip="Fixed number of clusters",
                                       callback=self.update,
                                       callbackOnReturn=True)

        optimizedBox = OWGUI.widgetBox(box, margin=0,
                                       spacing=bg.layout().spacing())
        button = OWGUI.appendRadioButton(bg, self, "optimized", "Optimized",
                                         insertInto=optimizedBox)

        box = OWGUI.indentedBox(optimizedBox,
                                sep=OWGUI.checkButtonOffsetHint(button))

        box.layout().setSpacing(0)
        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)

        OWGUI.spin(box, self, "optimizationTo", label="To",
                   min=3, max=100,
                   tooltip="Maximum number of clusters to try",
                   callback=self.updateOptimizationTo,
                   callbackOnReturn=True)

        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.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 if not orngDebugging.orngDebuggingEnabled else 5,
                   callback=self.update,
                   callbackOnReturn=True)

        box = OWGUI.widgetBox(self.controlArea, "Cluster IDs", addSpace=True)
        cb = OWGUI.checkBox(box, self, "classifySelected",
                            "Append cluster indices")

        box = OWGUI.indentedBox(box, sep=OWGUI.checkButtonOffsetHint(cb))

        form = QWidget()
        le = OWGUI.lineEdit(form, self, "classifyName", None,
                            orientation="horizontal",
                            valueType=str)

        cc = OWGUI.comboBox(form, self, "addIdAs", label=" ",
                            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)

        form.setLayout(layout)
        box.layout().addWidget(form)
        left, top, right, bottom = layout.getContentsMargins()
        layout.setContentsMargins(0, top, right, bottom)

        cb.disables.append(box)
        cb.makeConsistent()

        box = OWGUI.widgetBox(self.controlArea, "Run")
        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)
        self.tableBox = OWGUI.widgetBox(self.optimizationReportBox,
                                        "Optimization Report")
        self.table = OWGUI.table(self.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.connect(self.table,
                     SIGNAL("itemSelectionChanged()"),
                     self.tableItemSelected)

        self.setSizePolicy(QSizePolicy.Preferred,
                           QSizePolicy.Preferred)

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

        OWGUI.rubber(self.topWidgetPart)

        self.updateOptimizationGui()
    def defineGUI(self):

        self.sBox = OWGUI.widgetBox(self.controlArea, "Execution environment")
        itms = [e[0] for e in self.execEnvs]
        OWGUI.radioButtonsInBox(self.sBox, self, "execEnv", btnLabels=itms)

        boxGrid = OWGUI.widgetBox(self.controlArea,'Initial Point for the Optimizer')
        OWGUI.checkBox(boxGrid, self, 'UseGridSearch','Use Grid-Search',  tooltip='Use Grid-Search to find the best initial point to start the optimization.<br>If not checked, the midrange point will be used as optimization initial point.')
        OWGUI.spin(boxGrid, self, 'nInnerPoints', 1, 100, step=1, label='    Number of inner points:', tooltip='Number of points to break down each variable to evaluate the initial point.<br>It will evaluate nInnerPoints^nOptimizedVars')

        OWGUI.separator(self.controlArea)

        self.sBox = OWGUI.widgetBox(self.controlArea, "Sampling  Method")
        itms = [e[0] for e in self.SMethods]
        self.comboDistItems = ["Continuous","Power2","By Step","Specific Values"]        
        OWGUI.radioButtonsInBox(self.sBox, self, "SMethod", btnLabels=itms)

        hBox = OWGUI.widgetBox(OWGUI.indentedBox(self.sBox))
        #QWidget(hBox).setFixedSize(19, 8)
        OWGUI.spin(hBox, self, 'nFolds', 2, 100, step=1, label='Number of Folds:  ')


        OWGUI.separator(self.controlArea)

        box2 = OWGUI.widgetBox(self.controlArea,'Evaluation Method')
        width = 150
        itms = [e[0] for e in self.CMethods]
        OWGUI.comboBox(box2, self, 'CMethod', items=itms, label='For Classifiers:', labelWidth=width, orientation='horizontal',
                       tooltip='Method used for evaluation in case of classifiers.')
        itms = [e[0] for e in self.RMethods]
        OWGUI.comboBox(box2, self, 'RMethod', items=itms, label='For Regressors:', labelWidth=width, 
                       orientation='horizontal', tooltip='Method used for evaluation in case of regressors.')

        OWGUI.separator(self.controlArea)
        OWGUI.button(self.controlArea, self,"&Reload Defaults ", callback=self.reloadDefaults)
        OWGUI.separator(self.controlArea)


        #OWGUI.separator(self.controlArea, height=24)

        infoBox = OWGUI.widgetBox(self.controlArea, "Optimizer status")
        self.infoStatus = OWGUI.label(infoBox,self,'Waiting for inputs...')                    
        self.infoPars = OWGUI.label(infoBox,self,'')
        self.infoRes = OWGUI.label(infoBox,self,'')
        OWGUI.label(infoBox,self,'')
        self.infoErr = OWGUI.label(infoBox,self,'')
        OWGUI.separator(self.controlArea)
        OWGUI.button(self.controlArea, self,"&Apply Settings ", callback=self.optimizeParameters)
 

        # Main area GUI
        import sip
        sip.delete(self.mainArea.layout())
        self.mainLayout = QGridLayout(self.mainArea)

        mainRight = OWGUI.widgetBox(self.mainArea, "Parameters Configuration")
        mainRight.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding))

        self.paramsTable = OWGUI.table(self.mainArea, rows = 0, columns = 0, selectionMode = QTableWidget.MultiSelection, addToLayout = 0)
        #self.paramsTable.setLeftMargin(0)
        self.paramsTable.verticalHeader().hide()
        self.paramsTable.setSelectionMode(QTableWidget.NoSelection)
        self.paramsTable.setColumnCount(len(self.paramsNames))

        #for i, m in enumerate(self.paramsNames):
        #    self.paramsTable.setColumnStretchable(i, 0)
        #    header.setLabel(i, m)
        self.paramsTable.setHorizontalHeaderLabels(self.paramsNames)
        #self.mainLayout.setColumnStretch(1, 100)
        #self.mainLayout.setRowStretch(2, 100)
        self.mainLayout.addWidget(self.paramsTable, 0, 0, 1,2)
        self.mainLayout.addWidget(OWGUI.label(mainRight,self,'Red - Parameter selected to be optimized\r\nGreen - Parameter optimized\r\nBlack - Parameter will not be optimized'),1,0) 
        self.mainLayout.addWidget(OWGUI.label(mainRight,self,'N_EX - Number of Examples in dataset\r\nN_ATTR - Number of attributes in dataset'),1,1)
         
        self.adjustSize()
        self.create()
Ejemplo n.º 12
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "Confusion Matrix", 1)

        # inputs
        self.inputs = [("Evaluation Results", orngTest.ExperimentResults,
                        self.setTestResults, Default)]
        self.outputs = [("Selected Examples", ExampleTable, 8)]

        self.selectedLearner = []
        self.learnerNames = []
        self.selectionDirty = 0
        self.autoApply = True
        self.appendPredictions = True
        self.appendProbabilities = False
        self.shownQuantity = 0

        self.learnerList = OWGUI.listBox(self.controlArea,
                                         self,
                                         "selectedLearner",
                                         "learnerNames",
                                         box="Learners",
                                         callback=self.learnerChanged)
        self.learnerList.setMinimumHeight(100)
        OWGUI.separator(self.controlArea)

        OWGUI.comboBox(self.controlArea,
                       self,
                       "shownQuantity",
                       items=self.quantities,
                       box="Show",
                       callback=self.reprint)

        box = OWGUI.widgetBox(self.controlArea, "Selection", addSpace=True)
        OWGUI.button(box, self, "Correct", callback=self.selectCorrect)
        OWGUI.button(box, self, "Misclassified", callback=self.selectWrong)
        OWGUI.button(box, self, "None", callback=self.selectNone)

        box = OWGUI.widgetBox(self.controlArea, "Output")
        OWGUI.checkBox(box,
                       self,
                       "appendPredictions",
                       "Append class predictions",
                       callback=self.sendIf)
        OWGUI.checkBox(box,
                       self,
                       "appendProbabilities",
                       "Append predicted class probabilities",
                       callback=self.sendIf)
        applyButton = OWGUI.button(box, self, "Commit", callback=self.sendData)
        autoApplyCB = OWGUI.checkBox(box, self, "autoApply",
                                     "Commit automatically")
        OWGUI.setStopper(self, applyButton, autoApplyCB, "selectionDirty",
                         self.sendData)

        import sip
        sip.delete(self.mainArea.layout())
        self.layout = QGridLayout(self.mainArea)

        self.layout.addWidget(OWGUI.widgetLabel(self.mainArea, "Prediction"),
                              0, 1, Qt.AlignCenter)
        self.layout.addWidget(
            OWGUI.widgetLabel(self.mainArea, "Correct Class  "), 2, 0,
            Qt.AlignCenter)
        self.table = OWGUI.table(self.mainArea,
                                 rows=0,
                                 columns=0,
                                 selectionMode=QTableWidget.MultiSelection,
                                 addToLayout=0)
        self.layout.addWidget(self.table, 2, 1)
        self.layout.setColumnStretch(1, 100)
        self.layout.setRowStretch(2, 100)
        self.connect(self.table, SIGNAL("itemSelectionChanged()"), self.sendIf)

        ##scPA
        # Get location of model file
        self.filePath = os.path.join(os.getcwd(), "ConfusionMat.txt")
        boxFile = OWGUI.widgetBox(self.controlArea,
                                  "File for saving results",
                                  addSpace=True,
                                  orientation=0)
        L1 = OWGUI.lineEdit(
            boxFile,
            self,
            "filePath",
            labelWidth=80,
            orientation="horizontal",
            tooltip=
            "Enter full file path to save the displayed results to a tab separated file."
        )
        L1.setMinimumWidth(200)
        button = OWGUI.button(boxFile,
                              self,
                              '...',
                              callback=self.browseFile,
                              disabled=0,
                              tooltip="Browse for a location...")
        button.setMaximumWidth(25)
        # Save the model
        OWGUI.button(self.controlArea,
                     self,
                     "&Save Results",
                     callback=self.saveRes)
        ##ecPA
        self.resize(700, 450)
Ejemplo n.º 13
0
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, "TestLearners")

        self.inputs = [("Data", ExampleTable, self.setData, Default),
                       ("Separate Test Data", ExampleTable, self.setTestData),
                       ("Learner", orange.Learner, self.setLearner, Multiple),
                       ("Preprocess", PreprocessedLearner,
                        self.setPreprocessor)]
        self.outputs = [("Evaluation Results", orngTest.ExperimentResults)]

        # Settings
        self.resampling = 0  # cross-validation
        self.nFolds = 5  # cross validation folds
        self.pLearning = 70  # size of learning set when sampling [%]
        self.pRepeat = 10
        self.precision = 4
        self.applyOnAnyChange = True
        self.selectedCScores = [
            i for (i, s) in enumerate(self.cStatistics) if s.show
        ]
        self.selectedRScores = [
            i for (i, s) in enumerate(self.rStatistics) if s.show
        ]
        self.targetClass = 0
        self.loadSettings()
        self.resampling = 0  # cross-validation

        self.stat = self.cStatistics

        self.data = None  # input data set
        self.testdata = None  # separate test data set
        self.learners = {}  # set of learners (input)
        self.results = None  # from orngTest
        self.preprocessor = None

        self.controlArea.layout().setSpacing(8)
        # GUI
        self.sBtns = OWGUI.radioButtonsInBox(
            self.controlArea,
            self,
            "resampling",
            box="Sampling",
            btnLabels=self.resamplingMethods[:1],
            callback=self.newsampling)
        indent = OWGUI.checkButtonOffsetHint(self.sBtns.buttons[-1])

        ibox = OWGUI.widgetBox(OWGUI.indentedBox(self.sBtns, sep=indent))
        OWGUI.spin(ibox,
                   self,
                   'nFolds',
                   2,
                   100,
                   step=1,
                   label='Number of folds:',
                   callback=lambda p=0: self.conditionalRecompute(p))
        OWGUI.separator(self.sBtns, height=3)

        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[1])  # leave one out
        OWGUI.separator(self.sBtns, height=3)
        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[2])  # random sampling

        ibox = OWGUI.widgetBox(OWGUI.indentedBox(self.sBtns, sep=indent))
        OWGUI.spin(ibox,
                   self,
                   'pRepeat',
                   1,
                   100,
                   step=1,
                   label='Repeat train/test:',
                   callback=lambda p=2: self.conditionalRecompute(p))

        OWGUI.widgetLabel(ibox, "Relative training set size:")

        OWGUI.hSlider(ibox,
                      self,
                      'pLearning',
                      minValue=10,
                      maxValue=100,
                      step=1,
                      ticks=10,
                      labelFormat="   %d%%",
                      callback=lambda p=2: self.conditionalRecompute(p))

        OWGUI.separator(self.sBtns, height=3)
        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[3])  # test on train
        OWGUI.separator(self.sBtns, height=3)
        OWGUI.appendRadioButton(self.sBtns, self, "resampling",
                                self.resamplingMethods[4])  # test on test

        self.trainDataBtn = self.sBtns.buttons[-2]
        self.testDataBtn = self.sBtns.buttons[-1]
        self.testDataBtn.setDisabled(True)

        #        box = OWGUI.widgetBox(self.sBtns, orientation='vertical', addSpace=False)
        #        OWGUI.separator(box)
        OWGUI.separator(self.sBtns)
        OWGUI.checkBox(self.sBtns,
                       self,
                       'applyOnAnyChange',
                       label="Apply on any change",
                       callback=self.applyChange)
        self.applyBtn = OWGUI.button(self.sBtns,
                                     self,
                                     "&Apply",
                                     callback=lambda f=True: self.recompute(f))
        self.applyBtn.setDisabled(True)

        if self.resampling == 4:
            self.resampling = 3

#        OWGUI.separator(self.controlArea)

# statistics
        self.statLayout = QStackedLayout()
        #        self.cbox = OWGUI.widgetBox(self.controlArea, spacing=8, margin=0)
        #        self.cbox.layout().setSpacing(8)
        self.cbox = OWGUI.widgetBox(self.controlArea, addToLayout=False)
        self.cStatLabels = [s.name for s in self.cStatistics]
        self.cstatLB = OWGUI.listBox(self.cbox,
                                     self,
                                     'selectedCScores',
                                     'cStatLabels',
                                     box="Performance scores",
                                     selectionMode=QListWidget.MultiSelection,
                                     callback=self.newscoreselection)
        #        OWGUI.separator(self.cbox)
        self.cbox.layout().addSpacing(8)
        self.targetCombo = OWGUI.comboBox(self.cbox,
                                          self,
                                          "targetClass",
                                          orientation=0,
                                          callback=[self.changedTarget],
                                          box="Target class")

        self.rStatLabels = [s.name for s in self.rStatistics]
        self.rbox = OWGUI.widgetBox(self.controlArea,
                                    "Performance scores",
                                    addToLayout=False)
        self.rstatLB = OWGUI.listBox(self.rbox,
                                     self,
                                     'selectedRScores',
                                     'rStatLabels',
                                     selectionMode=QListWidget.MultiSelection,
                                     callback=self.newscoreselection)

        self.statLayout.addWidget(self.cbox)
        self.statLayout.addWidget(self.rbox)
        self.controlArea.layout().addLayout(self.statLayout)

        self.statLayout.setCurrentWidget(self.cbox)

        #        self.rstatLB.box.hide()

        # score table
        # table with results
        self.g = OWGUI.widgetBox(self.mainArea, 'Evaluation Results')
        self.tab = OWGUI.table(self.g, selectionMode=QTableWidget.NoSelection)

        #self.lab = QLabel(self.g)

        self.resize(680, 470)
Ejemplo n.º 14
0
    def defineGUI(self):

        self.sBox = OWGUI.widgetBox(self.controlArea, "Execution environment")
        itms = [e[0] for e in self.execEnvs]
        OWGUI.radioButtonsInBox(self.sBox, self, "execEnv", btnLabels=itms)

        boxGrid = OWGUI.widgetBox(self.controlArea,
                                  'Initial Point for the Optimizer')
        OWGUI.checkBox(
            boxGrid,
            self,
            'UseGridSearch',
            'Use Grid-Search',
            tooltip=
            'Use Grid-Search to find the best initial point to start the optimization.<br>If not checked, the midrange point will be used as optimization initial point.'
        )
        OWGUI.spin(
            boxGrid,
            self,
            'nInnerPoints',
            1,
            100,
            step=1,
            label='    Number of inner points:',
            tooltip=
            'Number of points to break down each variable to evaluate the initial point.<br>It will evaluate nInnerPoints^nOptimizedVars'
        )

        OWGUI.separator(self.controlArea)

        self.sBox = OWGUI.widgetBox(self.controlArea, "Sampling  Method")
        itms = [e[0] for e in self.SMethods]
        self.comboDistItems = [
            "Continuous", "Power2", "By Step", "Specific Values"
        ]
        OWGUI.radioButtonsInBox(self.sBox, self, "SMethod", btnLabels=itms)

        hBox = OWGUI.widgetBox(OWGUI.indentedBox(self.sBox))
        #QWidget(hBox).setFixedSize(19, 8)
        OWGUI.spin(hBox,
                   self,
                   'nFolds',
                   2,
                   100,
                   step=1,
                   label='Number of Folds:  ')

        OWGUI.separator(self.controlArea)

        box2 = OWGUI.widgetBox(self.controlArea, 'Evaluation Method')
        width = 150
        itms = [e[0] for e in self.CMethods]
        OWGUI.comboBox(
            box2,
            self,
            'CMethod',
            items=itms,
            label='For Classifiers:',
            labelWidth=width,
            orientation='horizontal',
            tooltip='Method used for evaluation in case of classifiers.')
        itms = [e[0] for e in self.RMethods]
        OWGUI.comboBox(
            box2,
            self,
            'RMethod',
            items=itms,
            label='For Regressors:',
            labelWidth=width,
            orientation='horizontal',
            tooltip='Method used for evaluation in case of regressors.')

        OWGUI.separator(self.controlArea)
        OWGUI.button(self.controlArea,
                     self,
                     "&Reload Defaults ",
                     callback=self.reloadDefaults)
        OWGUI.separator(self.controlArea)

        #OWGUI.separator(self.controlArea, height=24)

        infoBox = OWGUI.widgetBox(self.controlArea, "Optimizer status")
        self.infoStatus = OWGUI.label(infoBox, self, 'Waiting for inputs...')
        self.infoPars = OWGUI.label(infoBox, self, '')
        self.infoRes = OWGUI.label(infoBox, self, '')
        OWGUI.label(infoBox, self, '')
        self.infoErr = OWGUI.label(infoBox, self, '')
        OWGUI.separator(self.controlArea)
        OWGUI.button(self.controlArea,
                     self,
                     "&Apply Settings ",
                     callback=self.optimizeParameters)

        # Main area GUI
        import sip
        sip.delete(self.mainArea.layout())
        self.mainLayout = QGridLayout(self.mainArea)

        mainRight = OWGUI.widgetBox(self.mainArea, "Parameters Configuration")
        mainRight.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))

        self.paramsTable = OWGUI.table(
            self.mainArea,
            rows=0,
            columns=0,
            selectionMode=QTableWidget.MultiSelection,
            addToLayout=0)
        #self.paramsTable.setLeftMargin(0)
        self.paramsTable.verticalHeader().hide()
        self.paramsTable.setSelectionMode(QTableWidget.NoSelection)
        self.paramsTable.setColumnCount(len(self.paramsNames))

        #for i, m in enumerate(self.paramsNames):
        #    self.paramsTable.setColumnStretchable(i, 0)
        #    header.setLabel(i, m)
        self.paramsTable.setHorizontalHeaderLabels(self.paramsNames)
        #self.mainLayout.setColumnStretch(1, 100)
        #self.mainLayout.setRowStretch(2, 100)
        self.mainLayout.addWidget(self.paramsTable, 0, 0, 1, 2)
        self.mainLayout.addWidget(
            OWGUI.label(
                mainRight, self,
                'Red - Parameter selected to be optimized\r\nGreen - Parameter optimized\r\nBlack - Parameter will not be optimized'
            ), 1, 0)
        self.mainLayout.addWidget(
            OWGUI.label(
                mainRight, self,
                'N_EX - Number of Examples in dataset\r\nN_ATTR - Number of attributes in dataset'
            ), 1, 1)

        self.adjustSize()
        self.create()
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
    def defineGUI(self):
        OWGUI.lineEdit(
            self.controlArea,
            self,
            "name",
            box="Name",
            tooltip="Name to be used by other widgets to identify your classifier.<br>This should be a unique name!",
        )

        # Queue radio buttons
        self.queueBox = OWGUI.radioButtonsInBox(
            self.controlArea,
            self,
            "outputSel",
            box="Output mode",
            btnLabels=self.outputModes,
            callback=self.changeOutputMode,
        )

        # Queue radio buttons
        self.queueBox = OWGUI.radioButtonsInBox(
            self.controlArea, self, "queueType", box="Execution Mode", btnLabels=self.queueTypes, callback=None
        )

        # create table with selectable ML methods
        self.colNames = ["ML method", "Enabled"]
        mainRight = OWGUI.widgetBox(self.controlArea, "ML methods selection")
        mainRight.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding))

        self.mlTable = OWGUI.table(
            self.controlArea, rows=0, columns=0, selectionMode=QTableWidget.MultiSelection, addToLayout=1
        )
        self.mlTable.verticalHeader().hide()
        self.mlTable.setSelectionMode(QTableWidget.NoSelection)
        self.mlTable.setColumnCount(len(self.colNames))
        self.mlTable.setHorizontalHeaderLabels(self.colNames)

        # Set location of statistics file
        boxFile = OWGUI.widgetBox(self.controlArea, "Path for saving the results", addSpace=True, orientation=0)
        L1 = OWGUI.lineEdit(
            boxFile,
            self,
            "statPath",
            labelWidth=80,
            orientation="horizontal",
            tooltip="Please use full path to results file to be created.",
        )
        L1.setMinimumWidth(200)
        button = OWGUI.button(
            boxFile, self, "...", callback=self.setStatSaveDir, disabled=0, tooltip="Choose the dir where to save."
        )
        button.setMaximumWidth(25)

        # Apply the settings and send the model to the output channel
        OWGUI.button(self.controlArea, self, "&Apply settings", callback=self.Apply)

        # Set location of model file
        self.boxFile = OWGUI.widgetBox(self.controlArea, "Path for saving Model", addSpace=True, orientation=0)
        self.L1 = OWGUI.lineEdit(
            self.boxFile,
            self,
            "modelFile",
            labelWidth=80,
            orientation="horizontal",
            tooltip="Once a model is created (connect this widget with a data widget), \nit can be saved by giving a file name here and clicking the save button.",
        )
        self.L1.setMinimumWidth(200)
        self.button = OWGUI.button(
            self.boxFile,
            self,
            "...",
            callback=self.setModelSavePath,
            disabled=0,
            tooltip="Choose the dir where to save. After chosen, add a name for the model file!",
        )
        self.button.setMaximumWidth(25)

        # Save the model
        self.saveButton = OWGUI.button(self.controlArea, self, "&Save model", callback=self.saveModel)

        # Statistics show
        statBox = OWGUI.widgetBox(self.mainArea, "Statistics", addSpace=True, orientation=0)
        self.statInfoBox = OWGUI.widgetLabel(statBox, "")

        # Save the model
        OWGUI.button(self.mainArea, self, "&Save statistics", callback=self.saveStat)

        self.fillMLtable()

        self.changeOutputMode()
        self.adjustSize()