I would like to create a tabular model with multiple outputs. Currently, I can create a model with 2 regression outputs using the following code:
%%time
to = TabularPandas(
df_prep,
procs=[Categorify, Normalize],
cat_names=["cat1", 'cat2', 'cat3'],
cont_names=['cont1', 'cont2', "cont3"],
y_names=["y_reg", 'y_reg2'],
splits=splits,
y_block=RegressionBlock(n_out = 2),
)
After creating the model, I modify my losses and metrics using the following code:
import numpy as np
def board_loss(inp, true):
return F.mse_loss(inp[:, 0], true[:, 0])
def exit_loss(inp, true):
return F.mse_loss(inp[:, 1], true[:, 1])
def combine_loss(inp, true):
return board_loss(inp,true)+exit_loss(inp,true)
def board_error(inp, true):
return rmse(inp[:, 0].exp(), true[:, 0].exp())
def exit_error(inp, true):
return rmse(inp[:, 1].exp(), true[:, 1].exp())
def board_r2(inp, true):
return np.corrcoef(inp[:, 0].exp().cpu().numpy(), true[:, 0].exp().cpu().numpy())[0][1]
def exit_r2(inp, true):
return np.corrcoef(inp[:, 1].exp().cpu().numpy(), true[:, 1].exp().cpu().numpy())[0][1]
err_metrics = (board_error,exit_error, board_r2, exit_r2)
all_metrics = err_metrics+(board_loss,exit_loss)
I would now like to modify y2 to be a category while keeping y1 as a regression output. However, y_block in TabularPandas only allows for one type of output. Additionally, if I can achieve this, I would like to run y2 through a sigmoid and perhaps add additional layers for classification.