本文整理汇总了Python中sklearn.preprocessing.LabelBinarizer.repeat方法的典型用法代码示例。如果您正苦于以下问题:Python LabelBinarizer.repeat方法的具体用法?Python LabelBinarizer.repeat怎么用?Python LabelBinarizer.repeat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.preprocessing.LabelBinarizer
的用法示例。
在下文中一共展示了LabelBinarizer.repeat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compute_A
# 需要导入模块: from sklearn.preprocessing import LabelBinarizer [as 别名]
# 或者: from sklearn.preprocessing.LabelBinarizer import repeat [as 别名]
def _compute_A(X, pi, classes):
""" Compute the A matrix in the variance estimation technique.
Parameters
----------
X : array
The feature matrix.
pi : array
The probability matrix predicted by the classifier.
classes : array
The list of class names ordered lexicographically.
Returns
-------
A : array
The A matrix as part of the variance calcucation.
"""
n_classes = len(classes)
n_features = X.shape[1]
n_samples = X.shape[0]
width = n_classes * n_features
one_in_k = LabelBinarizer(pos_label=1, neg_label=0).fit_transform(classes)
I_same = one_in_k.repeat(n_features, axis=0)
I_same = np.tile(I_same, n_samples)
I_diff = 1 - I_same
A = np.tile(pi.flatten(), (width, 1))
B = 1 - A
C = -A
D = pi.transpose().repeat(n_features, axis=0).repeat(n_classes, axis=1)
E = X.transpose().repeat(n_classes, axis=1)
E = np.tile(E, (n_classes, 1))
G = A * B * I_same + C * D * I_diff
G = E * G
outer = np.dot(G, G.transpose())
return outer