question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModelValidator does not work with regression model

See original GitHub issue

I have created my own custom pipeline, using the taxi pipeline as basis to branch out from. So this pipeline contains everything from CsvExampleGen to the Pusher. I am trying to build a DNNLinearCombinedRegressor model. This all works fine until the ModelValidator component. It tries to compare the accuracy of the blessed model with the current model, however since we are running a regressor model, there is no accuracy metric and so the component fails on that point and with that the rest of the pipeline.

This is the error message that pops up here:

[2019-05-22 10:01:52,613] {logging_mixin.py:95} INFO - [2019-05-22 10:01:52,613] {executor.py:51} INFO - TF Logging: current metric: ((), {u’label/mean’: {‘doubleValue’: 5.047114372253418}, u’average_loss’: {‘doubleValue’: 335.8445129394531}, u’post_export_metrics/example_count’: {‘doubleValue’: 43299.0}, u’prediction/mean’: {‘doubleValue’: 5.458231449127197}}) [2019-05-22 10:01:52,613] {models.py:1788} ERROR - ‘accuracy’ Traceback (most recent call last): File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/airflow/models.py”, line 1657, in _run_raw_task result = task_copy.execute(context=context) File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/airflow/operators/python_operator.py”, line 103, in execute return_value = self.execute_callable() File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/airflow/operators/python_operator.py”, line 108, in execute_callable return self.python_callable(*self.op_args, **self.op_kwargs) File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/tfx/orchestration/airflow/airflow_adapter.py”, line 150, in python_exec executor.Do(self._input_dict, self._output_dict, self._exec_properties) File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/tfx/components/model_validator/executor.py”, line 164, in Do blessed_model_dir=blessed_model_dir) File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/tfx/components/model_validator/executor.py”, line 108, in _generate_blessing_result blessed_model_eval_result)): File “/home/username/taxi_pipeline/local/lib/python2.7/site-packages/tfx/components/model_validator/executor.py”, line 55, in _compare_eval_result if (current_metric[1][‘accuracy’][‘doubleValue’] < KeyError: ‘accuracy’

The code where this fails is in tfx/components/model_validator/executor.py in the _compare_eval_result definition:

  # TODO(jyzhao): customized validation support.
  def _compare_eval_result(self, current_model_eval_result,
                           blessed_model_eval_result):
    """Compare accuracy of all metrics and return true if current is better or equal."""
    for current_metric, blessed_metric in zip(
        current_model_eval_result.slicing_metrics,
        blessed_model_eval_result.slicing_metrics):
      # slicing_metric is a tuple, index 0 is slice, index 1 is its value.
      tf.logging.info("TF Logging: current metric: " + str(current_metric))
      tf.logging.info("TF Logging: current metric: " + str(blessed_metric))
      if current_metric[0] != blessed_metric[0]:
        raise RuntimeError('EvalResult not match {} vs {}.'.format(
            current_metric[0], blessed_metric[0]))
      if (current_metric[1]['accuracy']['doubleValue'] <
          blessed_metric[1]['accuracy']['doubleValue']):
        tf.logging.info(
            'Current model accuracy is worse than blessed model: {}'.format(
                current_metric[0]))
        return False
    return True

There seems to be no switch to check for accuracy when using a classification model and something else, like average_loss, when using a regressor model. I did a workaround by just replacing accuracy with average_loss, but this is hardcoded in the component code, so not very desirable.

Is there something that I am missing here, and is there actually a switch or a place to add custom configuration for the model validator? Or is this something that is indeed not implemented?

I am running in Python 2.7 and TFX 0.13.0.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Efaqcommented, May 22, 2019

Also experiencing that. I wonder if there is some possible configuration to be passed to the validator. There is a (not so well) documented input called “eval_spec” in a documentation page but this doesn’t seem to be present in the actual code.

documentation page: https://www.tensorflow.org/tfx/guide/modelval

0reactions
Efaqcommented, May 24, 2019

@zhitaoli Ok, thank you for these updates!

Read more comments on GitHub >

github_iconTop Results From Across the Web

R Tutorial: Model Validation, Model Fit, and Prediction
The linear model, at first glance, looks like it does not fit well, ... In R you can find the AIC value using...
Read more >
Five Regression Analysis Tips to Avoid Common Problems
Regression analysis is powerful but presents various pitfalls. Learn five tips that help you avoid common problems and make the modeling process easier....
Read more >
Bot's job? Quants question AI's model validation powers
“Model hacking is not an easy job, and needs creativity,” argues Agus ... In the US, banks putting AI to work in model...
Read more >
Regression Analysis: when the Data Doesn't Conform
Open ArcGIS Insights Desktop.You can also use your Insights in ArcGIS Online or Insights in ArcGIS Enterprise. If necessary, accept the ...
Read more >
Common pitfalls in statistical analysis: Logistic regression - PMC
Go to: HOW DOES MULTIPLE LOGISTIC REGRESSION WORK? The statistical program first calculates the baseline odds of having the outcome versus not having...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found