What is multioutput regression?
In a regression problem, the target variable is continuous in nature. A machine learning model predicts the continuous target variable based on the features. In a multioutput regression problem, there is more than one target variable. For example, a machine learning model can predict the latitude and longitude of a place based on features. In that case, there will be two target variables – the latitude and the longitude of the place.
How to solve a multioutput regression problem?
Machine learning algorithms such as linear regression, K-Nearest Neighbor, and Decision Tree regressors can solve a multi-output regression problem inherently. For example, we can use the following Python code to solve a multioutput regression problem using linear regression.
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=200, n_features=5, n_targets=2, shuffle=True, random_state=1)
model = LinearRegression()
kfold = KFold(n_splits=10, shuffle=True, random_state=1)
scores = cross_val_score(model, X, y, cv=kfold, scoring="r2")
print("R2: ", scores.mean())
Here, we are first creating two ndarrays X and y using the function make_regression(). X contains 5 features, and y contains two continuous target variables (How to use make_regression() in sklearn?) …








































0 Comments