Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cluster_stats_with_no_names(self):
# This would be the default.
X = np.ones((1000, 3))
ids = np.random.choice(20, 1000)
X[ids, 0] = 0
cluster_data = visuals._format_cluster_statistics(ids, X, [])
assert len(cluster_data["below"]) >= 1
assert cluster_data["below"][0]["feature"] == "f_0"
assert cluster_data["below"][0]["mean"] == 0
def test_cluster_stats_above(self):
X = np.ones((1000, 3))
ids = np.random.choice(20, 1000)
X[ids, 0] = 10
cluster_data = visuals._format_cluster_statistics(ids, X, ["a", "b", "c"])
assert len(cluster_data["above"]) >= 1
assert cluster_data["above"][0]["feature"] == "a"
assert cluster_data["above"][0]["mean"] == 10
def test_cluster_stats_below(self):
X = np.ones((1000, 3))
ids = np.random.choice(20, 1000)
X[ids, 0] = 0
cluster_data = visuals._format_cluster_statistics(ids, X, ["a", "b", "c"])
assert len(cluster_data["below"]) >= 1
assert cluster_data["below"][0]["feature"] == "a"
assert cluster_data["below"][0]["mean"] == 0
def test_cluster_stats(self):
X = np.random.random((1000, 3))
ids = np.random.choice(20, 1000)
cluster_data = visuals._format_cluster_statistics(ids, X, ["a", "b", "c"])
assert isinstance(cluster_data, dict)
assert cluster_data["size"] == len(ids)
def _hover_format(member_ids, custom_tooltips, X, X_names, lens, lens_names):
cluster_data = _format_cluster_statistics(member_ids, X, X_names)
tooltip = ""
custom_tooltips = (
custom_tooltips[member_ids] if custom_tooltips is not None else member_ids
)
val_size = cluster_data["size"]
tooltip += "{val_size}".format(**locals())
return tooltip