<p dir="auto">If I'm running the RANSAC-example code, everything works fine</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
from matplotlib import pyplot as plt

from sklearn import linear_model, datasets

n_samples = 5

X, y, coef = datasets.make_regression(n_samples=n_samples, n_features=1,
                                      n_informative=1, noise=10,
                                      coef=True, random_state=0)
# X = array([[ 0.97873798],
#            [ 2.2408932 ],
#            [ 1.76405235],
#            [ 1.86755799],
#            [ 0.40015721]])
# y = array([  37.7695571 ,  123.51062836,   67.41989586,   92.53006841, 30.17155299])

model_ransac = linear_model.RANSACRegressor(linear_model.LinearRegression())
model_ransac.fit(X, y)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-k">from</span> <span class="pl-s1">sklearn</span> <span class="pl-k">import</span> <span class="pl-s1">linear_model</span>, <span class="pl-s1">datasets</span>

<span class="pl-s1">n_samples</span> <span class="pl-c1">=</span> <span class="pl-c1">5</span>

<span class="pl-v">X</span>, <span class="pl-s1">y</span>, <span class="pl-s1">coef</span> <span class="pl-c1">=</span> <span class="pl-s1">datasets</span>.<span class="pl-en">make_regression</span>(<span class="pl-s1">n_samples</span><span class="pl-c1">=</span><span class="pl-s1">n_samples</span>, <span class="pl-s1">n_features</span><span class="pl-c1">=</span><span class="pl-c1">1</span>,
                                      <span class="pl-s1">n_informative</span><span class="pl-c1">=</span><span class="pl-c1">1</span>, <span class="pl-s1">noise</span><span class="pl-c1">=</span><span class="pl-c1">10</span>,
                                      <span class="pl-s1">coef</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">random_state</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-c"># X = array([[ 0.97873798],</span>
<span class="pl-c">#            [ 2.2408932 ],</span>
<span class="pl-c">#            [ 1.76405235],</span>
<span class="pl-c">#            [ 1.86755799],</span>
<span class="pl-c">#            [ 0.40015721]])</span>
<span class="pl-c"># y = array([  37.7695571 ,  123.51062836,   67.41989586,   92.53006841, 30.17155299])</span>

<span class="pl-s1">model_ransac</span> <span class="pl-c1">=</span> <span class="pl-s1">linear_model</span>.<span class="pl-v">RANSACRegressor</span>(<span class="pl-s1">linear_model</span>.<span class="pl-v">LinearRegression</span>())
<span class="pl-s1">model_ransac</span>.<span class="pl-en">fit</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>)</pre></div>
<p dir="auto">But as soon as I try <code class="notranslate">model_ransac.fit(X, y)</code> with my own <code class="notranslate">y</code> I'm getting an error</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
from matplotlib import pyplot as plt

from sklearn import linear_model, datasets

n_samples = 5

X, _, coef = datasets.make_regression(n_samples=n_samples, n_features=1,
                                      n_informative=1, noise=10,
                                      coef=True, random_state=0)

y  = np.array([1., 1., 2., 1., 1.])

# X = array([[ 0.97873798],
#            [ 2.2408932 ],
#            [ 1.76405235],
#            [ 1.86755799],
#            [ 0.40015721]])
# y = array([ 1.,  1.,  2.,  1.,  1.])
# y.shape = (5,)

model_ransac = linear_model.RANSACRegressor(linear_model.LinearRegression())
model_ransac.fit(X, y)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-k">from</span> <span class="pl-s1">sklearn</span> <span class="pl-k">import</span> <span class="pl-s1">linear_model</span>, <span class="pl-s1">datasets</span>

<span class="pl-s1">n_samples</span> <span class="pl-c1">=</span> <span class="pl-c1">5</span>

<span class="pl-v">X</span>, <span class="pl-s1">_</span>, <span class="pl-s1">coef</span> <span class="pl-c1">=</span> <span class="pl-s1">datasets</span>.<span class="pl-en">make_regression</span>(<span class="pl-s1">n_samples</span><span class="pl-c1">=</span><span class="pl-s1">n_samples</span>, <span class="pl-s1">n_features</span><span class="pl-c1">=</span><span class="pl-c1">1</span>,
                                      <span class="pl-s1">n_informative</span><span class="pl-c1">=</span><span class="pl-c1">1</span>, <span class="pl-s1">noise</span><span class="pl-c1">=</span><span class="pl-c1">10</span>,
                                      <span class="pl-s1">coef</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">random_state</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)

<span class="pl-s1">y</span>  <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">1.</span>, <span class="pl-c1">1.</span>, <span class="pl-c1">2.</span>, <span class="pl-c1">1.</span>, <span class="pl-c1">1.</span>])

<span class="pl-c"># X = array([[ 0.97873798],</span>
<span class="pl-c">#            [ 2.2408932 ],</span>
<span class="pl-c">#            [ 1.76405235],</span>
<span class="pl-c">#            [ 1.86755799],</span>
<span class="pl-c">#            [ 0.40015721]])</span>
<span class="pl-c"># y = array([ 1.,  1.,  2.,  1.,  1.])</span>
<span class="pl-c"># y.shape = (5,)</span>

<span class="pl-s1">model_ransac</span> <span class="pl-c1">=</span> <span class="pl-s1">linear_model</span>.<span class="pl-v">RANSACRegressor</span>(<span class="pl-s1">linear_model</span>.<span class="pl-v">LinearRegression</span>())
<span class="pl-s1">model_ransac</span>.<span class="pl-en">fit</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>)</pre></div>
<p dir="auto">Error message</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="model_ransac.fit(X, y)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-14-218aaab43d92&gt; in &lt;module&gt;()
----&gt; 1 model_ransac.fit(X, y)

/home/clemens/.local/lib/python2.7/site-packages/sklearn/linear_model/ransac.pyc in fit(self, X, y)
    299             # score of inlier data set
    300             score_subset = base_estimator.score(X_inlier_subset,
--&gt; 301                                                 y_inlier_subset)
    302 
    303             # same number of inliers but worse score -&gt; skip current random

/home/clemens/.local/lib/python2.7/site-packages/sklearn/base.pyc in score(self, X, y, sample_weight)
    326 
    327         from .metrics import r2_score
--&gt; 328         return r2_score(y, self.predict(X), sample_weight=sample_weight)
    329 
    330 

/home/clemens/.local/lib/python2.7/site-packages/sklearn/linear_model/base.pyc in predict(self, X)
    153             Returns predicted values.
    154         &quot;&quot;&quot;
--&gt; 155         return self.decision_function(X)
    156 
    157     _center_data = staticmethod(center_data)

/home/clemens/.local/lib/python2.7/site-packages/sklearn/linear_model/base.pyc in decision_function(self, X)
    136         check_is_fitted(self, &quot;coef_&quot;)
    137 
--&gt; 138         X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
    139         return safe_sparse_dot(X, self.coef_.T,
    140                                dense_output=True) + self.intercept_

/home/clemens/.local/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features)
    358             raise ValueError(&quot;Found array with %d sample(s) (shape=%s) while a&quot;
    359                              &quot; minimum of %d is required.&quot;
--&gt; 360                              % (n_samples, shape_repr, ensure_min_samples))
    361 
    362     if ensure_min_features &gt; 0 and array.ndim == 2:

ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required."><pre class="notranslate"><code class="notranslate">model_ransac.fit(X, y)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-14-218aaab43d92&gt; in &lt;module&gt;()
----&gt; 1 model_ransac.fit(X, y)

/home/clemens/.local/lib/python2.7/site-packages/sklearn/linear_model/ransac.pyc in fit(self, X, y)
    299             # score of inlier data set
    300             score_subset = base_estimator.score(X_inlier_subset,
--&gt; 301                                                 y_inlier_subset)
    302 
    303             # same number of inliers but worse score -&gt; skip current random

/home/clemens/.local/lib/python2.7/site-packages/sklearn/base.pyc in score(self, X, y, sample_weight)
    326 
    327         from .metrics import r2_score
--&gt; 328         return r2_score(y, self.predict(X), sample_weight=sample_weight)
    329 
    330 

/home/clemens/.local/lib/python2.7/site-packages/sklearn/linear_model/base.pyc in predict(self, X)
    153             Returns predicted values.
    154         """
--&gt; 155         return self.decision_function(X)
    156 
    157     _center_data = staticmethod(center_data)

/home/clemens/.local/lib/python2.7/site-packages/sklearn/linear_model/base.pyc in decision_function(self, X)
    136         check_is_fitted(self, "coef_")
    137 
--&gt; 138         X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
    139         return safe_sparse_dot(X, self.coef_.T,
    140                                dense_output=True) + self.intercept_

/home/clemens/.local/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features)
    358             raise ValueError("Found array with %d sample(s) (shape=%s) while a"
    359                              " minimum of %d is required."
--&gt; 360                              % (n_samples, shape_repr, ensure_min_samples))
    361 
    362     if ensure_min_features &gt; 0 and array.ndim == 2:

ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required.
</code></pre></div>
<p dir="auto">BR Clemens</p>
<p dir="auto">If the "residual_threshold" argument in RANSACRegressor is set to zero, the regression will almost certainly fail.  However, figuring out what is going on based on the error messages is not obvious:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required."><pre class="notranslate"><code class="notranslate">ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required.
</code></pre></div>
<p dir="auto">(I believe that when residual_threshold==0.0, one of the cross-validation classes is empty, and things break.)</p>
<p dir="auto">Because (I think?) there is no legitimate reason to set residual_threshold==0.0, and to save some future soul the debugging journey I just went through, it might be helpful to throw an exception (or at least a clear warning) if residual_threshold==0.0.</p>