Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __incFreqWord(self, ex, w):
domain = ex.domain
if domain.hasmeta(w):
id = domain.metaid(w)
if ex.hasmeta(id):
ex[id] += 1.0
else:
ex[id] = 1.0
else:
id = orange.newmetaid()
domain.addmeta(id, orange.FloatVariable(w), True)
ex[id] = 1.0
metaIDs.append(metaID)
corMetaIDs = []
if correlationsAsMeta:
for dim in dimensions:
metaVar = orange.FloatVariable("corr(%s)" % cache.attributes[dim][0])
metaID = orange.newmetaid()
dom.addmeta(metaID, metaVar)
corMetaIDs.append(metaID)
metaVar = orange.FloatVariable("corr")
metaID = orange.newmetaid()
dom.addmeta(metaID, metaVar)
corMetaIDs.append(metaID)
if originalAsMeta:
originalID = orange.newmetaid()
dom.addmeta(originalID, data.domain.classVar)
else:
originalID = 0
paded = orange.ExampleTable(dom, data)
for i, (pad, alldeltas) in enumerate(zip(paded, cache.deltas)):
deltas = [alldeltas[d] for d in dimensions]
if needQ:
qs = "".join([(delta > threshold and "0") or (delta < -threshold and "1") or (delta == "?" and "?") or "2" for delta in deltas])
q = ("?" in qs and "?") or int(qs, 3)
if outputAttr >= 0:
pad.setclass(alldeltas[outputAttr])
d2 = orange.Domain(["a", "b", "e", "y"], data.domain)
example = data[55]
print example
example2 = d2(example)
print example2
example2 = orange.Example(d2, example)
print example2
data2 = orange.ExampleTable(d2, data)
print data2[55]
d2.addmeta(orange.newmetaid(), orange.FloatVariable("w"))
data2 = orange.ExampleTable(d2, data)
print data2[55]
misses = orange.FloatVariable("misses")
id = orange.newmetaid()
data.domain.addmeta(id, misses)
print data[55]
print data.domain.hasmeta(id)
print data.domain.hasmeta(id-1)
for example in data:
example[misses] = 0
classifier = orange.BayesLearner(data)
for example in data:
def sendList(self, selectedInd):
if self.data and type(self.data[0]) == str:
xAttr=orange.FloatVariable("X")
yAttr=orange.FloatVariable("Y")
nameAttr= orange.StringVariable("name")
if self.selectionOptions == 1:
domain = orange.Domain([xAttr, yAttr, nameAttr])
selection = orange.ExampleTable(domain)
for i in range(len(selectedInd)):
selection.append(list(self.mds.points[selectedInd[i]]) + [self.data[i]])
else:
domain = orange.Domain([nameAttr])
if self.selectionOptions:
domain.addmeta(orange.newmetaid(), xAttr)
domain.addmeta(orange.newmetaid(), yAttr)
selection = orange.ExampleTable(domain)
for i in range(len(selectedInd)):
selection.append([self.data[i]])
if self.selectionOptions:
selection[i][xAttr]=self.mds.points[selectedInd[i]][0]
selection[i][yAttr]=self.mds.points[selectedInd[i]][1]
self.send("Data", selection)
return
if not selectedInd:
self.send("Structured Data Files", None)
else:
datasets=[self.data[i] for i in selectedInd]
names=list(set([d.dirname for d in datasets]))
data=[(name, [d for d in filter(lambda a:a.strain==name, datasets)]) for name in names]
self.send("Structured Data Files",data)
needQ = outputAttr < 0 or derivativeAsMeta
if needQ:
qVar = createClassVar([cache.attributes[i][0] for i in dimensions], MQCNotation)
if outputAttr >= 0:
classVar = orange.FloatVariable("df/d"+cache.attributes[outputAttr][0])
else:
classVar = qVar
dom = orange.Domain(data.domain.attributes, classVar)
dom.addmetas(data.domain.getmetas())
setattr(dom, "constraintAttributes", [cache.contAttributes[i] for i in dimensions])
if derivativeAsMeta:
derivativeID = orange.newmetaid()
dom.addmeta(derivativeID, qVar)
else:
derivativeID = 0
metaIDs = []
if differencesAsMeta:
for dim in dimensions:
metaVar = orange.FloatVariable("df/d"+cache.attributes[dim][0])
metaID = orange.newmetaid()
dom.addmeta(metaID, metaVar)
metaIDs.append(metaID)
corMetaIDs = []
if correlationsAsMeta:
for dim in dimensions:
metaVar = orange.FloatVariable("corr(%s)" % cache.attributes[dim][0])
if km is None:
km = self.bestRun[1] if self.optimized else self.km
if not self.data or not km:
self.send("Data", None)
self.send("Centroids", None)
return
clustVar = orange.EnumVariable(self.classifyName,
values=["C%d" % (x + 1) \
for x in range(km.k)])
origDomain = self.data.domain
if self.addIdAs == 0:
domain = orange.Domain(origDomain.attributes, clustVar)
if origDomain.classVar:
domain.addmeta(orange.newmetaid(), origDomain.classVar)
aid = -1
elif self.addIdAs == 1:
domain = orange.Domain(origDomain.attributes + [clustVar],
origDomain.classVar)
aid = len(origDomain.attributes)
else:
domain = orange.Domain(origDomain.attributes,
origDomain.classVar)
aid = orange.newmetaid()
domain.addmeta(aid, clustVar)
domain.addmetas(origDomain.getmetas())
# construct a new data set, with a class as assigned by
# k-means clustering
new = orange.ExampleTable(domain, self.data)
def sendExampleTable(self, selectedInd):
if self.selectionOptions == 0:
self.send("Data", orange.ExampleTable(self.data.getitems(selectedInd)))
else:
xAttr = orange.FloatVariable("X")
yAttr = orange.FloatVariable("Y")
if self.selectionOptions == 1:
domain = orange.Domain([xAttr, yAttr] +
[v for v in self.data.domain.variables])
domain.addmetas(self.data.domain.getmetas())
else:
domain = orange.Domain(self.data.domain)
domain.addmeta(orange.newmetaid(), xAttr)
domain.addmeta(orange.newmetaid(), yAttr)
selection = orange.ExampleTable(domain)
selection.extend(self.data.getitems(selectedInd))
for i in range(len(selectedInd)):
selection[i][xAttr] = self.mds.points[selectedInd[i]][0]
selection[i][yAttr] = self.mds.points[selectedInd[i]][1]
self.send("Data", selection)
return
selection = self.networkCanvas.selected_nodes()
if len(selection) == 1:
modelInstance = self.graph.items()[selection[0]]
# modelInfo - Python Dict; keys: method, classifier, probabilities,
# results, XAnchors, YAnchors, attributes
modelInfo = self.graph_matrix.results[modelInstance['uuid'].value]
#uuid = modelInstance["uuid"].value
#method, vizr_result, projection_points, classifier, attrs = self.matrix.results[uuid]
if 'YAnchors' in modelInfo and 'XAnchors' in modelInfo:
if not modelInstance.domain.hasmeta('anchors'):
modelInstance.domain.addmeta(orange.newmetaid(), orange.PythonVariable('anchors'))
modelInstance['anchors'] = (modelInfo['XAnchors'], modelInfo['YAnchors'])
if 'classifier' in modelInfo and modelInfo['classifier'] is not None:
if not modelInstance.domain.hasmeta('classifier'):
modelInstance.domain.addmeta(orange.newmetaid(), orange.PythonVariable('classifier'))
modelInstance['classifier'] = modelInfo['classifier']
self.send('Classifier', modelInfo['classifier'])
self.send('Model', modelInstance)
self.send('Selected Models', self.graph.items().getitems(selection))
elif len(selection) > 1:
self.send('Model', None)
self.send('Selected Models', self.graph.items().getitems(selection))
else:
self.send('Model', None)
self.send('Selected Models', None)
domain.addmetas(data.domain.getmetas())
data = orange.ExampleTable(domain, data)
if self.appendPredictions:
cname = self.learnerNames[learnerI]
predVar = type(domain.classVar)("%s(%s)" % (domain.classVar.name, cname.encode("utf-8") if isinstance(cname, unicode) else cname))
if hasattr(domain.classVar, "values"):
predVar.values = domain.classVar.values
predictionsId = orange.newmetaid()
domain.addmeta(predictionsId, predVar)
for i, ex in zip(selectionIndices, data):
ex[predictionsId] = res.results[i].classes[learnerI]
if self.appendProbabilities:
probVars = [orange.FloatVariable("p(%s)" % v) for v in domain.classVar.values]
probIds = [orange.newmetaid() for pv in probVars]
domain.addmetas(dict(zip(probIds, probVars)))
for i, ex in zip(selectionIndices, data):
for id, p in zip(probIds, res.results[i].probabilities[learnerI]):
ex[id] = p
if data is not None:
data.name = self.learnerNames[learnerI]
self.send("Selected Data", data)