Last active
August 7, 2020 06:48
-
-
Save idiomer/e91f68ed8d22fff80798df723832ac9a to your computer and use it in GitHub Desktop.
用facets_overview查看dataset的概览
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
from IPython.core.display import display, HTML | |
# pip install facets_overview | |
from facets_overview.generic_feature_statistics_generator import GenericFeatureStatisticsGenerator | |
def display_overview(df_train, df_test=None): | |
gfsg = GenericFeatureStatisticsGenerator() | |
if df_test is not None: | |
proto = gfsg.ProtoFromDataFrames([{'name': 'train', 'table': df_train}, | |
{'name': 'test', 'table': df_test}]) | |
else: | |
proto = gfsg.ProtoFromDataFrames([{'name': 'train', 'table': df_train}]) | |
protostr = base64.b64encode(proto.SerializeToString()).decode("utf-8") | |
# Display the facets overview visualization for this data | |
HTML_TEMPLATE = """ | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.3.3/webcomponents-lite.js"></script> | |
<link rel="import" href="https://raw.githubusercontent.com/PAIR-code/facets/1.0.0/facets-dist/facets-jupyter.html" > | |
<facets-overview id="elem"></facets-overview> | |
<script> | |
document.querySelector("#elem").protoInput = "{protostr}"; | |
</script>""" | |
html = HTML_TEMPLATE.format(protostr=protostr) | |
display(HTML(html)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment