本文整理匯總了Python中Orange.data.table.Table.from_numpy方法的典型用法代碼示例。如果您正苦於以下問題:Python Table.from_numpy方法的具體用法?Python Table.from_numpy怎麽用?Python Table.from_numpy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Orange.data.table.Table
的用法示例。
在下文中一共展示了Table.from_numpy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: apply_domain_edit
# 需要導入模塊: from Orange.data.table import Table [as 別名]
# 或者: from Orange.data.table.Table import from_numpy [as 別名]
def apply_domain_edit(self):
if self.data is None:
table = None
else:
domain, cols = self.domain_editor.get_domain(self.data.domain, self.data)
if not (domain.variables or domain.metas):
table = None
else:
X, y, m = cols
table = Table.from_numpy(domain, X, y, m, self.data.W)
table.name = self.data.name
table.ids = np.array(self.data.ids)
table.attributes = getattr(self.data, 'attributes', {})
self.Outputs.data.send(table)
self.apply_button.setEnabled(False)
示例2: apply_domain_edit
# 需要導入模塊: from Orange.data.table import Table [as 別名]
# 或者: from Orange.data.table.Table import from_numpy [as 別名]
def apply_domain_edit(self):
attributes = []
class_vars = []
metas = []
places = [attributes, class_vars, metas]
X, y, m = [], [], []
cols = [X, y, m] # Xcols, Ycols, Mcols
def is_missing(x):
return str(x) in ("nan", "")
for column, (name, tpe, place, vals, is_con), (orig_var, orig_plc) in \
zip(count(), self.editor_model.variables,
chain([(at, 0) for at in self.data.domain.attributes],
[(cl, 1) for cl in self.data.domain.class_vars],
[(mt, 2) for mt in self.data.domain.metas])):
if place == 3:
continue
if orig_plc == 2:
col_data = list(chain(*self.data[:, orig_var].metas))
else:
col_data = list(chain(*self.data[:, orig_var]))
if name == orig_var.name and tpe == type(orig_var):
var = orig_var
elif tpe == DiscreteVariable:
values = list(str(i) for i in set(col_data) if not is_missing(i))
var = tpe(name, values)
col_data = [np.nan if is_missing(x) else values.index(str(x))
for x in col_data]
elif tpe == StringVariable and type(orig_var) == DiscreteVariable:
var = tpe(name)
col_data = [orig_var.repr_val(x) if not np.isnan(x) else ""
for x in col_data]
else:
var = tpe(name)
places[place].append(var)
cols[place].append(col_data)
domain = Domain(attributes, class_vars, metas)
X = np.array(X).T if len(X) else np.empty((len(self.data), 0))
y = np.array(y).T if len(y) else None
dtpe = object if any(isinstance(m, StringVariable)
for m in domain.metas) else float
m = np.array(m, dtype=dtpe).T if len(m) else None
table = Table.from_numpy(domain, X, y, m, self.data.W)
self.send("Data", table)
self.apply_button.setEnabled(False)
示例3: insert_topics_into_corpus
# 需要導入模塊: from Orange.data.table import Table [as 別名]
# 或者: from Orange.data.table.Table import from_numpy [as 別名]
def insert_topics_into_corpus(self, corp_in):
"""
Insert topical representation into corpus.
:param corp_in: Corpus into whic we want to insert topical representations
:return: `Orange.data.table.Table`
"""
matrix = matutils.corpus2dense(self.corpus,
num_terms=self.num_topics).T
# Generate the new table.
attr = [ContinuousVariable(n) for n in self.topic_names]
domain = Domain(attr,
corp_in.domain.class_vars,
metas=corp_in.domain.metas)
return Table.from_numpy(domain,
matrix,
Y=corp_in._Y,
metas=corp_in.metas)
示例4: get_all_topics_table
# 需要導入模塊: from Orange.data.table import Table [as 別名]
# 或者: from Orange.data.table.Table import from_numpy [as 別名]
def get_all_topics_table(self):
""" Transform all topics from gensim model to table. """
all_words = self._topics_words(self.n_words)
all_weights = self._topics_weights(self.n_words)
sorted_words = sorted(all_words[0])
n_topics = len(all_words)
X = []
for words, weights in zip(all_words, all_weights):
weights = [we for wo, we in sorted(zip(words, weights))]
X.append(weights)
X = np.array(X).T
# take only first n_topics; e.g. when user requested 10, but gensim
# returns only 9 — when the rank is lower than num_topics requested
attrs = [ContinuousVariable(n)
for n in self.topic_names[:n_topics]]
t = Table.from_numpy(Domain(attrs, metas=[StringVariable('Word')]),
X=X, metas=np.array(sorted_words)[:, None])
t.name = 'All topics'
return t