Message Boards Message Boards

3
|
9047 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Create a custom loss function with NetTrain?

Suppose I want to Classify some data but, for my own reasons, want a custom NeuralNet architecture rather than whatever Classify develops algorithmically. AND I also want a custom loss function. In my example, I want an asymmetric loss such that predicting True when the real answer is False is a worse problem than predicting False when the real answer is True. In Classify, there is an option UtilityFunction that works splendidly in such cases. And I think the following set of layers would work to emulate a utility function in the Neural Network arena if I wanted losses in one direction to count double losses in the other direction. There may well be much better functions, I only show the code below to indicate that something may be possible.

 lossnet = 
  NetChain[{ThreadingLayer[#1 - #2 &], 
    ElementwiseLayer[2*Ramp[#] + 1*Ramp[-#] &]}]

But I can't quite figure out how to put it all together. The particular toy problem I want to solve is to come up with a model that works on the Titanic dataset and predicts survival but, for my own reasons, counts a prediction of survival when the person dies as worse that prediction of death when the person survives.

Three other notes:

1) My question is related to a question asked here but no one ever answered it.

2) The documentation for the neural net framework really needs to be improved, particularly if it escapes the "Experimental" framework. Right now, it is missing the conceptual framework that would make its use easy. It also seems to have a very heavy focus on image processing rather than on data analysis in other contexts, such as social science. Moreover, some of the documentation is underinclusive. By way of example, there are options to NetGraph that are listed in the "Details" section yet there is no indication at the top of the ref page that any options exist. As a result it is extremely challenging to figure out how to deal with data such as the Titanic which is a list of Associations and for which various columns of the data need special encoding.

3) One motivation for using a custom utility function is that when one output class is scarce, the neural net frequently develops a predictor that always predicts the most common class: predicting that everyone on the Titanic will live. In the Classify context, there are ways of dealing with this: use of ClassPriors, UtilityFunctions. I'd like the same capabilities when using the Neural Network framework.

POSTED BY: Seth Chandler
3 Replies
POSTED BY: Seth Chandler

Using a custom loss is documented in the 3rd example of the LossFunction documentation:

http://reference.wolfram.com/language/ref/LossFunction.html.

That whole page is useful for understanding how to control losses.

I'm still very much hoping for a response here. BUT ... I did make a lot of progress on the general issues involved in using NeuralNetworks on data with nominal values. I've shared my progress on a post here.

POSTED BY: Seth Chandler
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract