def test_compound_kernel_input_type(): kernel = CompoundKernel([WhiteKernel(noise_level=3.0)]) assert not kernel.requires_vector_input kernel = CompoundKernel([WhiteKernel(noise_level=3.0), RBF(length_scale=2.0)]) assert kernel.requires_vector_input
def kernel_(self): if self.n_classes_ == 2: return self.base_estimator_.kernel_ else: return CompoundKernel( [estimator.kernel_ for estimator in self.base_estimator_.estimators_])
def test_guess_priors(): """Construct a complicated kernel and check if priors are constructed correctly.""" kernel = Exponentiation( ConstantKernel(constant_value_bounds="fixed") * Matern() + WhiteKernel() + CompoundKernel([RBF(), Matern()]), 2.0, ) priors = guess_priors(kernel) assert len(priors) == 4 expected = [ -1.737085713764618, -4.107091211892862, -1.737085713764618, -1.737085713764618, ] for p, v in zip(priors, expected): assert_almost_equal(p(0.0), v)
"Increasing the bound and calling " "fit again may find a better value." ) assert ( record[1].message.args[0] == "The optimal value found for " "dimension 1 of parameter " "length_scale is close to the " "specified upper bound 100.0. " "Increasing the bound and calling " "fit again may find a better value." ) @pytest.mark.parametrize( "params, error_type, err_msg", [ ( {"kernel": CompoundKernel(0)}, ValueError, "kernel cannot be a CompoundKernel", ) ], ) def test_gpc_fit_error(params, error_type, err_msg): """Check that expected error are raised during fit.""" gpc = GaussianProcessClassifier(**params) with pytest.raises(error_type, match=err_msg): gpc.fit(X, y)