Exemplo n.º 1
0
 def fit(self, X, y, *args, parallel=None, **kwargs):
     """
     :param X: n_samples X n_models
     :param y: n_samples
     :param args: placeholder
     :param kwargs: placeholder
     """
     data = NpDataset(X, y=y)
     self.__val_preds = np.zeros(y.shape)
     if self.__val_preds.ndim != 1:
         logging.error(
             "Shape of validation predictions is incorrect: {}".format(
                 self.__val_preds.shape))
     model_and_preds = parallel(
         delayed(fit_fold_model)(self.models[i], train_data.x, train_data.y,
                                 val_data.x, val_data.y, *args, **kwargs)
         for i, (train_data,
                 val_data) in enumerate(data.kfold(self.k, shuffle=False)))
     cur_sample_ind = 0
     for i, (model, val_preds) in enumerate(model_and_preds):
         self.models[i] = model
         self.__val_preds[cur_sample_ind:cur_sample_ind +
                          val_preds.shape[0]] = val_preds
         cur_sample_ind += val_preds.shape[0]
     assert cur_sample_ind == X.shape[0]
Exemplo n.º 2
0
 def roc_auc(self, X, y, *args, **kwargs):
     data = NpDataset(X, y=y)
     score = 0.
     for i, (train_data,
             val_data) in enumerate(data.kfold(self.k, shuffle=False)):
         score = score + self.models[i].roc_auc(val_data.x, val_data.y, *
                                                args, **kwargs)
     return score / self.k