Skip to content

Commit

Permalink
added sample_weight to QRF
Browse files Browse the repository at this point in the history
  • Loading branch information
nepslor committed Sep 25, 2024
1 parent a2253eb commit 2a0cb81
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyforecaster/forecasting_models/randomforests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ def __init__(self, n_estimators=100, q_vect=None, val_ratio=None, nodes_at_step=
"ccp_alpha":ccp_alpha
}

def _fit(self, i, x, y):
def _fit(self, i, x, y, sample_weight=None):
x_i = self.dataset_at_stepahead(x, i, self.metadata_features, formatter=self.formatter,
logger=self.logger, method='periodic', keep_last_n_lags=self.keep_last_n_lags,
keep_last_seconds=self.keep_last_seconds,
tol_period=self.tol_period)
model = RandomForestQuantileRegressor(**self.qrf_pars).fit(x_i, y.iloc[:, i])
model = RandomForestQuantileRegressor(**self.qrf_pars).fit(x_i, y.iloc[:, i], sample_weight=sample_weight)
return model

@encode_categorical
def fit(self, x, y):
def fit(self, x, y, sample_weight=None):
x, y, x_val, y_val = self.train_val_split(x, y)
if self.parallel:
with concurrent.futures.ProcessPoolExecutor(max_workers=self.max_parallel_workers) as executor:
self.models = [i for i in tqdm(executor.map(partial(self._fit, x=x, y=y), range(self.n_single)),total=self.n_single)]
self.models = [i for i in tqdm(executor.map(partial(self._fit, x=x, y=y, sample_weight=sample_weight), range(self.n_single)),total=self.n_single)]
else:
for i in tqdm(range(self.n_single)):
model = self._fit(i, x, y)
model = self._fit(i, x, y, sample_weight=sample_weight)
self.models.append(model)

n_sa = y.shape[1]
Expand Down

0 comments on commit 2a0cb81

Please sign in to comment.