code: def calc_cost(y, yhat, cost_matrix):
      
      return np.mean(cost_matrix[list(y), list(yhat)])
docs: Calculate the cost with given cost matrix
  
      y : ground truth
  
      yhat : estimation
  
      cost_matrix : array-like, shape=(n_classes, n_classes)
          The ith row, jth column represents the cost of the ground truth being
          ith class and prediction as jth class.