title: gradient for mean absolute error (mae) and mean squared error (mse) loss functions
body: <p>I am trying to implement linear regression using numpy. For that, I need to implement derivatives for loss functions mae and mse. These are my versions but they are incorrect (failing tests that are unfortunately not disclosed).
  Can someone help me implement correct gradient methods for mae and mse. Please note here that the dimension of the target is &gt; 1 and that's probably not handled in my version.</p>
  <pre><code>def mse_derivative(X, Y, w):
      &quot;&quot;&quot;
      X : numpy array of shape (`n_observations`, `n_features`)
      Y : numpy array of shape (`n_observations`, `target_dimentionality`) or (`n_observations`,)
      w : numpy array of shape (`n_features`, `target_dimentionality`) or (`n_features`,)
      
      Return: NumPy array of the same shape as `w`
  
      &quot;&quot;&quot;
  
      return (X.T.dot(X.dot(w) - Y)) * 2 / Y.shape[0]
  
  def mae_derivative(X, Y, w):
      &quot;&quot;&quot;
      X : numpy array of shape (`n_observations`, `n_features`)
      Y : numpy array of shape (`n_observations`, `target_dimentionality`) or (`n_observations`,)
      w : numpy array of shape (`n_features`, `target_dimentionality`) or (`n_features`,)
      
      Return: NumPy array of the same shape as `w`
      &quot;&quot;&quot;
  
  
     
      return np.array(list(map(lambda diff : 0 if diff == 0 else 1 if diff &gt; 0 else -1, list(X.dot(w) - Y))))
  </code></pre>