Skip to content

Commit

Permalink
adding sample weights for XGBRegressor (was this forgotten?) (#1874)
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsan authored and tqchen committed Jan 21, 2017
1 parent 2b5b96d commit 036ee55
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python-package/xgboost/sklearn.py
Expand Up @@ -182,7 +182,7 @@ def get_xgb_params(self):
xgb_params.pop('nthread', None)
return xgb_params

def fit(self, X, y, eval_set=None, eval_metric=None,
def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None,
early_stopping_rounds=None, verbose=True):
# pylint: disable=missing-docstring,invalid-name,attribute-defined-outside-init
"""
Expand All @@ -194,6 +194,8 @@ def fit(self, X, y, eval_set=None, eval_metric=None,
Feature matrix
y : array_like
Labels
sample_weight : array_like
instance weights
eval_set : list, optional
A list of (X, y) tuple pairs to use as a validation set for
early-stopping
Expand All @@ -219,7 +221,10 @@ def fit(self, X, y, eval_set=None, eval_metric=None,
If `verbose` and an evaluation set is used, writes the evaluation
metric measured on the validation set to stderr.
"""
trainDmatrix = DMatrix(X, label=y, missing=self.missing)
if sample_weight is not None:
trainDmatrix = DMatrix(X, label=y, weight=sample_weight, missing=self.missing)
else:
trainDmatrix = DMatrix(X, label=y, missing=self.missing)

evals_result = {}
if eval_set is not None:
Expand Down

0 comments on commit 036ee55

Please sign in to comment.