How to use the orange.MakeRandomIndices2 function in Orange

To help you get started, we’ve selected a few Orange examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biolab / orange2 / orange / doc / ofb-rst / code / regression2.py View on Github external
# Description: Builds regression models from data and outputs predictions for first five instances
# Category:    modelling
# Uses:        housing
# Classes:     MakeRandomIndices2, MajorityLearner, orngTree.TreeLearner, orange.kNNLearner
# Referenced:  regression.htm

import orange, orngTree, orngTest, orngStat

data = orange.ExampleTable("housing.tab")
selection = orange.MakeRandomIndices2(data, 0.5)
train_data = data.select(selection, 0)
test_data = data.select(selection, 1)

maj = orange.MajorityLearner(train_data)
maj.name = "default"

rt = orngTree.TreeLearner(train_data, measure="retis", mForPruning=2, minExamples=20)
rt.name = "reg. tree"

k = 5
knn = orange.kNNLearner(train_data, k=k)
knn.name = "k-NN (k=%i)" % k

regressors = [maj, rt, knn]

print "\n%10s " % "original",
github biolab / orange2 / Orange / OrangeWidgets / Evaluate / OWPredictions.py View on Github external
self.changedFlag = False

##############################################################################
# Test the widget, run from DOS prompt

if __name__=="__main__":
    a = QApplication(sys.argv)
    ow = OWPredictions()
    ow.show()

    import orngTree

    dataset = orange.ExampleTable('../../doc/datasets/iris.tab')
#    dataset = orange.ExampleTable('../../doc/datasets/auto-mpg.tab')
    ind = orange.MakeRandomIndices2(p0=0.5)(dataset)
    data = dataset.select(ind, 0)
    test = dataset.select(ind, 1)
    testnoclass = orange.ExampleTable(orange.Domain(test.domain.attributes, False), test)        
    tree = orngTree.TreeLearner(data)
    tree.name = "tree"
    maj = orange.MajorityLearner(data)
    maj.name = "maj"
    knn = orange.kNNLearner(data, k = 10)
    knn.name = "knn"
    
#    ow.setData(test)
#    
#    ow.setPredictor(maj, 1)
github biolab / orange2 / orange / OrangeWidgets / Prototypes / OWMoleculeVisualizer.py View on Github external
def filterSmilesVariables(self, data):
        candidates=data.domain.variables+data.domain.getmetas().values()
        candidates=filter(lambda v:v.varType==orange.VarTypes.Discrete or v.varType==orange.VarTypes.String, candidates)
        if len(data)>20:
            data=data.select(orange.MakeRandomIndices2(data, 20))
        vars=[]
        if localOpenEye:
            isValidSmiles = lambda s: OEParseSmiles(OEGraphMol(), s)
        else:
            from openbabel import OBConversion, OBMol
            loader = OBConversion()
            loader.SetInAndOutFormats("smi", "smi")
            isValidSmiles = lambda s: loader.ReadString(OBMol(), s)
            
        import os
        tmpFd1=os.dup(1)
        tmpFd2=os.dup(2)
        fd=os.open(os.devnull, os.O_APPEND)
##        os.close(1)
        os.dup2(fd, 1)
        os.dup2(fd, 2)
github biolab / orange2 / orange / doc / ofb-rst / code / sample_adult.py View on Github external
# Description: Read 'adult' data set and select 3% of instances (use stratified sampling)
# Category:    preprocessing
# Uses:        adult.tab
# Classes:     ExampleTable, MakeRandomIndices2
# Referenced:  basic_exploration.htm

import orange
data = orange.ExampleTable("../../datasets/adult_sample")
selection = orange.MakeRandomIndices2(data, 0.03)
sample = data.select(selection, 0)
sample.save("adult_sample.tab")
github biolab / orange2 / docs / tutorial / rst / code / sample_adult.py View on Github external
# Description: Read 'adult' data set and select 3% of instances (use stratified sampling)
# Category:    preprocessing
# Uses:        adult.tab
# Classes:     ExampleTable, MakeRandomIndices2
# Referenced:  basic_exploration.htm

import orange
data = orange.ExampleTable("adult_sample.tab")
selection = orange.MakeRandomIndices2(data, 0.03)
sample = data.select(selection, 0)
sample.save("adult_sample.tab")
github biolab / orange2 / docs / tutorial / rst / code / disc7.py View on Github external
# Description: Discretize the test set based on discretization of the training set.
# Category:    preprocessing
# Uses:        iris
# Classes:     Preprocessor_discretize, EntropyDiscretization
# Referenced:  o_categorization.htm

import orange
data = orange.ExampleTable("iris")

#split the data to learn and test set
ind = orange.MakeRandomIndices2(data, p0=6)
learn = data.select(ind, 0)
test = data.select(ind, 1)

# discretize learning set, then use its new domain
# to discretize the test set
learnD = orange.Preprocessor_discretize(data, method=orange.EntropyDiscretization())
testD = orange.ExampleTable(learnD.domain, test)

print "Test set, original:"
for i in range(3):
    print test[i]

print "Test set, discretized:"
for i in range(3):
    print testD[i]
github biolab / orange2 / orange / OrangeWidgets / Associate / OWDistanceMap.py View on Github external
def distanceMatrix(data):
        dist = orange.ExamplesDistanceConstructor_Euclidean(data)
        matrix = orange.SymMatrix(len(data))
        matrix.setattr('items', data)
        for i in range(len(data)):
            for j in range(i+1):
                matrix[i, j] = dist(data[i], data[j])
        return matrix

    import orange
    a = QApplication(sys.argv)
    ow = OWDistanceMap()
    ow.show()

    data = orange.ExampleTable(r'../../doc/datasets/iris.tab')
    data = data.select(orange.MakeRandomIndices2(p0=20)(data), 0)
    for d in data:
        d.name = str(d["sepal length"])
    matrix = distanceMatrix(data)
    ow.setMatrix(matrix)

    a.exec_()

    ow.saveSettings()