Spaces:
Sleeping
Sleeping
import pandas as pd | |
import numpy as np | |
from renumics import spotlight | |
from renumics.spotlight.analysis.typing import DataIssue | |
if __name__ == "__main__": | |
df = pd.read_json("df.json") | |
# df[ | |
# "GitHub" | |
# ] = '<a href="https://github.com/Renumics/spotlight" target="_blank">⭐ Check Out Spotlight on GitHub</a>' | |
issues = pd.read_json("issues.json") | |
spotlight_issues = [] | |
for _, issue in issues.sort_values("metric").iterrows(): | |
issue_metric = issue["metric"] | |
issue_title = ( | |
f"Metric: {issue_metric:.2f} | Cause: {issue['predicates'][0]['column']}" | |
) | |
predicate_strings = [ | |
f"{x['minimum']:.1f} < {x['column']} < {x['maximum']:.1f}" | |
for x in issue["predicates"] | |
if ("minimum" in x and "maximum" in x) | |
] | |
issue_explanation = "Feature Importances:\n" + issue["explanation"] | |
if len(predicate_strings) > 0: | |
issue_explanation = ( | |
issue_explanation + "\n\nFeature Ranges:\n" + "; ".join(predicate_strings) | |
) | |
data_issue = DataIssue( | |
severity="high" if issue_metric < 0.5 else "medium", | |
title=issue_title, | |
description=issue_explanation, | |
rows=issue["rows"], | |
columns=[x["column"] for x in issue["predicates"]], | |
) | |
spotlight_issues.append(data_issue) | |
while True: | |
dtypes = { | |
"sg_projection": spotlight.Embedding, | |
} | |
view = spotlight.show( | |
df, | |
dtype=dtypes, | |
port=7860, | |
host="0.0.0.0", | |
allow_filebrowsing=False, | |
issues=spotlight_issues, | |
layout="spotlight-layout.json", | |
) | |
view.close() | |