Skip to content

RANSACRegressor throws "less than two samples" warnings #98

@ablot

Description

@ablot

I have:

/camp/home/blota/.conda/envs/iss-preprocess/lib/python3.10/site-packages/sklearn/metrics/_regression.py:918: UndefinedMetricWarning: R^2 score is not well-defined with less than two samples.
  warnings.warn(msg, UndefinedMetricWarning)

It's triggered in correct_shifts_to_ref (L464 in masked_phase_corr branch) even with 52 samples. I did not investigate more than checking what triggers it. Did you get that @znamensk ?

reg = RANSACRegressor(random_state=0).fit(
                X[inliers, :], shifts[ich, idim, inliers]
            )

To make it easier to reproduce:

import numpy as np
from sklearn.linear_model import RANSACRegressor
y = np.array([ 64.,  36.,  36.,  33.,  32.,  35.,  34.,  33.,  32.,  89.,  36.,
        30.,  34.,  32.,  36.,  34.,  34.,  34., 408.,  39.,  35.,  36.,
        35.,  35.,  34., 231.,  43.,  35.,  34.,  34.,  36.,  34.,  35.,
        33., 220., 295., 268.,  35.,  35.,  35.,  36.,  37.,  54., 149.,
       213., 272., 204.,  43.,  36.,  40.,  37.,  12.])
X = np.array([[0., 0., 1.],
       [0., 1., 1.],
       [0., 2., 1.],
       [0., 3., 1.],
       [0., 4., 1.],
       [0., 5., 1.],
       [0., 6., 1.],
       [0., 7., 1.],
       [0., 8., 1.],
       [1., 0., 1.],
       [1., 1., 1.],
       [1., 2., 1.],
       [1., 3., 1.],
       [1., 4., 1.],
       [1., 5., 1.],
       [1., 6., 1.],
       [1., 7., 1.],
       [1., 8., 1.],
       [2., 0., 1.],
       [2., 1., 1.],
       [2., 2., 1.],
       [2., 5., 1.],
       [2., 6., 1.],
       [2., 7., 1.],
       [2., 8., 1.],
       [3., 0., 1.],
       [3., 1., 1.],
       [3., 2., 1.],
       [3., 3., 1.],
       [3., 4., 1.],
       [3., 5., 1.],
       [3., 6., 1.],
       [3., 7., 1.],
       [3., 8., 1.],
       [4., 0., 1.],
       [4., 1., 1.],
       [4., 2., 1.],
       [4., 3., 1.],
       [4., 4., 1.],
       [4., 5., 1.],
       [4., 6., 1.],
       [4., 7., 1.],
       [4., 8., 1.],
       [5., 0., 1.],
       [5., 1., 1.],
       [5., 2., 1.],
       [5., 3., 1.],
       [5., 4., 1.],
       [5., 5., 1.],
       [5., 6., 1.],
       [5., 7., 1.],
       [5., 8., 1.]])

reg = RANSACRegressor(random_state=0).fit(X,y)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions