本文整理汇总了Python中Orange.data.Variable类的典型用法代码示例。如果您正苦于以下问题:Python Variable类的具体用法?Python Variable怎么用?Python Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_all_models_work_after_unpickling
def test_all_models_work_after_unpickling(self):
Variable._clear_all_caches()
datasets = [Table('iris'), Table('titanic')]
for learner in list(self.all_learners()):
try:
learner = learner()
except Exception:
print('%s cannot be used with default parameters' % learner.__name__)
traceback.print_exc()
continue
# Skip slow tests
if isinstance(learner, _RuleLearner):
continue
for ds in datasets:
model = learner(ds)
s = pickle.dumps(model, 0)
model2 = pickle.loads(s)
np.testing.assert_almost_equal(
Table(model.domain, ds).X, Table(model2.domain, ds).X)
np.testing.assert_almost_equal(
model(ds), model2(ds),
err_msg='%s does not return same values when unpickled %s'
% (learner.__class__.__name__, ds.name))
示例2: setUp
def setUp(self):
""" Override __eq__ for Orange objects that do not implement it"""
self.add_comparator(Domain,
compare_members=("attributes", "class_vars",
"class_var", "variables",
"metas", "anonymous"))
Variable._clear_all_caches()
示例3: test_to_val
def test_to_val(self):
string_var = StringVariable("x")
self.assertEqual(string_var.to_val("foo"), "foo")
self.assertEqual(string_var.to_val(42), "42")
cont_var = ContinuousVariable("x")
self.assertTrue(math.isnan(cont_var.to_val("?")))
self.assertTrue(math.isnan(Unknown))
var = Variable("x")
self.assertEqual(var.to_val("x"), "x")
示例4: create_domain
def create_domain(*ss):
Variable._clear_all_caches()
vars=dict(
age=ContinuousVariable(name="AGE"),
gender=DiscreteVariable(name="Gender", values=["M", "F"]),
incomeA=ContinuousVariable(name="incomeA"),
income=ContinuousVariable(name="income"),
education=DiscreteVariable(name="education", values=["GS", "HS", "C"]),
ssn=StringVariable(name="SSN"),
race=DiscreteVariable(name="race",
values=["White", "Hypsanic", "African", "Other"]))
def map_vars(s):
return [vars[x] for x in s]
return Domain(*[map_vars(s) for s in ss])
示例5: setUpClass
def setUpClass(cls):
"""Prepare environment for test execution
Construct a dummy signal manager and monkey patch
OWReport.get_instance to return a manually created instance.
"""
super().setUpClass()
cls.widgets = []
cls.signal_manager = DummySignalManager()
report = OWReport()
cls.widgets.append(report)
OWReport.get_instance = lambda: report
Variable._clear_all_caches()
示例6: test_properties_as_predicates
def test_properties_as_predicates(self):
a = ContinuousVariable()
self.assertTrue(Variable.is_continuous(a))
self.assertFalse(Variable.is_discrete(a))
self.assertFalse(Variable.is_string(a))
self.assertTrue(Variable.is_primitive(a))
a = StringVariable()
self.assertFalse(Variable.is_continuous(a))
self.assertFalse(Variable.is_discrete(a))
self.assertTrue(Variable.is_string(a))
self.assertFalse(Variable.is_primitive(a))
示例7: test_bad_data
def test_bad_data(self):
"""
Firstly it creates predictions with TreeLearner. Then sends predictions and
different data with different domain to Predictions widget. Those different
data and domain are similar to original data and domain but they have three
different target values instead of two.
GH-2129
"""
Variable._clear_all_caches()
filestr1 = """\
age\tsex\tsurvived
d\td\td
\t\tclass
adult\tmale\tyes
adult\tfemale\tno
child\tmale\tyes
child\tfemale\tyes
"""
file1 = io.StringIO(filestr1)
table = TabReader(file1).read()
learner = TreeLearner()
tree = learner(table)
filestr2 = """\
age\tsex\tsurvived
d\td\td
\t\tclass
adult\tmale\tyes
adult\tfemale\tno
child\tmale\tyes
child\tfemale\tunknown
"""
file2 = io.StringIO(filestr2)
bad_table = TabReader(file2).read()
self.send_signal(self.widget.Inputs.predictors, tree, 1)
with excepthook_catch():
self.send_signal(self.widget.Inputs.data, bad_table)
Variable._clear_all_caches() # so that test excepting standard titanic work
示例8: test_datasets_info_features
def test_datasets_info_features(self):
print(datasets.items())
for dataset, info in datasets.items():
Variable._clear_all_caches()
if info['location'].startswith('http'): continue # Tested elsewhere
table = Table(dataset)
domain = table.domain
# Test features
self.assertEqual(table.X.shape[0], info['rows'], dataset)
self.assertEqual(table.has_missing(), info['missing'], dataset)
self.assertEqual(len(domain.metas), info['features']['meta'], dataset)
self.assertEqual(sum(i.is_discrete for i in domain.attributes),
info['features']['discrete'],
dataset)
self.assertEqual(sum(i.is_continuous for i in domain.attributes),
info['features']['continuous'],
dataset)
# Test class vars
if len(domain.class_vars) > 1:
self.assertEqual(['discrete' if i.is_discrete else 'continuous'
for i in domain.class_vars],
info['target']['type'],
dataset)
elif len(domain.class_vars) == 1:
cls = domain.class_var
self.assertEqual('discrete' if cls.is_discrete else 'continuous',
info['target']['type'],
dataset)
if cls.is_discrete:
self.assertEqual(len(cls.values), info['target']['values'], dataset)
else:
self.assertEqual(False, info['target']['type'], dataset)
示例9: setUp
def setUp(self):
Variable._clear_all_caches()
data.table.dataset_dirs.append(test_dirname())
示例10: setUp
def setUp(self):
Variable._clear_all_caches()
random.seed(42)
self.zoo = Table("zoo")
示例11: setUp
def setUp(self):
Variable._clear_all_caches()
示例12: test_unpickling_recreates_known_domains
def test_unpickling_recreates_known_domains(self):
Variable._clear_all_caches()
domain = Domain([])
unpickled_domain = pickle.loads(pickle.dumps(domain))
self.assertTrue(hasattr(unpickled_domain, '_known_domains'))
示例13: setUp
def setUp(self):
Variable._clear_all_caches() # pylint: disable=protected-access
random.seed(42)
self.zoo = Table("zoo")
示例14: setUp
def setUp(self):
Variable._clear_all_caches()
dataset_dirs.append("Orange/tests")
示例15: init
def init(self):
Variable._clear_all_caches()
self.data = Table("iris")