title: Custom loss function for training optimisation using python and sklearn.neural_network.MLPRegressor
body: <p>I am using the scikit-learn neural network toolbox sklearn.neural_network.MLPRegressor to train a regressor with an output vector of 24 nodes. I am looking to use an error function similar to dynamic time warping (but slightly simplified) to quantify the prediction error. I have written the function that quantifies the error between two input vectors but am not sure how to link this in with sklearn's MLP Regressor. </p>
  
  <p>Q: Is it simply a case of defining a scoring object as shown here <a href="http://scikit-learn.org/stable/modules/model_evaluation.html#defining-your-scoring-strategy-from-metric-functions" rel="noreferrer">sklearn</a> and feeding it into the training part. </p>
  
  <p>Below is my defined loss function. </p>
  
  <pre><code>def MAAPE(actual,forecast,p,w):
  error_array = np.zeros([len(actual), len(forecast)])
  error_sum = 0
  
  for i in range(len(actual)):
      for j in range(len(forecast)):            
          if abs(i-j)&gt;w:
              error_array[i,j] = float('inf')
          else:
              error_array[i,j] = abs(actual[i] - forecast[j])/actual[i]        
      error_sum = error_sum + min(error_array[i,:])**p        
  MAAPE = (error_sum**(1/p))/len(actual)    
  return MAAPE 
  </code></pre>