def predict(d): if len(d) == 1: # This is to make sure the progress bar of SHAP display properly: # 1. The newline makes the progress bar string captured in pipe # 2. The ASCII control code moves cursor up twice for alignment print("\033[A" * 2) def input_fn(): return tf.data.Dataset.from_tensor_slices( dict(pd.DataFrame(d, columns=shap_dataset.columns))).batch(1000) if isinstance(estimator, tf.keras.Model): return np.array(estimator.predict(input_fn())) if plot_type == 'bar': predictions = [ p['logits'] if 'logits' in p else p['predictions'] for p in estimator.predict(input_fn) ] else: predictions = [ p['logits'][-1] if 'logits' in p else p['predictions'][-1] for p in estimator.predict(input_fn) ] return np.array(predictions)
def _input_fn(): dataset = input_fn("", datasource, feature_column_names, feature_metas, label_meta, is_pai=True, pai_table=pai_table) return dataset.batch(1).cache()
def _input_fn(): dataset = input_fn(select, datasource, feature_column_names, feature_metas, label_meta) return dataset.batch(1).cache()