Example #1
0
 def _setup_metrics(self):
     self.metric_functions[LOSS] = self.eval_loss_function
     self.metric_functions[ERROR] = ErrorScore(name='metric_error')
     self.metric_functions[MEAN_SQUARED_ERROR] = MeanSquaredErrorMetric(
         name='metric_mse')
     self.metric_functions[MEAN_ABSOLUTE_ERROR] = MeanAbsoluteErrorMetric(
         name='metric_mae')
     self.metric_functions[R2] = R2Score(name='metric_r2')
Example #2
0
 def _setup_metrics(self):
     self.metric_functions = {}  # needed to shadow class variable
     self.metric_functions[LOSS] = self.eval_loss_function
     self.metric_functions[MEAN_SQUARED_ERROR] = MeanSquaredErrorMetric(
         name='metric_mse'
     )
     self.metric_functions[MEAN_ABSOLUTE_ERROR] = MeanAbsoluteErrorMetric(
         name='metric_mae'
     )
     self.metric_functions[R2] = R2Score(name='metric_r2')
Example #3
0
 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')
     else:
         self.metric_functions[LOSS] = MAEMetric(name='eval_loss')
     self.metric_functions[ERROR] = ErrorScore(name='metric_error')
     self.metric_functions[MEAN_SQUARED_ERROR] = MeanSquaredErrorMetric(
         name='metric_mse')
     self.metric_functions[MEAN_ABSOLUTE_ERROR] = MeanAbsoluteErrorMetric(
         name='metric_mae')
     self.metric_functions[R2] = R2Score(name='metric_r2')
Example #4
0
    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")
X_train, X_test, y_train, y_test = train_test_split(diabetes_data,
                                                    diabetes_target,
                                                    test_size=.1)

model = Sequential([
    Dense(units=128, activation=relu, input_shape=(X_train.shape[1], )),
    Dense(units=64, activation=relu),
    Dense(units=64, activation=relu),
    Dense(units=64, activation=relu),
    Dense(units=1),
])

model.compile(loss=MeanSquaredError(),
              optimizer=Adam(),
              metrics=[MeanAbsoluteErrorMetric(),
                       MeanSquaredErrorMetric()])

# Learning rate scheduler


def lr_schedule(epoch, lr):
    if epoch % 2 == 0:
        return lr
    else:
        return lr + epoch / 1000


# history = model.fit(X_train,
#                     y_train,
#                     epochs=100,
#                     validation_split=.15,