Created
April 23, 2018 12:23
-
-
Save creotiv/fd46477151b1d4dd2b390343bcc65290 to your computer and use it in GitHub Desktop.
Facets fro Colab
This file contains hidden or 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 shutil | |
| if os.path.exists('./facets'): | |
| shutil.rmtree("./facets") | |
| !git clone https://github.com/PAIR-code/facets | |
| !jupyter nbextension install facets/facets-dist/ | |
| import sys | |
| import os | |
| sys.path.append(os.path.abspath('./facets/facets_overview/python/')) | |
| from generic_feature_statistics_generator import GenericFeatureStatisticsGenerator | |
| import base64 | |
| class FacetsOverview(object): | |
| def __init__(self, df_train, df_test): | |
| gfsg = GenericFeatureStatisticsGenerator() | |
| self._proto = gfsg.ProtoFromDataFrames([{'name': 'train', 'table': df_train}, | |
| {'name': 'test', 'table': df_test}]) | |
| def _repr_html_(self): | |
| protostr = base64.b64encode(self._proto.SerializeToString()).decode("utf-8") | |
| HTML_TEMPLATE = """<link rel="import" href="/nbextensions/facets-dist/facets-jupyter.html" > | |
| <facets-overview id="elem"></facets-overview> | |
| <script> | |
| document.querySelector("#elem").protoInput = "{protostr}"; | |
| </script>""" | |
| html = HTML_TEMPLATE.format(protostr=protostr) | |
| return html | |
| class FacetsDive(object): | |
| def __init__(self, data): | |
| self._data = data | |
| self.height = 1000 | |
| def _repr_html_(self): | |
| HTML_TEMPLATE = """<link rel="import" href="/nbextensions/facets-dist/facets-jupyter.html" > | |
| <facets-dive id="elem" height="{height}"></facets-dive> | |
| <script> | |
| document.querySelector("#elem").data = {data}; | |
| </script>""" | |
| html = HTML_TEMPLATE.format(data=self._data.to_json(orient='records'), height=self.height) | |
| return html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment