本文整理汇总了Python中Orange.data.DiscreteVariable.sparse方法的典型用法代码示例。如果您正苦于以下问题:Python DiscreteVariable.sparse方法的具体用法?Python DiscreteVariable.sparse怎么用?Python DiscreteVariable.sparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.data.DiscreteVariable
的用法示例。
在下文中一共展示了DiscreteVariable.sparse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extend_attributes
# 需要导入模块: from Orange.data import DiscreteVariable [as 别名]
# 或者: from Orange.data.DiscreteVariable import sparse [as 别名]
def extend_attributes(self, X, feature_names, feature_values=None,
compute_values=None, var_attrs=None, sparse=False):
"""
Append features to corpus. If `feature_values` argument is present,
features will be Discrete else Continuous.
Args:
X (numpy.ndarray or scipy.sparse.csr_matrix): Features values to append
feature_names (list): List of string containing feature names
feature_values (list): A list of possible values for Discrete features.
compute_values (list): Compute values for corresponding features.
var_attrs (dict): Additional attributes appended to variable.attributes.
sparse (bool): Whether the features should be marked as sparse.
"""
if self.X.size == 0:
self.X = X
elif sp.issparse(self.X) or sp.issparse(X):
self.X = sp.hstack((self.X, X)).tocsr()
else:
self.X = np.hstack((self.X, X))
if compute_values is None:
compute_values = [None] * X.shape[1]
if feature_values is None:
feature_values = [None] * X.shape[1]
new_attr = self.domain.attributes
for f, values, cv in zip(feature_names, feature_values, compute_values):
if values is not None:
var = DiscreteVariable(f, values=values, compute_value=cv)
else:
var = ContinuousVariable(f, compute_value=cv)
var.sparse = sparse # don't pass this to constructor so this works with Orange < 3.8.0
if cv is not None: # set original variable for cv
cv.variable = var
if isinstance(var_attrs, dict):
var.attributes.update(var_attrs)
new_attr += (var, )
new_domain = Domain(
attributes=new_attr,
class_vars=self.domain.class_vars,
metas=self.domain.metas
)
self.domain = new_domain