As the other answers pointed out, this may not be something you want to do. But in cases where your 2 regression targets are closely related (say in the case of latitude and longitude) it may make sense.
One of the things I really love about neural networks is that they are very flexible, and allow you to define one model that does multiple things. For example, you can have one model that predicts both a classification target and a regression target.
Even if that's not what you should do on this dataset, I still think it's pretty cool, so I'm gonna share some code for a keras neural network in python that does classification and regression at the same time!
First, lets load some data. In this case, we're gonna predict sex (classification) and age (regression) from some census data:
import pandas as pd
adult = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data')
adult.columns = ['age', 'workclass', 'fnlwgt', 'edu', 'edu_num', 'marital_status',
'occupation', 'relationship', 'race', 'sex', 'capital_gain', 'capital_loss',
'hours_per_week', 'native_country', 'income']
adult["sex"] = adult["sex"].astype('category').cat.codes
adult["workclass"] = adult["workclass"].astype('category').cat.codes
adult["marital_status"] = adult["marital_status"].astype('category').cat.codes
adult["race"] = adult["race"].astype('category').cat.codes
adult["occupation"] = adult["occupation"].astype('category').cat.codes
adult["native_country"] = adult["native_country"].astype('category').cat.codes
target_bin = adult[['sex']].values.astype('float32')
target_num = adult[['age']].values.astype('float32')
X = adult[['workclass', 'edu_num', 'marital_status', 'occupation', 'race', 'capital_gain',
'capital_loss', 'hours_per_week', 'native_country']].values.astype('float32')
X
is our predictors, target_bin
is the classification target, and target_num
is the regression target.
Now lets define a keras model with one input (X
) and 2 outputs (target_bin
and target_num
):
from keras.layers import Input, Dense, BatchNormalization
from keras.models import Model
from keras.optimizers import Adam
from keras.utils.vis_utils import plot_model
input = Input(shape=(X.shape1,), name='Input')
hidden = Dense(64, name='Shared-Hidden-Layer', activation='relu')(input)
hidden = BatchNormalization()(hidden)
out_bin = Dense(1, name='Output-Bin', activation='sigmoid')(hidden)
out_num = Dense(1, name='Output-Num', activation='linear')(hidden)
model = Model(input, [out_bin, out_num])
model.compile(optimizer=Adam(0.10), loss=['binary_crossentropy', 'mean_squared_error'])
model.summary()
plot_model(model, to_file='model.png')

Now we can fit this model to our data:
model.fit(X, [target_bin, target_num], validation_split=.20, epochs=100, batch_size=2048)
model.predict(X)
We use a 20% validation set, where the model gets a logloss of 0.5649
and a mean squared error of 117.0967
, which corresponds to an RMSE of 10.8
. A logloss of <.69 means the model learned something useful for classification, and the RMSE of 10.8
is pretty good given that the mean of the numeric target is 38.6.
If you look at this model's predictions, you see it predicts 2 arrays. The first is the probability that the person is female, and the second is the person's predicted age.
You'll notice that I setup this network to use a shared hidden layer from the inputs to predict the outputs. You could also setup the network to e.g. use the sex prediction as a predictor for age, or other creative ways to relate the 2 variables.
So you can make one model to do both classification and regression!