From 61d3170ec54a92b87f853f802e1b17027a127f92 Mon Sep 17 00:00:00 2001 From: jcusick13 Date: Sun, 22 Dec 2019 15:19:53 -0500 Subject: [PATCH 1/2] Apply sample weights to loss fn --- sklearn/linear_model/_ransac.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sklearn/linear_model/_ransac.py b/sklearn/linear_model/_ransac.py index 40ebb3a08420f..c94c8e7b907a0 100644 --- a/sklearn/linear_model/_ransac.py +++ b/sklearn/linear_model/_ransac.py @@ -373,7 +373,10 @@ def fit(self, X, y, sample_weight=None): # residuals of all data for current random sample model y_pred = base_estimator.predict(X) - residuals_subset = loss_function(y, y_pred) + if sample_weight is None: + residuals_subset = loss_function(y, y_pred) + else: + residuals_subset = loss_function(y, y_pred) * sample_weight # classify data into inliers and outliers inlier_mask_subset = residuals_subset < residual_threshold From 1b8033794e0f93637994c45433daeacd751f1bac Mon Sep 17 00:00:00 2001 From: jcusick13 Date: Thu, 26 Dec 2019 12:55:42 -0500 Subject: [PATCH 2/2] Use internal check sample weight fn --- sklearn/linear_model/_ransac.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sklearn/linear_model/_ransac.py b/sklearn/linear_model/_ransac.py index c94c8e7b907a0..a5511b49e1ba1 100644 --- a/sklearn/linear_model/_ransac.py +++ b/sklearn/linear_model/_ransac.py @@ -373,10 +373,8 @@ def fit(self, X, y, sample_weight=None): # residuals of all data for current random sample model y_pred = base_estimator.predict(X) - if sample_weight is None: - residuals_subset = loss_function(y, y_pred) - else: - residuals_subset = loss_function(y, y_pred) * sample_weight + sample_weight = _check_sample_weight(sample_weight, X) + residuals_subset = loss_function(y, y_pred) * sample_weight # classify data into inliers and outliers inlier_mask_subset = residuals_subset < residual_threshold