Multitask Regression

I have CSV data with 2 target columns, each is continuous data that can be modeled as a regression problem. How would I structure a neural network in PyTorch with 2 output targets? What would the final layer look like? What would the loss function be? Thanks

Hi Max!

As I understand it you have it, you have input data – perhaps images,
perhaps measurements or statistics describing some object, etc. – and
for each sample, you have two target values.

You also say that your target values are continuous and can be modeled
as “regression.”

From this I understand that if your target is, say, 17.20, then a predicted
value of 17.21 would be quite good, 17.30 would be slightly less good,
while 112.00 would be quite bad. That is, closer is better, and almost
right is almost as good as exactly right.

For such a situation, the upstream part of your network would be whatever
is appropriate for processing your input data. For example, if your input
samples are images, your network might start out with a number of
convolutional layers. On the other that, if your input data is simply vectors
of “unstructured” numerical data, your network might begin immediately
with fully-connected layers.

Towards the end of your network, you would typically have just vectors of
numerical “features.” Your final layer should be fully-connected with two

final_layer = torch.nn.Linear (in_features = n_features, out_features = 2)

This will output two numerical predictions, one each for each of the two
values in your target. You would then typically use MSELoss as your loss


K. Frank

Thanks for the reply. That’s exactly what I ended up doing. PyTorch’s MSELoss also handles vectors, so it can average the loss of both features at the same time. Nice to know it was recommended.