orange / docs / extend-widgets / rst / OWDataSamplerB.py

Miha Stajdohar f4dd8db 


Aleš Erjavec 6edc44e 
Miha Stajdohar f4dd8db 

Aleš Erjavec 6edc44e 
Miha Stajdohar f4dd8db 





Aleš Erjavec 6edc44e 
Miha Stajdohar f4dd8db 
Aleš Erjavec 6edc44e 

Miha Stajdohar f4dd8db 

































Aleš Erjavec 6edc44e 
Miha Stajdohar f4dd8db 















Aleš Erjavec 6edc44e 
Miha Stajdohar f4dd8db 
"""
<name>Data Sampler (B)</name>
<description>Randomly selects a subset of instances from the data set</description>
<icon>icons/DataSamplerB.svg</icon>
<priority>20</priority>
"""
import Orange
from OWWidget import *
import OWGUI

class OWDataSamplerB(OWWidget):
    settingsList = ['proportion', 'commitOnChange']
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager)

        self.inputs = [("Data", Orange.data.Table, self.data)]
        self.outputs = [("Sampled Data", Orange.data.Table)]

        self.proportion = 50
        self.commitOnChange = 0
        self.loadSettings()

        # GUI
        box = OWGUI.widgetBox(self.controlArea, "Info")
        self.infoa = OWGUI.widgetLabel(box, 'No data on input yet, waiting to get something.')
        self.infob = OWGUI.widgetLabel(box, '')

        OWGUI.separator(self.controlArea)
        self.optionsBox = OWGUI.widgetBox(self.controlArea, "Options")
        OWGUI.spin(self.optionsBox, self, 'proportion', min=10, max=90, step=10,
                   label='Sample Size [%]:', callback=[self.selection, self.checkCommit])
        OWGUI.checkBox(self.optionsBox, self, 'commitOnChange', 'Commit data on selection change')
        OWGUI.button(self.optionsBox, self, "Commit", callback=self.commit)
        self.optionsBox.setDisabled(1)

        self.resize(100,50)

    def data(self, dataset):
        if dataset:
            self.dataset = dataset
            self.infoa.setText('%d instances in input data set' % len(dataset))
            self.optionsBox.setDisabled(0)
            self.selection()
            self.commit()
        else:
            self.send("Sampled Data", None)
            self.optionsBox.setDisabled(1)
            self.infoa.setText('No data on input yet, waiting to get something.')
            self.infob.setText('')

    def selection(self):
        indices = Orange.data.sample.SubsetIndices2(p0=self.proportion / 100.)
        ind = indices(self.dataset)
        self.sample = self.dataset.select(ind, 0)
        self.infob.setText('%d sampled instances' % len(self.sample))

    def commit(self):
        self.send("Sampled Data", self.sample)

    def checkCommit(self):
        if self.commitOnChange:
            self.commit()


if __name__=="__main__":
    appl = QApplication(sys.argv)
    ow = OWDataSamplerB()
    ow.show()
    dataset = Orange.data.Table('iris.tab')
    ow.data(dataset)
    appl.exec_()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.