def generate_facets(config, df): proto = GenericFeatureStatisticsGenerator().ProtoFromDataFrames([{ 'name': 'facets-iss', 'table': df }]) protostr = base64.b64encode(proto.SerializeToString()).decode("utf-8") 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) return html
def overview(tables: typing.Union[pandas.DataFrame, typing.Mapping[str, pandas.DataFrame]]) -> HTML: # Element ID MUST be unique elem_id = _generate_element_id() if isinstance(tables, pandas.DataFrame): tables = {"default": tables} table_list = [] for name, table in tables.items(): # Convert PandasExtensionDType column to object column because facets currently doesn't support it. view = table.copy() for k, v in view.dtypes.iteritems(): if not isinstance(v, numpy.dtype): view[k] = view[k].astype(object) table_list.append({'name': name, 'table': view}) proto = GenericFeatureStatisticsGenerator().ProtoFromDataFrames(table_list) proto_str = base64.b64encode(proto.SerializeToString()).decode("utf-8") return HTML(FACETS_OVERVIEW_TEMPLATE.format(elem_id=elem_id, proto_str=proto_str))
def generate_html(self, datasets: List[Dict[Text, pd.DataFrame]]) -> str: """Generates html for facet. Args: datasets: List of dicts of dataframes to be visualized as stats. Returns: HTML template with proto string embedded. """ proto = GenericFeatureStatisticsGenerator().ProtoFromDataFrames( datasets) protostr = base64.b64encode(proto.SerializeToString()).decode("utf-8") template = os.path.join( os.path.abspath(os.path.dirname(__file__)), "stats.html", ) html_template = fileio.read_file_contents_as_string(template) html_ = html_template.replace("protostr", protostr) return html_
my_pipeline = make_pipeline(Imputer(), RandomForestRegressor()) my_pipeline.fit(train_X, train_y) predictions = my_pipeline.predict(test_X) print("Error:" + str(mean_absolute_error(predictions, test_y))) #%% train = pd.read_csv('ML/train.csv') test = pd.read_csv('ML/test.csv') from facets_overview.generic_feature_statistics_generator import GenericFeatureStatisticsGenerator #%% proto = GenericFeatureStatisticsGenerator().ProtoFromDataFrames([{ 'name': 'test', 'table': test }]) #%% from IPython.core.display import display, HTML import base64 protostr = base64.b64encode(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) display(HTML(html)) #%%