Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Facets fro Colab
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
You can’t perform that action at this time.