本文整理汇总了Python中sklearn.utils.fixes.bincount方法的典型用法代码示例。如果您正苦于以下问题:Python fixes.bincount方法的具体用法?Python fixes.bincount怎么用?Python fixes.bincount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.utils.fixes
的用法示例。
在下文中一共展示了fixes.bincount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _iter_indices
# 需要导入模块: from sklearn.utils import fixes [as 别名]
# 或者: from sklearn.utils.fixes import bincount [as 别名]
def _iter_indices(self):
rng = np.random.RandomState(self.random_state)
cls_count = bincount(self.y_indices)
for n in range(self.n_iter):
train = []
test = []
for i, cls in enumerate(self.classes):
sample_size = int(cls_count[i]*(1-self.test_size))
randint = rng.randint(cls_count[i], size=sample_size)
aidx = np.where((self.y == cls))[0]
iidx = aidx[randint]
oidx = aidx[list(set(range(cls_count[i])).difference(set(randint)))]
train.extend(iidx)
test.extend(oidx)
train = rng.permutation(train)
test = rng.permutation(test)
yield train, test
示例2: _document_frequency
# 需要导入模块: from sklearn.utils import fixes [as 别名]
# 或者: from sklearn.utils.fixes import bincount [as 别名]
def _document_frequency(X):
"""Count the number of non-zero values for each feature in sparse X."""
if sp.isspmatrix_csr(X):
# return np.sum(X,axis=0)
return bincount(X.indices, minlength=X.shape[1])
else:
return np.diff(sp.csc_matrix(X, copy=False).indptr)