Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
newdomain = orange.Domain(self.data.domain)
newdomain.addmeta(orange.newmetaid(), orange.FloatVariable("Z score"))
self.newdata = orange.ExampleTable(newdomain, self.data)
zv = outlier.zValues()
for i, el in enumerate(zv):
self.newdata[i]["Z score"] = el
self.send("Data with z-score", self.newdata)
filterout = orange.Filter_values(domain=self.newdata.domain)
filterout["Z score"] = (orange.Filter_values.Greater, eval(self.zscore))
outliers = filterout(self.newdata)
filterin = orange.Filter_values(domain=self.newdata.domain)
filterin["Z score"] = (orange.Filter_values.LessEqual, eval(self.zscore))
inliers = filterin(self.newdata)
self.send("Outliers", outliers)
self.send("Inliers", inliers)
else:
self.send("Data with z-score", None)
self.send("Outliers", None)
self.send("Inliers", None)
self.val2 = value2 # string/float
self.caseSensitive = caseSensitive # True/False
class Operator:
operatorsD = staticmethod(["equals","in"])
operatorsC = staticmethod(["=","<","<=",">",">=","between","outside"])
operatorsS = staticmethod(["=","<","<=",">",">=","contains","begins with","ends with","between","outside"])
operatorDef = staticmethod("is defined")
getOperators = staticmethod(lambda: Operator.operatorsD + Operator.operatorsS + [Operator.operatorDef])
_operFilter = {"=":orange.Filter_values.Equal,
"<":orange.Filter_values.Less,
"<=":orange.Filter_values.LessEqual,
">":orange.Filter_values.Greater,
">=":orange.Filter_values.GreaterEqual,
"between":orange.Filter_values.Between,
"outside":orange.Filter_values.Outside,
"contains":orange.Filter_values.Contains,
"begins with":orange.Filter_values.BeginsWith,
"ends with":orange.Filter_values.EndsWith}
def __init__(self, operator, varType):
"""Members: operator, varType, isInterval.
"""
assert operator in Operator.getOperators(), "Unknown operator: %s" % str(operator)
self.operator = operator
self.varType = varType
self.isInterval = False
if operator in Operator.operatorsC and Operator.operatorsC.index(operator) > 4 \
or operator in Operator.operatorsD and Operator.operatorsD.index(operator) > 0 \
or operator in Operator.operatorsS and Operator.operatorsS.index(operator) > 7:
self.negated = negate # True/False
self.val1 = value1 # string/float
self.val2 = value2 # string/float
self.caseSensitive = caseSensitive # True/False
class Operator:
operatorsD = staticmethod(["equals","in"])
operatorsC = staticmethod(["=","<","<=",">",">=","between","outside"])
operatorsS = staticmethod(["=","<","<=",">",">=","contains","begins with","ends with","between","outside"])
operatorDef = staticmethod("is defined")
getOperators = staticmethod(lambda: Operator.operatorsD + Operator.operatorsS + [Operator.operatorDef])
_operFilter = {"=":orange.Filter_values.Equal,
"<":orange.Filter_values.Less,
"<=":orange.Filter_values.LessEqual,
">":orange.Filter_values.Greater,
">=":orange.Filter_values.GreaterEqual,
"between":orange.Filter_values.Between,
"outside":orange.Filter_values.Outside,
"contains":orange.Filter_values.Contains,
"begins with":orange.Filter_values.BeginsWith,
"ends with":orange.Filter_values.EndsWith}
def __init__(self, operator, varType):
"""Members: operator, varType, isInterval.
"""
assert operator in Operator.getOperators(), "Unknown operator: %s" % str(operator)
self.operator = operator
self.varType = varType
self.isInterval = False
if operator in Operator.operatorsC and Operator.operatorsC.index(operator) > 4 \
operatorsC = staticmethod(["=","<","<=",">",">=","between","outside"])
operatorsS = staticmethod(["=","<","<=",">",">=","contains","begins with","ends with","between","outside"])
operatorDef = staticmethod("is defined")
getOperators = staticmethod(lambda: Operator.operatorsD + Operator.operatorsS + [Operator.operatorDef])
negations = {"equals": "does not equal", "in": "is not in",
"between": "not between", "outside": "not outside",
"contains": "does not contain", "begins with": "does not begin with", "ends with": "does not end with",
"is defined": "is undefined"}
_operFilter = {"=":orange.Filter_values.Equal,
"<":orange.Filter_values.Less,
"<=":orange.Filter_values.LessEqual,
">":orange.Filter_values.Greater,
">=":orange.Filter_values.GreaterEqual,
"between":orange.Filter_values.Between,
"outside":orange.Filter_values.Outside,
"contains":orange.Filter_values.Contains,
"begins with":orange.Filter_values.BeginsWith,
"ends with":orange.Filter_values.EndsWith}
def __init__(self, operator, varType):
"""Members: operator, varType, isInterval.
"""
assert operator in Operator.getOperators(), "Unknown operator: %s" % str(operator)
self.operator = operator
self.varType = varType
self.isInterval = False
if operator in Operator.operatorsC and Operator.operatorsC.index(operator) > 4 \
or operator in Operator.operatorsD and Operator.operatorsD.index(operator) > 0 \
or operator in Operator.operatorsS and Operator.operatorsS.index(operator) > 7:
self.isInterval = True
if self.haveInput == 1:
outlier = self.outlier
outlier.setKNN(self.ks[self.k][1])
newdomain = orange.Domain(self.data.domain)
newdomain.addmeta(orange.newmetaid(), orange.FloatVariable("Z score"))
self.newdata = orange.ExampleTable(newdomain, self.data)
zv = outlier.zValues()
for i, el in enumerate(zv):
self.newdata[i]["Z score"] = el
self.send("Data with z-score", self.newdata)
filterout = orange.Filter_values(domain=self.newdata.domain)
filterout["Z score"] = (orange.Filter_values.Greater, eval(self.zscore))
outliers = filterout(self.newdata)
filterin = orange.Filter_values(domain=self.newdata.domain)
filterin["Z score"] = (orange.Filter_values.LessEqual, eval(self.zscore))
inliers = filterin(self.newdata)
self.send("Outliers", outliers)
self.send("Inliers", inliers)
else:
self.send("Data with z-score", None)
self.send("Outliers", None)
self.send("Inliers", None)
for ex in fcont(data):
print ex
fcont[0] = (orange.ValueFilter.Outside, 4.6, 7.5)
print "\n\nThe first attribute is between to 4.5 and 5.0"
for ex in fcont(data):
print ex
############ THIS IS WHAT YOU CAN DO WITH STRING ATTRIBUTES
data.domain.addmeta(orange.newmetaid(), orange.StringVariable("name"))
for ex in data:
ex["name"] = str(ex.getclass())
fstr = orange.Filter_values(domain = data.domain)
fstr["name"] = "Iris-setosa"
print "\n\nSetosae"
d = fstr(data)
print "%i examples, starting with %s" % (len(d), d[0])
fstr["name"] = ["Iris-setosa", "Iris-virginica"]
print "\n\nSetosae and virginicae"
d = fstr(data)
print "%i examples, starting with %s\n finishing with %s" % (len(d), d[0], d[-1])
fstr["name"] = ["Iris-setosa", "Iris-viRGInica"]
fstr["name"].caseSensitive = 1
print "\n\nSetosae and viRGInicae (case sensitive)"
d = fstr(data)
print "%i examples, starting with %s\n finishing with %s" % (len(d), d[0], d[-1])
print ex
fya["age"] = ["presbyopic", "young"]
print "\n\nYoung and presbyopic examples\n"
for ex in fya(data):
print ex
astigm = data.domain["astigmatic"]
fya["age"] = ["presbyopic", "young"]
fya[astigm] = "yes"
print "\n\nYoung and presbyopic examples that are astigmatic\n"
for ex in fya(data):
print ex
fr = orange.Filter_values(domain = data.domain)
fr[3] = "reduced"
# Conjunction is not necessary here - we could still do this with a single filter
fcon = orange.Filter_conjunction([fya, fr])
print "\n\nYoung and presbyopic examples that are astigmatic and have reduced tear rate\n"
for ex in fcon(data):
print ex
fcon = orange.Filter_disjunction([fya, fr])
print "\n\nYoung and presbyopic asticmatic examples and examples that have reduced tear rate\n"
for ex in fcon(data):
print ex
############ THIS IS WHAT YOU CAN DO WITH CONTINUOUS ATTRIBUTES
negations = {"equals": "does not equal", "in": "is not in",
"between": "not between", "outside": "not outside",
"contains": "does not contain", "begins with": "does not begin with", "ends with": "does not end with",
"is defined": "is undefined"}
_operFilter = {"=":orange.Filter_values.Equal,
"<":orange.Filter_values.Less,
"<=":orange.Filter_values.LessEqual,
">":orange.Filter_values.Greater,
">=":orange.Filter_values.GreaterEqual,
"between":orange.Filter_values.Between,
"outside":orange.Filter_values.Outside,
"contains":orange.Filter_values.Contains,
"begins with":orange.Filter_values.BeginsWith,
"ends with":orange.Filter_values.EndsWith}
def __init__(self, operator, varType):
"""Members: operator, varType, isInterval.
"""
assert operator in Operator.getOperators(), "Unknown operator: %s" % str(operator)
self.operator = operator
self.varType = varType
self.isInterval = False
if operator in Operator.operatorsC and Operator.operatorsC.index(operator) > 4 \
or operator in Operator.operatorsD and Operator.operatorsD.index(operator) > 0 \
or operator in Operator.operatorsS and Operator.operatorsS.index(operator) > 7:
self.isInterval = True
def __eq__(self, other):
assert other in Operator.getOperators()
return self.operator == other