本文整理汇总了Python中Orange.data.DiscreteVariable.make方法的典型用法代码示例。如果您正苦于以下问题:Python DiscreteVariable.make方法的具体用法?Python DiscreteVariable.make怎么用?Python DiscreteVariable.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.data.DiscreteVariable
的用法示例。
在下文中一共展示了DiscreteVariable.make方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_colors
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_colors(self):
var = DiscreteVariable.make("a", values=["F", "M"])
self.assertIsNone(var._colors)
self.assertEqual(var.colors.shape, (2, 3))
self.assertIs(var._colors, var.colors)
self.assertEqual(var.colors.shape, (2, 3))
self.assertFalse(var.colors.flags.writeable)
var.colors = np.arange(6).reshape((2, 3))
np.testing.assert_almost_equal(var.colors, [[0, 1, 2], [3, 4, 5]])
self.assertFalse(var.colors.flags.writeable)
with self.assertRaises(ValueError):
var.colors[0] = [42, 41, 40]
var.set_color(0, [42, 41, 40])
np.testing.assert_almost_equal(var.colors, [[42, 41, 40], [3, 4, 5]])
var = DiscreteVariable.make("x", values=["A", "B"])
var.attributes["colors"] = ['#0a0b0c', '#0d0e0f']
np.testing.assert_almost_equal(var.colors, [[10, 11, 12], [13, 14, 15]])
# Test ncolors adapts to nvalues
var = DiscreteVariable.make('foo', values=['d', 'r'])
self.assertEqual(len(var.colors), 2)
var.add_value('e')
self.assertEqual(len(var.colors), 3)
user_defined = (0, 0, 0)
var.set_color(2, user_defined)
var.add_value('k')
self.assertEqual(len(var.colors), 4)
np.testing.assert_array_equal(var.colors[2], user_defined)
示例2: test_repr
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_repr(self):
var = DiscreteVariable.make("a", values=["F", "M"])
self.assertEqual(
repr(var),
"DiscreteVariable(name='a', values=['F', 'M'])")
var.ordered = True
self.assertEqual(
repr(var),
"DiscreteVariable(name='a', values=['F', 'M'], ordered=True)")
var = DiscreteVariable.make("a", values="1234567")
self.assertEqual(
repr(var),
"DiscreteVariable(name='a', values=['1', '2', '3', '4', '5', '6', '7'])")
示例3: _create_corpus
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def _create_corpus(self):
corpus = None
names = ["name", "path", "content"]
data = []
category_data = []
text_categories = list(set(t.category for t in self._text_data))
values = list(set(text_categories))
category_var = DiscreteVariable.make("category", values=values)
for textdata in self._text_data:
data.append(
[textdata.name,
textdata.path,
textdata.content]
)
category_data.append(category_var.to_val(textdata.category))
if len(text_categories) > 1:
category_data = np.array(category_data)
else:
category_var = []
category_data = np.empty((len(data), 0))
domain = Domain(
[], category_var, [StringVariable.make(name) for name in names]
)
domain["name"].attributes["title"] = True
data = np.array(data, dtype=object)
if len(data):
corpus = Corpus(domain,
Y=category_data,
metas=data,
text_features=[domain.metas[2]])
return corpus
示例4: test_colors
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_colors(self):
var = DiscreteVariable.make("a", values=["F", "M"])
self.assertIsNone(var._colors)
self.assertEqual(var.colors.shape, (2, 3))
self.assertIs(var._colors, var.colors)
self.assertEqual(var.colors.shape, (2, 3))
self.assertFalse(var.colors.flags.writeable)
var.colors = np.arange(6).reshape((2, 3))
np.testing.assert_almost_equal(var.colors, [[0, 1, 2], [3, 4, 5]])
self.assertFalse(var.colors.flags.writeable)
with self.assertRaises(ValueError):
var.colors[0] = [42, 41, 40]
var.set_color(0, [42, 41, 40])
np.testing.assert_almost_equal(var.colors, [[42, 41, 40], [3, 4, 5]])
var = DiscreteVariable.make("x", values=["A", "B"])
var.attributes["colors"] = ['#0a0b0c', '#0d0e0f']
np.testing.assert_almost_equal(var.colors, [[10, 11, 12], [13, 14, 15]])
示例5: test_repr
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_repr(self):
var = DiscreteVariable.make("a", values=["F", "M"])
self.assertEqual(
repr(var),
"DiscreteVariable('a', values=['F', 'M'])")
var.base_value = 1
self.assertEqual(
repr(var),
"DiscreteVariable('a', values=['F', 'M'], base_value=1)")
var.ordered = True
self.assertEqual(
repr(var),
"DiscreteVariable('a', values=['F', 'M'], "
"ordered=True, base_value=1)")
var = DiscreteVariable.make("a", values="1234567")
self.assertEqual(
repr(var),
"DiscreteVariable('a', values=['1', '2', '3', '4', '5', ...])")
示例6: _guess_variable
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def _guess_variable(self, field_name, field_metadata, inspect_table):
type_code = field_metadata[0]
FLOATISH_TYPES = (700, 701, 1700) # real, float8, numeric
INT_TYPES = (20, 21, 23) # bigint, int, smallint
CHAR_TYPES = (25, 1042, 1043,) # text, char, varchar
BOOLEAN_TYPES = (16,) # bool
DATE_TYPES = (1082, 1114, 1184, ) # date, timestamp, timestamptz
# time, timestamp, timestamptz, timetz
TIME_TYPES = (1083, 1114, 1184, 1266,)
if type_code in FLOATISH_TYPES:
return ContinuousVariable.make(field_name)
if type_code in TIME_TYPES + DATE_TYPES:
tv = TimeVariable.make(field_name)
tv.have_date |= type_code in DATE_TYPES
tv.have_time |= type_code in TIME_TYPES
return tv
if type_code in INT_TYPES: # bigint, int, smallint
if inspect_table:
values = self.get_distinct_values(field_name, inspect_table)
if values:
return DiscreteVariable.make(field_name, values)
return ContinuousVariable.make(field_name)
if type_code in BOOLEAN_TYPES:
return DiscreteVariable.make(field_name, ['false', 'true'])
if type_code in CHAR_TYPES:
if inspect_table:
values = self.get_distinct_values(field_name, inspect_table)
# remove trailing spaces
values = [v.rstrip() for v in values]
if values:
return DiscreteVariable.make(field_name, values)
return StringVariable.make(field_name)
示例7: test_find_compatible_ordered
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_find_compatible_ordered(self):
abc = DiscreteVariable("abc", values="abc", ordered=True)
find_comp = DiscreteVariable._find_compatible
self.assertIsNone(find_comp("abc"))
self.assertIsNone(find_comp("abc", list("abc")))
self.assertIs(find_comp("abc", ordered=True), abc)
self.assertIs(find_comp("abc", ["a"], ordered=True), abc)
self.assertIs(find_comp("abc", ["a", "b"], ordered=True), abc)
self.assertIs(find_comp("abc", ["a", "b", "c"], ordered=True), abc)
self.assertIs(find_comp("abc", ["a", "b", "c", "d"], ordered=True), abc)
abd = DiscreteVariable.make(
"abc", values=["a", "d", "b"], ordered=True)
self.assertIsNot(abc, abd)
abc_un = DiscreteVariable.make("abc", values=["a", "b", "c"])
self.assertIsNot(abc_un, abc)
self.assertIs(
find_comp("abc", values=["a", "d", "b"], ordered=True), abd)
self.assertIs(find_comp("abc", values=["a", "b", "c"]), abc_un)
示例8: test_unpickle
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_unpickle(self):
d1 = DiscreteVariable("A", values=["two", "one"])
s = pickle.dumps(d1)
d2 = DiscreteVariable.make("A", values=["one", "two", "three"])
d2_values = tuple(d2.values)
d1c = pickle.loads(s)
# See: gh-3238
# The unpickle reconstruction picks an existing variable (d2), on which
# __setstate__ or __dict__.update is called
self.assertSequenceEqual(d2.values, d2_values)
self.assertSequenceEqual(d1c.values, d1.values)
s = pickle.dumps(d2)
DiscreteVariable._clear_all_caches() # [comment redacted]
d1 = DiscreteVariable("A", values=["one", "two"])
d2 = pickle.loads(s)
self.assertSequenceEqual(d2.values, ["two", "one", "three"])
示例9: test_val_from_str
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_val_from_str(self):
var = DiscreteVariable.make("a", values=["F", "M"])
self.assertTrue(math.isnan(var.to_val(None)))
self.assertEqual(var.to_val(1), 1)
示例10: test_make
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
def test_make(self):
var = DiscreteVariable.make("a", values=["F", "M"])
self.assertIsInstance(var, DiscreteVariable)
self.assertEqual(var.name, "a")
self.assertEqual(var.values, ["F", "M"])
示例11: Domain
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import make [as 别名]
item_summary_df[item_summary_df.total_perc <= 0.5].shape
# In[13]:
item_summary_df[item_summary_df.total_perc <= 0.5]
# # Construct Orange Table
# In[16]:
input_assoc_rules = grocery_df
domain_grocery = Domain([DiscreteVariable.make(name=item,values=['0', '1']) for item in input_assoc_rules.columns])
data_gro_1 = Orange.data.Table.from_numpy(domain=domain_grocery, X=input_assoc_rules.as_matrix(),Y= None)
# # Prune Dataset for frequently purchased items
# In[2]:
def prune_dataset(input_df, length_trans = 2, total_sales_perc = 0.5, start_item = None, end_item = None):
if 'total_items' in input_df.columns:
del(input_df['total_items'])
item_count = input_df.sum().sort_values(ascending = False).reset_index()
total_items = sum(input_df.sum().sort_values(ascending = False))
item_count.rename(columns={item_count.columns[0]:'item_name',item_count.columns[1]:'item_count'}, inplace=True)
if not start_item and not end_item: