本文整理匯總了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)