Python code to support the Facets Overview visualization
Archived. The repository is read-only: no more fixes or releases will come.
pip install facets-overviewThe example code shown in the below explanation can also be found in this example Jupyter notebook.
Feature Statistics Protocol Buffer
The Overview visualization is powered by the feature statistics protocol buffer. The feature statistics protocol buffer messages store summary statistics for individual feature columns of a set of input data for an ML system (although it will be general enough to be used for summary statistics of any set of data).
The top-level proto is DatasetFeatureStatisticsList, which is a list of DatasetFeatureStatistics. Each DatasetFeatureStatistics represents the feature statistics for a single dataset. Each DatasetFeatureStatistics contains a list of FeatureNameStatistics, which contain the statistics for a single feature in a single dataset.
The feature statistics are different depending on the feature data type (numeric, string, or raw bytes). For numeric features, the statistics include metrics such as min, mean, median, max and standard deviation. For string feature, the statistics include metrics such as average length, number of unique values and mode.
Feature statistics includes an optional field for weighted statistics. If the dataset has an example weight feature, it can be used to calculate weighted statistics for every feature in addition to standard statistics. If a proto contains weighted fields, then the visualization will show the weighted statistics and the user will be able to toggle between unweighted and weighted versions of the charts per feature.
Feature statistics includes an optional field for custom statistics. If there are additional statistics for features in a dataset that a team wants to track and visualize they can be added to the custom stats field, which is a map of custom stat names to custom stat values (either numbers or strings). These custom stats will be displayed alongside the standard statistics.
Feature Statistics Generation
The feature statistics protocol buffer can be created for datasets by the python code provided in the facets_overview/facets-overview directory.
This code can be installed through pip install facets-overview. TensorFlow should also be installed but is not included as a
pip dependency, so as to allow a user to depend on either the tensorflow or tensorflow-gpu package as necessary.
Datasets can be analyzed either from a TfRecord files of tensorflow Example protocol buffers, or from pandas DataFrames.
As of version 1.1.0, the facets-overview package requires a version of protobuf at version 3.20.0 or later.
To create the proto from a pandas DataFrame, use the ProtoFromDataFrames method of the GenericFeatureStatisticsGenerator class.
To create the proto from a TfRecord file, use the method of the .
These generators have dependencies on the numpy and pandas python libraries.
Use of the FeatureStatisticsGenerator class also requires having tensorflow installed.
See those files for further documentation.