Skip to content

Commit

Permalink
Fix multi dimensional GaussianRegressor
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Dupre <[email protected]>
  • Loading branch information
xadupre committed May 28, 2024
1 parent 369949a commit c48511c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 4 additions & 2 deletions skl2onnx/operator_converters/gaussian_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def convert_gaussian_process_regressor(

if hasattr(op, "_y_train_std"):
# y_var = y_var * self._y_train_std**2
ys0_var = OnnxMul(var_y**2, ys0_var, op_version=opv)
ys0_var = OnnxMul(
ys0_var, (op._y_train_std**2).astype(dtype), op_version=opv
)

# var = np.sqrt(ys0_var)
var = OnnxSqrt(ys0_var, op_version=opv)
Expand Down Expand Up @@ -414,4 +416,4 @@ def convert_gaussian_process_classifier(
"output_class_labels": [False, True],
"zipmap": [False, True],
},
)
)
19 changes: 9 additions & 10 deletions tests/test_sklearn_gaussian_process_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@
WhiteKernel,
)
from sklearn.model_selection import train_test_split

try:
# scikit-learn >= 0.22
from sklearn.utils._testing import ignore_warnings
except ImportError:
# scikit-learn < 0.22
from sklearn.utils.testing import ignore_warnings
from sklearn.utils._testing import ignore_warnings
from sklearn.exceptions import ConvergenceWarning
from skl2onnx.common.data_types import FloatTensorType, DoubleTensorType
from skl2onnx import to_onnx
Expand Down Expand Up @@ -1019,6 +1013,9 @@ def test_gpr_rbf_fitted_return_std_exp_sine_squared_false(self):
model_onnx,
verbose=False,
basename="SklearnGaussianProcessExpSineSquaredStdF-Out0-Dec3",
# operator MatMul gets replaced by FusedMatMul but onnxruntime does not check
# the availability of the kernel for double.
disable_optimisation=True,
)
self.check_outputs(
gp,
Expand Down Expand Up @@ -1418,6 +1415,7 @@ def test_x_issue_789_cdist(self):
pipe.predict(vx1.astype(np.float64)).ravel(), pred[0].ravel()
)

@ignore_warnings(category=ConvergenceWarning)
def test_white_kernel_float(self):
X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
tx1, vx1, ty1, vy1 = train_test_split(X, y)
Expand All @@ -1436,6 +1434,7 @@ def test_white_kernel_float(self):
gpr.predict(vx1.astype(np.float32)).ravel(), pred[0].ravel(), rtol=1e-3
)

@ignore_warnings(category=ConvergenceWarning)
def test_white_kernel_double(self):
X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
tx1, vx1, ty1, vy1 = train_test_split(X, y)
Expand Down Expand Up @@ -1497,8 +1496,8 @@ def test_kernel_white_kernel(self):
m1 = res
m2 = ker(x, x)
assert_almost_equal(m2, m1, decimal=5)
def test_issue_1073(self):

def test_issue_1073_multidimension_process(self):
# multioutput gpr
n_samples, n_features, n_targets = 1000, 8, 3
X, y = make_regression(n_samples, n_features, n_targets=n_targets)
Expand All @@ -1522,5 +1521,5 @@ def test_issue_1073(self):
# log.setLevel(logging.DEBUG)
# logging.basicConfig(level=logging.DEBUG)
# TestSklearnGaussianProcessRegressor().test_kernel_white_kernel()
#TestSklearnGaussianProcessRegressor().test_issue_1073()
# TestSklearnGaussianProcessRegressor().test_issue_1073()
unittest.main(verbosity=2)

0 comments on commit c48511c

Please sign in to comment.