<p dir="auto">I fit exactly same data to LinearRegression() function but get two slightly different model coeficients.</p>
<p dir="auto">1st try:<br>
3260 12/05/2018 12:41:59 PM self.ref_price_psf_model.coef_1 = 0.8927025598257011<br>
3260 12/05/2018 12:41:59 PM self.ref_price_psf_model.coef_2 = -1.697037974902777e-05<br>
3260 12/05/2018 12:41:59 PM self.ref_price_psf_model.coef_3 = -0.031210337831353692<br>
3260 12/05/2018 12:41:59 PM self.ref_price_psf_model.coef_4 = 0.0021041235932400064<br>
3260 12/05/2018 12:41:59 PM self.ref_price_psf_model.intercept_ = 19.049368273019788</p>
<p dir="auto">2nd try:<br>
2976 12/05/2018 12:56:50 PM self.ref_price_psf_model.coef_1 = 0.8927025598256996<br>
2976 12/05/2018 12:56:50 PM self.ref_price_psf_model.coef_2 = -1.6970379749026318e-05<br>
2976 12/05/2018 12:56:50 PM self.ref_price_psf_model.coef_3 = -0.031210337831354636<br>
2976 12/05/2018 12:56:50 PM self.ref_price_psf_model.coef_4 = 0.0021041235932399926<br>
2976 12/05/2018 12:56:50 PM self.ref_price_psf_model.intercept_ = 19.049368273019823</p>
<p dir="auto">I am expecting then to be exactly the same. Could you tell me what could cause this? How to fix it?</p>
<p dir="auto">Thanks</p>
<p dir="auto"><code class="notranslate">LinearRegression</code> is sometimes not deterministic, as shown by the following test:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn.linear_model import LinearRegression
from sklearn.utils.testing import assert_array_equal
from sklearn.tests.test_multioutput import generate_multilabel_dataset_with_correlations

def test_investigate_linear_regression_indeterminacy():
    # Is LinearRegression deterministic?
    X, Y = generate_multilabel_dataset_with_correlations()
    y = Y[:, 1]
    ref = LinearRegression().fit(X, y).coef_
    for i in range(1000):
        coef = LinearRegression().fit(X, y).coef_
        assert_array_equal(ref, coef, 'iter %d' % i)

test_investigate_linear_regression_indeterminacy()"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">linear_model</span> <span class="pl-k">import</span> <span class="pl-v">LinearRegression</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">utils</span>.<span class="pl-s1">testing</span> <span class="pl-k">import</span> <span class="pl-s1">assert_array_equal</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">tests</span>.<span class="pl-s1">test_multioutput</span> <span class="pl-k">import</span> <span class="pl-s1">generate_multilabel_dataset_with_correlations</span>

<span class="pl-k">def</span> <span class="pl-en">test_investigate_linear_regression_indeterminacy</span>():
    <span class="pl-c"># Is LinearRegression deterministic?</span>
    <span class="pl-v">X</span>, <span class="pl-v">Y</span> <span class="pl-c1">=</span> <span class="pl-en">generate_multilabel_dataset_with_correlations</span>()
    <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-v">Y</span>[:, <span class="pl-c1">1</span>]
    <span class="pl-s1">ref</span> <span class="pl-c1">=</span> <span class="pl-v">LinearRegression</span>().<span class="pl-en">fit</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>).<span class="pl-s1">coef_</span>
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">1000</span>):
        <span class="pl-s1">coef</span> <span class="pl-c1">=</span> <span class="pl-v">LinearRegression</span>().<span class="pl-en">fit</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>).<span class="pl-s1">coef_</span>
        <span class="pl-en">assert_array_equal</span>(<span class="pl-s1">ref</span>, <span class="pl-s1">coef</span>, <span class="pl-s">'iter %d'</span> <span class="pl-c1">%</span> <span class="pl-s1">i</span>)

<span class="pl-en">test_investigate_linear_regression_indeterminacy</span>()</pre></div>
<p dir="auto">which failed <strong>at iteration 18</strong> in <a href="https://travis-ci.org/scikit-learn/scikit-learn/jobs/314812527#L2797" rel="nofollow">this Travis job</a>. I can't reproduce locally.<br>
It only occurs on one Travis platform (Linux + python 3.6.2), only sometimes (iteration 18 in this test case).</p>
<p dir="auto">Failure spotted initially in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="239823784" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/9257" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/9257/hovercard?comment_id=350111442&amp;comment_type=issue_comment" href="https://github.com/scikit-learn/scikit-learn/pull/9257#issuecomment-350111442">#9257 (comment)</a></p>