Skip to content

[Docs] Multi-task (multi-classification + regression) #2634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ChihYuLee opened this issue Feb 6, 2025 · 0 comments
Open

[Docs] Multi-task (multi-classification + regression) #2634

ChihYuLee opened this issue Feb 6, 2025 · 0 comments

Comments

@ChihYuLee
Copy link

ChihYuLee commented Feb 6, 2025

Hi I am wondering if there's an example of combining multi-classification and regression problem into linear coregionalization model? My input features are 2 dimensional output is 1D regression + 1D 3-classes categories.
My problem is defined as:


I am wondering if there is a way we can combine multi-class classification with regression. I probably need to write a CategoricalLikelihood().
My input features are 2 dimensional output is 1D regression + 1D 3-classes categories.
My current code is:

np.random.seed(42)
n_samples = 100
X1 = np.random.rand(n_samples) * 10
X2 = np.random.rand(n_samples) * 10

y_regression = 3 * X1 + 2 * X2 + np.random.randn(n_samples) * 2
y_classification = np.digitize(y_regression, bins=[-np.inf, 10, 25, np.inf]) - 1
y_classification = y_classification.astype(int)
y_regression = np.array([2.5 if label == 0 else 0.5 if label == 1 else 1.5 for label in y_classification])+np.random.randn(n_samples) * 2 *0.1

plt.figure(figsize=(4, 3))
plt.scatter(X1,X2, c=y_regression)
plt.title('Regression')
plt.colorbar()

plt.figure(figsize=(4, 3))
plt.scatter(X1,X2, c=y_classification)
plt.title('Classification')

X = np.hstack([X1[:,None], X2[:,None]])
y = np.hstack([y_regression[:,None], y_classification[:,None]])
X_train = torch.from_numpy(X).float()
y_train=torch.tensor(y)

num_latents = X_train.shape[1]
num_tasks = y_train.shape[1]
num_classes= 3

I have referred to some discussion and examples, still quite not sure where I should start.
#1396
https://github.com/cornellius-gp/gpytorch/blob/main/examples/03_Multitask_Exact_GPs/Hadamard_Multitask_GP_Regression.ipynb
https://docs.gpytorch.ai/en/stable/examples/04_Variational_and_Approximate_GPs/SVGP_Multitask_GP_Regression.html
I would appreciate any hints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant