title: ValueError: Unknown metric function when using custom metric in Keras
body: <p>Keras 2.x killed off a bunch of useful metrics that I need to use, so I copied the functions from the old metrics.py file into my code, then included them as follows.</p>
  
  <pre><code>def precision(y_true, y_pred): #taken from old keras source code
       true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
       predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
       precision = true_positives / (predicted_positives + K.epsilon())
       return precision
  def recall(y_true, y_pred): #taken from old keras source code
       true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
       possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
       recall = true_positives / (possible_positives + K.epsilon())
       return recall
  </code></pre>
  
  <p>...</p>
  
  <pre><code>model.compile(loss='categorical_crossentropy', optimizer='adam', 
  metrics=['accuracy', precision, recall])
  </code></pre>
  
  <p>and this results in </p>
  
  <pre><code>ValueError: Unknown metric function:precision
  </code></pre>
  
  <p>What am I doing wrong? I can't see anything I'm doing wrong according to Keras documentation.</p>
  
  <p>edit:</p>
  
  <p>Here is the full Traceback:</p>
  
  <pre><code> Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "/Library/Python/2.7/site-packages/keras/models.py", line 274, in 
  load_model
      sample_weight_mode=sample_weight_mode)
    File "/Library/Python/2.7/site-packages/keras/models.py", line 824, in 
  compile
       **kwargs)
    File "/Library/Python/2.7/site-packages/keras/engine/training.py", line 
  934, in compile
       handle_metrics(output_metrics)
     File "/Library/Python/2.7/site-packages/keras/engine/training.py", line 
  901, in handle_metrics
      metric_fn = metrics_module.get(metric)
    File "/Library/Python/2.7/site-packages/keras/metrics.py", line 75, in get
       return deserialize(str(identifier))
    File "/Library/Python/2.7/site-packages/keras/metrics.py", line 67, in 
  deserialize
      printable_module_name='metric function')
    File "/Library/Python/2.7/site-packages/keras/utils/generic_utils.py", 
  line 164, in deserialize_keras_object
      ':' + function_name)
  ValueError: Unknown metric function:precision
  &lt;FATAL&gt;                         : Failed to load Keras model from file: 
  model.h5
  ***&gt; abort program execution
  Traceback (most recent call last):
    File "classification.py", line 84, in &lt;module&gt;
      'H:!V:FilenameModel=model.h5:NumEpochs=20:BatchSize=32') 
  #:VarTransform=D,G
  TypeError: none of the 3 overloaded methods succeeded. Full details:
    TMVA::MethodBase* TMVA::Factory::BookMethod(TMVA::DataLoader* loader, 
  TString theMethodName, TString methodTitle, TString theOption = "") =&gt;
      could not convert argument 2
    TMVA::MethodBase* TMVA::Factory::BookMethod(TMVA::DataLoader* loader, 
  TMVA::Types::EMVA theMethod, TString methodTitle, TString theOption = "") =&gt;
      FATAL error (C++ exception of type runtime_error)
    TMVA::MethodBase* TMVA::Factory::BookMethod(TMVA::DataLoader*, 
  TMVA::Types::EMVA, TString, TString, TMVA::Types::EMVA, TString) =&gt;
      takes at least 6 arguments (4 given)
  </code></pre>