title: Local variable referenced before assignment in If statement when calculating mean absolute error
body: <p>I'm trying to add a weight to not penalize as much if prediction is greater than the actual in a forecast. Here's my code, however, I keep getting:</p>
  <blockquote>
  <p>UnboundLocalError: local variable 'under' referenced before assignment</p>
  </blockquote>
  <pre><code>import numpy as np
  
  def mae(y, y_hat):
      if np.where(y_hat &gt;= y):
          over = np.mean(0.5*(np.abs(y - y_hat)))
      elif np.where(y_hat &lt; y):
          under = np.mean(np.abs(y - y_hat))
      return (over + under) / 2
  </code></pre>
  <p>I've tried setting 'under' to global but that doesn't work either. This is probably an easy fix though I'm more of an R user.</p>