@@ -157,6 +157,18 @@ def mlalpha(line, cell=None):
157
157
package_parser .add_argument ('--name' , help = 'The name of the package.' , required = True )
158
158
package_parser .add_argument ('--output' , help = 'the output dir of the package.' , required = True )
159
159
package_parser .set_defaults (func = _package )
160
+
161
+ package_parser = parser .subcommand ('feature-slice-view' ,'View results of a ' +
162
+ 'FeatureSlicingPipeline, some eval metrics grouped by ' +
163
+ 'specified feature column values' )
164
+ package_parser .add_argument ('--file' , help = 'The results file from FeatureSlicingPipeline' ,
165
+ required = True )
166
+ package_parser .add_argument ('--feature' ,
167
+ help = 'Which feature to view. The feature must be specified ' +
168
+ 'in the FeatureSlicingPipeline. If not specified, all ' +
169
+ 'features will be listed.' )
170
+ package_parser .set_defaults (func = _feature_slice_view )
171
+
160
172
namespace = datalab .utils .commands .notebook_environment ()
161
173
return datalab .utils .commands .handle_magic_line (line , cell , parser , namespace = namespace )
162
174
@@ -971,3 +983,25 @@ def _package(args, cell):
971
983
google .cloud .ml .util ._file .copy_file (package_path , dest )
972
984
os .remove (package_path )
973
985
print 'Package created at %s.' % dest
986
+
987
+
988
+ def _feature_slice_view (args , cell ):
989
+ HTML_TEMPLATE = """<link rel="import" href="/nbextensions/gcpdatalab/extern/lantern-browser.html" >
990
+ <lantern-browser id="%s"></lantern-browser>
991
+ <script>
992
+ var browser = document.querySelector('#%s');
993
+ browser.metrics = %s;
994
+ browser.data = %s;
995
+ browser.sourceType = 'colab';
996
+ browser.weightedExamplesColumn = 'totalWeightedExamples';
997
+ browser.calibrationPlotUriFn = function(s) { return '/' + s; }
998
+ </script>"""
999
+ with open (args ['file' ]) as f :
1000
+ data = map (json .loads , f )
1001
+ if args ['feature' ]:
1002
+ data = [e for e in data if e ['feature' ].split (':' )[0 ] == args ['feature' ]]
1003
+ metrics_str = str (map (str , data [0 ]['metricValues' ].keys ()))
1004
+ data_str = str ([{str (k ): json .dumps (v ) for k ,v in elem .iteritems ()} for elem in data ])
1005
+ html_id = 'l' + datalab .utils .commands .Html .next_id ()
1006
+ html = HTML_TEMPLATE % (html_id , html_id , metrics_str , data_str )
1007
+ return IPython .core .display .HTML (html )
0 commit comments