def testTwoDimensionalDistribution(self):
df = pd.DataFrame({"X": [1, 1, 1, 2, 2, 3, 4],
"Y": [1, 2, 0, 1, 1, 1, 1],
"Z": [1, 0, 0, 0, 0, 0, 0]})
weights = np.array([1, 1, 1, 1, 1, 1, 1])
metric = metrics.Distribution("X", ["Y", "Z"])
output = metric(df, weights)
correct = pd.DataFrame(
np.array([1 / 14., 1 / 14., 1 / 14., 11 / 14.]),
columns=[""],
index=pd.MultiIndex(levels=[[0, 1, 2], [0, 1]],
labels=[[1, 2, 0, 1], [1, 0, 0, 0]],
names=["Y", "Z"]))
self.assertTrue(output.equals(correct))
评论列表
文章目录