def fit(self, X, y): """Fit.""" X = X[(self.mdlNr*5 % self.subsample_data)::self.subsample_data] y = y[(self.mdlNr*5 % self.subsample_data)::self.subsample_data] if self.applyPreds: if self.jump is not None: X = delay_preds(X, delay=self.delay/self.subsample_data, skip=self.skip/self.subsample_data, jump=self.jump/self.subsample_data) else: X = delay_preds(X, delay=self.delay/self.subsample_data, skip=self.skip/self.subsample_data) self.clf = [] widgets = ['Training : ', Percentage(), ' ', Bar(marker=RotatingMarker()), ' ', ETA(), ' '] pbar = ProgressBar(widgets=widgets, maxval=6) pbar.start() # training separate models for each event for col in range(6): self.clf.append(xgb.XGBClassifier(n_estimators=self.n_estimators, max_depth=self.max_depth, subsample=self.subsample, nthread=self.nthread)) self.clf[col].fit(X, y[:, col]) pbar.update(col)
def predict_proba(self, X): """Predict probability.""" if self.applyPreds: p = np.zeros((X.shape[0],6)) for part in range(self.partsTest): start = part*X.shape[0]//self.partsTest-self.delay*(part>0) stop = (part+1)*X.shape[0]//self.partsTest X_delayed = delay_preds(X[slice(start,stop)], delay=self.delay, skip=self.skip, jump=self.jump)[self.delay*(part>0):] start += self.delay*(part>0) p[slice(start,stop)] += self._predict_proba(X_delayed) X_delayed = None return p else: return self._predict_proba(X)