Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
content = self.customClassSplits.replace(":", " ").replace(",", " ").replace("-", " ").split()
customs = dict.fromkeys([float(x) for x in content]).keys() # remove duplicates (except 8.0, 8.000 ...)
customs.sort()
except:
customs = []
if not customs:
discType = 0
try:
if discType == 0:
discretizer = orange.EquiNDiscretization(classVar, self.originalData, numberOfIntervals = self.classIntervals)
elif discType == 1:
discretizer = orange.EquiDistDiscretization(classVar, self.originalData, numberOfIntervals = self.classIntervals)
else:
discretizer = orange.IntervalDiscretizer(points = customs).constructVariable(classVar)
self.discClassData = orange.ExampleTable(orange.Domain(self.originalData.domain.attributes, discretizer), self.originalData)
if self.data:
self.data = self.discClassData
# else, the data has no continuous attributes other then the class
self.classIntervalsLabel.setText("Current splits: " + ", ".join([str(classVar(x)) for x in discretizer.getValueFrom.transformer.points]))
self.error(0)
self.warning(0)
return True
except:
if self.data:
self.warning(0, "Cannot discretize the class; using previous class")
else:
self.error(0, "Cannot discretize the class")
self.classIntervalsLabel.setText("")
content = self.customClassSplits.replace(":", " ").replace(",", " ").replace("-", " ").split()
customs = dict.fromkeys([float(x) for x in content]).keys() # remove duplicates (except 8.0, 8.000 ...)
customs.sort()
except:
customs = []
if not customs:
discType = 0
try:
if discType == 0:
discretizer = orange.EquiNDiscretization(classVar, self.originalData, numberOfIntervals = self.classIntervals)
elif discType == 1:
discretizer = orange.EquiDistDiscretization(classVar, self.originalData, numberOfIntervals = self.classIntervals)
else:
discretizer = orange.IntervalDiscretizer(points = customs).constructVariable(classVar)
self.discClassData = orange.ExampleTable(orange.Domain(self.originalData.domain.attributes, discretizer), self.originalData)
if self.data:
self.data = self.discClassData
# else, the data has no continuous attributes other then the class
self.classIntervalsLabel.setText("Current splits: " + ", ".join([str(classVar(x)) for x in discretizer.getValueFrom.transformer.points]))
self.error(0)
self.warning(0)
return True
except:
if self.data:
self.warning(0, "Cannot discretize the class; using previous class")
else:
self.error(0, "Cannot discretize the class")
self.classIntervalsLabel.setText("")
print "\nDiscretized attribute:", sep_w
print "Continuous attribute:", sep_w.getValueFrom.whichVar
print "Cut-off points:", sep_w.getValueFrom.transformer.points
print "\nManual construction of IntervalDiscretizer - single attribute"
idisc = orange.IntervalDiscretizer(points = [3.0, 5.0])
sep_l = idisc.constructVariable(data.domain["sepal length"])
data2 = data.select([data.domain["sepal length"], sep_l, data.domain.classVar])
for ex in data2[:10]:
print ex
print "\nManual construction of IntervalDiscretizer - all attributes"
idisc = orange.IntervalDiscretizer(points = [3.0, 5.0])
newattrs = [idisc.constructVariable(attr) for attr in data.domain.attributes]
data2 = data.select(newattrs + [data.domain.classVar])
for ex in data2[:10]:
print ex
print "\n\nEqual interval size discretization"
disc = orange.EquiDistDiscretization(numberOfIntervals = 6)
newattrs = [disc(attr, data) for attr in data.domain.attributes]
data2 = data.select(newattrs + [data.domain.classVar])
for attr in newattrs:
print "%s: %s" % (attr.name, attr.values)
print
for attr in newattrs:
else:
slot = 0
self.indiDiscretization = slot + self.D_N_METHODS + 1
print "T", slot, self.indiDiscretization
idx = self.continuousIndices[self.selectedAttr]
attr = self.data.domain[idx]
cp = list(self.graph.curCutPoints)
cp.sort()
splits = [str(attr(i)) for i in cp]
splitsTxt = " ".join(splits)
self.indiData[idx][0] = self.indiDiscretization
self.indiData[idx][2+slot] = self.customSplits[slot] = splits
self.customLineEdits[slot].setText(splitsTxt)
discretizer = orange.IntervalDiscretizer(points = cp).constructVariable(attr)
self.discretizers[idx] = discretizer
self.indiLabels[self.selectedAttr] = ": " + splitsTxt + self.shortDiscNames[self.indiDiscretization]
self.attrList.triggerUpdate(0)
self.pointsChanged = False
self.commitIf()
def computeAddedScore(self, spoints):
candidateSplits = [x for x in frange(self.minVal, self.maxVal, self.resolution) if x not in spoints]
idisc = orange.IntervalDiscretizer(points = [-99999] + spoints)
var = idisc.constructVariable(self.data.domain[self.master.continuousIndices[self.master.selectedAttr]])
measure = self.master.measures[self.master.measure][1]
score=[]
chisq = self.master.measure == 2
for cut in candidateSplits:
idisc.points = spoints + [cut]
idisc.points.sort()
score.append(measure(var, self.data))
return candidateSplits, score
return
discType -= 1
try:
if discType == self.D_LEAVE: # leave continuous
discretizer = None
elif discType == self.D_ENTROPY:
discretizer = orange.EntropyDiscretization(attr, self.data)
elif discType == self.D_FREQUENCY:
discretizer = orange.EquiNDiscretization(attr, self.data, numberOfIntervals = intervals)
elif discType == self.D_WIDTH:
discretizer = orange.EquiDistDiscretization(attr, self.data, numberOfIntervals = intervals)
elif discType == self.D_REMOVE:
discretizer = False
else:
discretizer = orange.IntervalDiscretizer(points = customs).constructVariable(attr)
except:
discretizer = False
self.discretizers[idx] = discretizer
if discType == self.D_LEAVE:
discInts = ""
elif discType == self.D_REMOVE:
discInts = ""
elif not discretizer:
discInts = ": "+""
else:
points = discretizer.getValueFrom.transformer.points
discInts = points and (": " + ", ".join([str(attr(x)) for x in points])) or ": "+""
self.indiLabels[i] = discInts + discName
import orange
def printexamples(data, inxs, msg="First %i examples"):
print msg % len(inxs)
for i in inxs:
print data[i]
print
iris = orange.ExampleTable("iris")
pl = orange.EnumVariable("pl")
getValue = orange.ClassifierFromVar()
getValue.whichVar = iris.domain["petal length"]
getValue.classVar = pl
getValue.transformer = orange.IntervalDiscretizer()
getValue.transformer.points = [2.0, 4.0]
pl.getValueFrom = getValue
pl.values = ['low', 'medium', 'high']
d_iris = iris.select(["petal length", pl, iris.domain.classVar])
printexamples(d_iris, [0, 15, 35, 50, 98], "%i examples after discretization")
def computeAddedScore(self, spoints):
candidateSplits = [x for x in frange(self.minVal, self.maxVal, self.resolution) if x not in spoints]
idisc = orange.IntervalDiscretizer(points = [-99999] + spoints)
var = idisc.constructVariable(self.data.domain[self.master.continuousIndices[self.master.selectedAttr]])
measure = self.master.measures[self.master.measure][1]
score=[]
chisq = self.master.measure == 2
for cut in candidateSplits:
idisc.points = spoints + [cut]
idisc.points.sort()
score.append(measure(var, self.data))
return candidateSplits, score
def computeAddedScore(self, spoints):
candidateSplits = [x for x in frange(self.minVal, self.maxVal, self.resolution) if x not in spoints]
idisc = orange.IntervalDiscretizer(points = [-99999] + spoints)
var = idisc.constructVariable(self.data.domain[self.master.continuousIndices[self.master.selectedAttr]])
measure = self.master.measures[self.master.measure][1]
score=[]
chisq = self.master.measure == 2
for cut in candidateSplits:
idisc.points = spoints + [cut]
idisc.points.sort()
score.append(measure(var, self.data))
return candidateSplits, score