<h3 dir="auto">Describe the bug</h3>
<p dir="auto">I'm executing below command after <code class="notranslate">/usr/bin/python3 -sBm build -w --no-isolation</code>.</p>
<p dir="auto">Looks like documentation buiuld fails because wrong import in sklearn/__check_build/<strong>init</strong>.py</p>
<h3 dir="auto">Steps/Code to Reproduce</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/usr/bin/python3 -sBm build -w --no-isolation
PYTHONPATH=$PWD/build/$(cd build; ls -1d lib*) /usr/bin/sphinx-build -n -T -b html doc build/sphinx/html"><pre class="notranslate"><code class="notranslate">/usr/bin/python3 -sBm build -w --no-isolation
PYTHONPATH=$PWD/build/$(cd build; ls -1d lib*) /usr/bin/sphinx-build -n -T -b html doc build/sphinx/html
</code></pre></div>
<h3 dir="auto">Expected Results</h3>
<p dir="auto">It should be possible to build documemtation.</p>
<h3 dir="auto">Actual Results</h3>
<details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[tkloczko@pers-jacek scikit-learn-1.2.2]$ PYTHONPATH=$PWD/build/$(cd build; ls -1d lib*) /usr/bin/sphinx-build -n -T -b man doc build/sphinx/man
Running Sphinx v6.1.3

Traceback (most recent call last):
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 48, in &lt;module&gt;
    from sklearn._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/usr/lib/python3.8/site-packages/sphinx/config.py&quot;, line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/doc/conf.py&quot;, line 20, in &lt;module&gt;
    from sklearn.externals._packaging.version import parse
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__init__.py&quot;, line 81, in &lt;module&gt;
    from sklearn import __check_build  # noqa: F401
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 50, in &lt;module&gt;
    raise_build_error(e)
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build:
_check_build.pyx          _check_build.c            __pycache__
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File &quot;/usr/lib/python3.8/site-packages/sphinx/cmd/build.py&quot;, line 279, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File &quot;/usr/lib/python3.8/site-packages/sphinx/application.py&quot;, line 202, in __init__
    self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
  File &quot;/usr/lib/python3.8/site-packages/sphinx/config.py&quot;, line 173, in read
    namespace = eval_config_file(filename, tags)
  File &quot;/usr/lib/python3.8/site-packages/sphinx/config.py&quot;, line 364, in eval_config_file
    raise ConfigError(msg % traceback.format_exc()) from exc
sphinx.errors.ConfigError: There is a programmable error in your configuration file:

Traceback (most recent call last):
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 48, in &lt;module&gt;
    from sklearn._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/usr/lib/python3.8/site-packages/sphinx/config.py&quot;, line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/doc/conf.py&quot;, line 20, in &lt;module&gt;
    from sklearn.externals._packaging.version import parse
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__init__.py&quot;, line 81, in &lt;module&gt;
    from sklearn import __check_build  # noqa: F401
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 50, in &lt;module&gt;
    raise_build_error(e)
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build:
_check_build.pyx          _check_build.c            __pycache__
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.


Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 48, in &lt;module&gt;
    from sklearn._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/usr/lib/python3.8/site-packages/sphinx/config.py&quot;, line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/doc/conf.py&quot;, line 20, in &lt;module&gt;
    from sklearn.externals._packaging.version import parse
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__init__.py&quot;, line 81, in &lt;module&gt;
    from sklearn import __check_build  # noqa: F401
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 50, in &lt;module&gt;
    raise_build_error(e)
  File &quot;/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py&quot;, line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build:
_check_build.pyx          _check_build.c            __pycache__
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform."><pre lang="consile" class="notranslate"><code class="notranslate">[tkloczko@pers-jacek scikit-learn-1.2.2]$ PYTHONPATH=$PWD/build/$(cd build; ls -1d lib*) /usr/bin/sphinx-build -n -T -b man doc build/sphinx/man
Running Sphinx v6.1.3

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 48, in &lt;module&gt;
    from sklearn._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/doc/conf.py", line 20, in &lt;module&gt;
    from sklearn.externals._packaging.version import parse
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__init__.py", line 81, in &lt;module&gt;
    from sklearn import __check_build  # noqa: F401
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 50, in &lt;module&gt;
    raise_build_error(e)
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build:
_check_build.pyx          _check_build.c            __pycache__
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/cmd/build.py", line 279, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/usr/lib/python3.8/site-packages/sphinx/application.py", line 202, in __init__
    self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 173, in read
    namespace = eval_config_file(filename, tags)
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 364, in eval_config_file
    raise ConfigError(msg % traceback.format_exc()) from exc
sphinx.errors.ConfigError: There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 48, in &lt;module&gt;
    from sklearn._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/doc/conf.py", line 20, in &lt;module&gt;
    from sklearn.externals._packaging.version import parse
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__init__.py", line 81, in &lt;module&gt;
    from sklearn import __check_build  # noqa: F401
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 50, in &lt;module&gt;
    raise_build_error(e)
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build:
_check_build.pyx          _check_build.c            __pycache__
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.


Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 48, in &lt;module&gt;
    from sklearn._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/doc/conf.py", line 20, in &lt;module&gt;
    from sklearn.externals._packaging.version import parse
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__init__.py", line 81, in &lt;module&gt;
    from sklearn import __check_build  # noqa: F401
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 50, in &lt;module&gt;
    raise_build_error(e)
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build/__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.2/sklearn/__check_build:
_check_build.pyx          _check_build.c            __pycache__
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
</code></pre></div>
</details>
<h3 dir="auto">Versions</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="1.2.2"><pre class="notranslate">1.2.2</pre></div>
<p dir="auto">Hello,</p>
<p dir="auto">the gaussian process are by default fitted using the fmin_cobyal optimizer.  The optimizer is started from various random inital conditions to avoid local extrema. The problem is, the worst of those extrema is chosen in the end.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="optimal_minus_rlf_value, optimal_par = self.reduced_likelihood_function(theta=optimal_theta)
# sign error 
# reduced_likelihood_function return the likelihood
# not the negative likelihood
optimal_rlf_value = - optimal_minus_rlf_value(theta=optimal_theta)"><pre class="notranslate"><span class="pl-s1">optimal_minus_rlf_value</span>, <span class="pl-s1">optimal_par</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">reduced_likelihood_function</span>(<span class="pl-s1">theta</span><span class="pl-c1">=</span><span class="pl-s1">optimal_theta</span>)
<span class="pl-c"># sign error </span>
<span class="pl-c"># reduced_likelihood_function return the likelihood</span>
<span class="pl-c"># not the negative likelihood</span>
<span class="pl-s1">optimal_rlf_value</span> <span class="pl-c1">=</span> <span class="pl-c1">-</span> <span class="pl-en">optimal_minus_rlf_value</span>(<span class="pl-s1">theta</span><span class="pl-c1">=</span><span class="pl-s1">optimal_theta</span>)</pre></div>
<p dir="auto">The reason it did not show up in the unit test is, that they been to easy. Even the worst local maximum was good enough to pass the test. I added a test which is more "tough" and manage to prove the current solution wrong.<br>
Here is the solution to the unit test plotted with the current implementation:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/7404851/3053066/42fef8c4-e1a3-11e3-9158-08074a5f427f.png"><img src="https://cloud.githubusercontent.com/assets/7404851/3053066/42fef8c4-e1a3-11e3-9158-08074a5f427f.png" alt="gp_org" style="max-width: 100%;"></a><br>
and fixed:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/7404851/3053068/48c970f4-e1a3-11e3-8801-d41f2ee34b27.png"><img src="https://cloud.githubusercontent.com/assets/7404851/3053068/48c970f4-e1a3-11e3-8801-d41f2ee34b27.png" alt="gp_with_fix" style="max-width: 100%;"></a></p>