具有具有一维输入向量和二维输出向量的 SVR 模型

Having an SVR model with one dimensional input vector and 2 dimensional output vector

我目前有两个数据集。一个给我一个对应于不同输入数字的输出有理数。另一个给了我一个对应于相同输入向量的输出整数。数据看起来很像这样 -

X (input) = 0, 5, 10, 15, 20, 25
Y1 (output 1) = 0.2, 0.4, 0.7, 1.1, 1.5, 1.9
Y2 (output 2) = 45, 47, 51, 60, 90, 100

虽然我已经成功地使用 sklearn.svm 的 SVR 训练了两个不同的 SVR 模型,如下所示 -

from sklearn.svm import SVR
regressor = SVR(kernel = 'rbf')
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
regressor.fit(X, Y1)
Y1_rbf = svr_rbf.fit(X, Y1).predict(X)
regressor.fit(X, Y2)
Y2_rbf = svr_rbf.fit(X, Y2).predict(X)

有没有办法使用 SVR 进行多维输出?像输入向量 X 和输出向量一样 - [Y1, Y2]?没有具体原因-我只是想减少代码量并使一切变得简洁。

P. S. 我调查了这个 - https://github.com/nwtgck/multi-svr-python,这不是我需要的。

一个不错的选择肯定是使用 sklearn.multioutput 模块及其提供的回归和分类模型。

他们基本上采用基本估计器(SVR 在你的情况下)并用它来预测多个标签。根据实际模型,这是在不同的 ways.The MultiOutputRegressor 中实现的,例如每个目标适合一个回归器。

使用它肯定会使代码更简洁:

import numpy as np
from sklearn.multioutput import MultiOutputRegressor
from sklearn.svm import SVR


X = np.asarray([0, 5, 10, 15, 20, 25]).reshape(-1, 1)
y = np.asarray([[0.2, 45], [0.4, 47], [0.7, 51], [1.1, 60], [1.5, 90], [1.9, 100]])

regressor = MultiOutputRegressor(SVR(kernel='rbf', C=1e3, gamma=0.1))

regressor.fit(X, y)