<h4 dir="auto">Describe the bug</h4>

<p dir="auto">When fitting a GPR with y-values having std=0 (and normalize=True), an error occurs. The error relates to dividing by 0 in sklearn/gaussian_processes/_gpr.py: </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/scikit-learn/scikit-learn/blob/fd1ff73c64816159f08fb4cbb322c6050b03a3ac/sklearn/gaussian_process/_gpr.py#L201">scikit-learn/sklearn/gaussian_process/_gpr.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 201
      in
      <a data-pjax="true" class="commit-tease-sha" href="/scikit-learn/scikit-learn/commit/fd1ff73c64816159f08fb4cbb322c6050b03a3ac">fd1ff73</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L201" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="201"></td>
          <td id="LC201" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1">y</span> <span class="pl-c1">=</span> (<span class="pl-s1">y</span> <span class="pl-c1">-</span> <span class="pl-s1">self</span>.<span class="pl-s1">_y_train_mean</span>) <span class="pl-c1">/</span> <span class="pl-s1">self</span>.<span class="pl-s1">_y_train_std</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<h4 dir="auto">Steps/Code to Reproduce</h4>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import ConstantKernel, Matern

X = [[1.,2.],[2.,2.]]
y = [0,0]

m52 = ConstantKernel(1.0) * Matern(nu=2.5)
gpr = GaussianProcessRegressor(kernel=m52, normalize_y=True, n_restarts_optimizer=3)

gpr.fit(X,y)
"><pre class="notranslate"><code class="notranslate">from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import ConstantKernel, Matern

X = [[1.,2.],[2.,2.]]
y = [0,0]

m52 = ConstantKernel(1.0) * Matern(nu=2.5)
gpr = GaussianProcessRegressor(kernel=m52, normalize_y=True, n_restarts_optimizer=3)

gpr.fit(X,y)

</code></pre></div>
<h4 dir="auto">Expected Results</h4>

<p dir="auto">Either the regressor could internally switch normalize_y to False, when np.std(y)==0 or set the std to 1. Or warn the user of the eminent error instead of an error message that can be difficult to understand.</p>
<h4 dir="auto">Actual Results</h4>

<p dir="auto">"runfile('C:/users/sqbl/onedrive - novo nordisk/dokumenter/python/12 gitlab inout/po20200908/processoptimizer/ProcessOptimizer/learning/gaussian_process/untitled0.py', wdir='C:/users/sqbl/onedrive - novo nordisk/dokumenter/python/12 gitlab inout/po20200908/processoptimizer/ProcessOptimizer/learning/gaussian_process', current_namespace=True)<br>
C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\sklearn\gaussian_process_gpr.py:201: RuntimeWarning: invalid value encountered in true_divide<br>
y = (y - self._y_train_mean) / self._y_train_std<br>
Traceback (most recent call last):</p>
<p dir="auto">File "C:\users\sqbl\onedrive - novo nordisk\dokumenter\python\12 gitlab inout\po20200908\processoptimizer\ProcessOptimizer\learning\gaussian_process\untitled0.py", line 16, in <br>
gpr.fit(X,y)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\sklearn\gaussian_process_gpr.py", line 234, in fit<br>
self.kernel_.bounds))]</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\sklearn\gaussian_process_gpr.py", line 503, in _constrained_optimization<br>
bounds=bounds)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize_minimize.py", line 618, in minimize<br>
callback=callback, **options)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize\lbfgsb.py", line 308, in _minimize_lbfgsb<br>
finite_diff_rel_step=finite_diff_rel_step)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize\optimize.py", line 262, in _prepare_scalar_function<br>
finite_diff_rel_step, bounds, epsilon=epsilon)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize_differentiable_functions.py", line 76, in <strong>init</strong><br>
self._update_fun()</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize_differentiable_functions.py", line 166, in _update_fun<br>
self._update_fun_impl()</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize_differentiable_functions.py", line 73, in update_fun<br>
self.f = fun_wrapped(self.x)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize_differentiable_functions.py", line 70, in fun_wrapped<br>
return fun(x, *args)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize\optimize.py", line 74, in <strong>call</strong><br>
self._compute_if_needed(x, *args)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\optimize\optimize.py", line 68, in _compute_if_needed<br>
fg = self.fun(x, *args)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\sklearn\gaussian_process_gpr.py", line 225, in obj_func<br>
theta, eval_gradient=True, clone_kernel=False)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\sklearn\gaussian_process_gpr.py", line 476, in log_marginal_likelihood<br>
alpha = cho_solve((L, True), y_train)  # Line 3</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\scipy\linalg\decomp_cholesky.py", line 194, in cho_solve<br>
b1 = asarray_chkfinite(b)</p>
<p dir="auto">File "C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\lib\site-packages\numpy\lib\function_base.py", line 486, in asarray_chkfinite<br>
"array must not contain infs or NaNs")</p>
<p dir="auto">ValueError: array must not contain infs or NaNs"</p>
<h4 dir="auto">Versions</h4>

<p dir="auto">System:<br>
python: 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)]<br>
executable: C:\Users\sqbl\AppData\Local\Continuum\anaconda3\envs\updatePO20200908\python.exe<br>
machine: Windows-10-10.0.17763-SP0</p>
<p dir="auto">Python dependencies:<br>
pip: 20.2.2<br>
setuptools: 41.6.0<br>
sklearn: 0.23.2<br>
numpy: 1.19.1<br>
scipy: 1.5.2<br>
Cython: None<br>
pandas: 1.1.2<br>
matplotlib: 3.3.1<br>
joblib: 0.16.0<br>
threadpoolctl: 2.1.0</p>
<p dir="auto">Built with OpenMP: True</p>
<p dir="auto">In <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="532692478" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/15782" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/15782/hovercard?comment_id=685086334&amp;comment_type=issue_comment" href="https://github.com/scikit-learn/scikit-learn/pull/15782#issuecomment-685086334">#15782 (comment)</a>, <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rkern/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rkern">@rkern</a> writes regarding that fix:</p>
<blockquote>
<p dir="auto">FWIW, this broke a few downstream users where y_train.std() == 0 (e.g. only one datapoint) when being used for Bayesian optimization. This probably needs a guard for such a case (which is common in the Bayesian optimization use case)</p>
</blockquote>
<p dir="auto">More detail in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="667038712" data-permission-text="Title is private" data-url="https://github.com/bayesian-optimization/BayesianOptimization/issues/243" data-hovercard-type="issue" data-hovercard-url="/bayesian-optimization/BayesianOptimization/issues/243/hovercard?comment_id=685004696&amp;comment_type=issue_comment" href="https://github.com/bayesian-optimization/BayesianOptimization/issues/243#issuecomment-685004696">bayesian-optimization/BayesianOptimization#243 (comment)</a>:</p>
<blockquote>
<p dir="auto">The normalize_y=True option which is used now divides out the standard deviation of the y data, not just subtracting the mean. When there is just one data point, this results in a NaN.</p>
</blockquote>