def _setup_loss(self): if self.loss[TYPE] == 'mean_squared_error': self.train_loss_function = MSELoss() self.eval_loss_function = MSEMetric(name='eval_loss') elif self.loss[TYPE] == 'mean_absolute_error': self.train_loss_function = MAELoss() self.eval_loss_function = MAEMetric(name='eval_loss') elif self.loss[TYPE] == SOFTMAX_CROSS_ENTROPY: self.train_loss_function = SoftmaxCrossEntropyLoss( num_classes=self.vector_size, feature_loss=self.loss, name='train_loss') self.eval_loss_function = SoftmaxCrossEntropyMetric( num_classes=self.vector_size, feature_loss=self.loss, name='eval_loss') else: raise ValueError('Unsupported loss type {}'.format( self.loss[TYPE]))
def _setup_metrics(self): self.metric_functions = {} # needed to shadow class variable if self.loss[TYPE] == "mean_squared_error": self.metric_functions[LOSS] = MSEMetric(name="eval_loss") elif self.loss[TYPE] == "mean_absolute_error": self.metric_functions[LOSS] = MAEMetric(name="eval_loss") elif self.loss[TYPE] == "root_mean_squared_error": self.metric_functions[LOSS] = RMSEMetric(name="eval_loss") elif self.loss[TYPE] == "root_mean_squared_percentage_error": self.metric_functions[LOSS] = RMSPEMetric(name="eval_loss") self.metric_functions[MEAN_SQUARED_ERROR] = MeanSquaredErrorMetric( name="metric_mse" ) self.metric_functions[MEAN_ABSOLUTE_ERROR] = MeanAbsoluteErrorMetric( name="metric_mae" ) self.metric_functions[ ROOT_MEAN_SQUARED_ERROR ] = RootMeanSquaredErrorMetric(name="metric_rmse") self.metric_functions[ ROOT_MEAN_SQUARED_PERCENTAGE_ERROR ] = RMSPEMetric(name="metric_rmspe") self.metric_functions[R2] = R2Score(name="metric_r2")