def validation_error(self, learner, criterion, **other_params):
     error = 0
     try:
         for i in range(self.num_folds):
             predictor = learner(self,
                                 train=list(self.fold_complement(i)),
                                 **other_params).learn()
             error += sum(
                 error_example(predictor(example), self.target(example),
                               criterion) for example in self.fold(i))
     except ValueError:
         return float("inf")  #infinity
     return error / len(self.data)
Beispiel #2
0
def training_error(dataset, data_subset, to_optimize):
    """returns training error for dataset on to_optimize.
    This assumes that we choose the best value for the optimization
    criteria for dataset according to point_prediction
    """
    select_dict = {"sum-of-squares":"mean", "sum_absolute":"median",
                       "logloss":"Laplace"}  # arbitrary mapping. Perhaps wrong.
    selection = select_dict[to_optimize]
    predictor = point_prediction(dataset.target, data_subset, selection=selection)
    error = sum(error_example(predictor(example),
                               dataset.target(example),
                               to_optimize)
                 for example in data_subset)
    return error