Multioutput Regression
Multioutput Regression is an extended version of Simple Linear Regression. We can easily find about Simple Linear Regression on the internet and there is a vast literature available on that but there are cases when we want to find the relationship between multiple independent variables and multiple quantitative dependent variable. When we come across such a problem, Multioutput Regression can be used.
Introduction:
Multioutput regression is a regression model that aims to model the relationship between the independent variables and multiple dependent variables. Unlike Simple linear Regression, where the goal is to predict only one variable given a set of independent variables. Multioutput regression is also termed as multi-target regression. Basically, it extends the simple linear regression framework to make it able to handle the problems where we have multiple dependent variables.
It enables a deeper understanding and accurate predictions based on joint behavior of the data.
Hypothesis:
Hypothesis of Multioutput Regression is that there exists a linear relationship between independent variables and multiple dependent variables.
Null Hypothesis(Ho): Null Hypothesis suggests that there is no linear relationship between Independent Variables and multiple dependent Variables. The Regression coefficients for all the variables are zero.
Alternative Hypothesis(Ha): Alternative Hypothesis Suggests that the regression coefficient for atleast one variable is non-zero suggesting there is a linear relationship between independent and dependent variables.
We can also use Linear Regression for finding the relationship between independent and multiple dependent variables but there the output dependent variables will be converted to an array then it will try to fit a simple linear regression to the data given and will give the output.
Now, here you can find a demo of how to tackle the problem of multioutput Regression. In the code given Below, I have used the Multioutput Regressor available in Scikit Learn Library.
ARTICLE OUTLINE:
- Importing Libraries
- Loading the data
- Splitting the dataset
- Training Multioutput Regression
- Getting the predictions
- Checking the Performance
1. Importing Libraries
First Step always is to import the required libraries.
Get Disha Verma’s stories in your inbox
Join Medium for free to get updates from this writer.
Let’s read the multivariate dataset already available in the linnerud sklearn library. It is a small dataset having 20 dimensions but is good to start with.
import numpy as np
from sklearn.datasets import load_linnerud
from sklearn.multioutput import MultiOutputRegressor
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score2. Loading the dataset
After importing the required libraries, let’s import the dataset. Here is the code to import the dataset
# Importing the dataset
X, y = load_linnerud(return_X_y=True)Given data will be in the form of an array.
3. Splitting the dataset
Ideally this step should have been the data pre-processing step, but since it is a very small dataset and which have been directly imported from the sklearn library itself, I am skipping the data preprocessing step.
Here is the code for splitting the dataset in train and test. You can learn more about train and test split from train_test_split available in scikit-learn library.
# Train-Test Split
X_train, X_test, y_train, y_test = train_test_split( X, y,
test_size=0.33, random_state=42)4. Training the Multioutput Regressor
After splitting the dataset, it is time to train the model using the training dataset. Below is the code for the same
# training the model
model = MultiOutputRegressor(LinearRegression()).fit(X_train, y_train)I have used the Linear Regression model for training the multioutput regressor, you can try to use any other regressor also like Random Forest Regressor.
5. Getting the Predictions
For getting the predictions, we need to feed the independent test data to the model.
# Getting the Prediction
predictions=model.predict(X_test)6. Checking the Performance
Generally the metrics to check the performance of the model depends on the business case. But since it is a generalized regression problem, I will be using R2 Score.
# Checking the Performance
r2_score(y_test, predictions)I have demonstrated here how to handle the problem of multi-target regression. You can access the Google Colab File for the Problem through the link given.







