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.

F1 score support for objective

See original GitHub issue

Today objective = “val_f1” returns an error Failed to train : <class ‘ValueError’> : Could not infer optimization direction (“min” or “max”) for unknown metric “val_f1”. Please specify the objective asa kerastuner.Objective, for example kerastuner.Objective("val_f1", direction="min").

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
natanrajchcommented, Aug 27, 2021

Had this same issue while running latest version of autokeras in Colab environment. While using this f1 custom objective, the object’s .fit() worked OK, but failed to .predict() or .export_model() after training. Keras was demanding the custom objects, and they weren’t being passed on.

Fixed it by changing the StructuredDataClassifierTuner function like this, I leave it here for reference of whomever might find this useful:

my_custom_objects={'f1_score_cust': f1_score_custom}
my_custom_objects.update(ak.CUSTOM_OBJECTS)

from keras_tuner.engine import hypermodel as hm_module
def get_best_model_custom(self):
  with hm_module.maybe_distribute(self.distribution_strategy):
    model = tf.keras.models.load_model(self.best_model_path, custom_objects=my_custom_objects)
  return model
autok.tuner.get_best_model = get_best_model_custom.__get__(autok.tuner,ak.tuners.task_specific.StructuredDataClassifierTuner)

Here f1_score_custom is a custom function, ak is autokeras, and autok is an StructuredDataClassifier instance.

1reaction
haifeng-jincommented, Jul 28, 2020

I am working on it. It seems it is a bug that it always use val_loss as objective.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Look at Precision, Recall, and F1-Score | by Teemu Kanstrén
F1-score equals precision and recall if the two input metrics (P&R) are equal. The Difference column in the table shows the difference between...
Read more >
Accuracy, Precision, Recall & F1 Score - Exsilio Blog
F1 score - F1 Score is the weighted average of Precision and Recall. Therefore, this score takes both false positives and false negatives...
Read more >
What Is a Good F1 Score? — Inside GetYourGuide
F1 := 2 / (1/precision + 1/recall ). It reaches its optimum 1 only if precision and recall are both at 100%. And...
Read more >
Accuracy, Precision, Recall & F1-Score - Python Examples
Model F1 score represents the model score as a function of precision and recall score. F-score is a machine learning model performance metric ......
Read more >
What is the F1-score? - Educative.io
The F1-score combines the precision and recall of a classifier into a single metric by taking their harmonic mean. It is primarily used...
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