Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RANSAC does not pass sample weights to final estimator #13425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gerhajdu opened this issue Mar 8, 2019 · 14 comments · Fixed by #15773
Closed

RANSAC does not pass sample weights to final estimator #13425

gerhajdu opened this issue Mar 8, 2019 · 14 comments · Fixed by #15773
Labels
Easy Well-defined and straightforward way to resolve help wanted

Comments

@gerhajdu
Copy link

gerhajdu commented Mar 8, 2019

RANSACRegressor does not pass weights to the used estimator during the training of the final model.

Sample weights to RANSAC have been requested by #5871 and #6113, and implemented in #6140, but the weights of the final inlier sample are not used during the training of the final model.

The issue only causes crashes when using a custom estimator which always requires the sample_weight parameter to be passed to it, as is the case in the training of the final estimator with the current implementation.

# estimate final model using all inliers
base_estimator.fit(X_inlier_best, y_inlier_best)
self.estimator_ = base_estimator

@jnothman
Copy link
Member

Thanks for the report. A fix is welcome

@jnothman jnothman added Easy Well-defined and straightforward way to resolve help wanted labels Mar 10, 2019
@AbhishekBabuji
Copy link

Desperately waiting for first time issues tag XD

@jnothman
Copy link
Member

You're welcome to take it on as a first time contributor. My main reason for not adding that tag is that this may not be trivial to write a test for.

@HunterMcGushion
Copy link
Contributor

@jnothman, if no one is looking into this, would you mind clarifying the kind of tests necessary here?

Do we want to assert that calls to base_estimator.fit include the correct sample_weight (when provided to RANSACRegressor.fit) via mock or pytest’s monkeypatch?

Or would it be sufficient to give RANSACRegressor a dummy base_estimator that requires the sample_weight argument in its fit method and ensure it runs without catching on fire?

@jnothman
Copy link
Member

jnothman commented Mar 20, 2019 via email

@pallashadow
Copy link

It is not enough to pass sample_weight to base_estimator.fit(), because it is the loss_function within RANSACRegressor.fit() who determined whether the weighted inlier_subset is good enough. Sample_weight should be passed to loss_function as well.

@J-A16
Copy link
Contributor

J-A16 commented Nov 27, 2019

@jnothman, this class has been made private, is this issue still open though?

@J-A16
Copy link
Contributor

J-A16 commented Nov 27, 2019

As in should it really still be open?

@J-A16
Copy link
Contributor

J-A16 commented Dec 3, 2019

This is what I have so far. Can someone please check this? @jnothman, @gerhajdu?

J-A16@e0d78ce#diff-15e1ad3883740ee06b2d4e15f86cad68

@J-A16
Copy link
Contributor

J-A16 commented Dec 4, 2019

It passes pytest test_ransac.py, by the way. No errors. Inside that test file, there are weights passed to the fit method of RANSACRegressor. I did a couple tests where I edited RANSACRegressor to make it fail, but the code I posted works.

@jnothman
Copy link
Member

jnothman commented Dec 4, 2019

@jnothman, this class has been made private, is this issue still open though?

The class is not private. It is publicly available for import from linear_model. Only the module is private.

@J-A16
Copy link
Contributor

J-A16 commented Dec 4, 2019

Oh, first time dealing with private anything in Python, actually. Thanks for letting me know.

@J-A16
Copy link
Contributor

J-A16 commented Dec 4, 2019

I thought since it was in a private file, maybe it was.

Do you think I need to change my code at all?

@jnothman
Copy link
Member

jnothman commented Dec 4, 2019

If you have code, please submit a pull request for review.

I agree with @pallashadow that it looks like the loss calculation should also be weighted... but we ideally drive this from tests. See #15657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Well-defined and straightforward way to resolve help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants