Example #1
0
    def fit_trial_split(self, trial_split: TrialSplit,
                        train_data_container: DataContainer,
                        validation_data_container: DataContainer,
                        context: ExecutionContext) -> TrialSplit:
        """
        Train pipeline using the training data container.
        Track training, and validation metrics for each epoch.

        :param train_data_container: train data container
        :param validation_data_container: validation data container
        :param trial_split: trial to execute
        :param context: execution context

        :return: executed trial
        """

        for i in range(self.epochs):
            context.logger.info('epoch {}/{}'.format(i + 1, self.epochs))
            trial_split = trial_split.fit_trial_split(
                train_data_container.copy(),
                context.copy().set_execution_phase(ExecutionPhase.TRAIN))
            y_pred_train = trial_split.predict_with_pipeline(
                train_data_container.copy(),
                context.copy().set_execution_phase(ExecutionPhase.VALIDATION))
            y_pred_val = trial_split.predict_with_pipeline(
                validation_data_container.copy(),
                context.copy().set_execution_phase(ExecutionPhase.VALIDATION))

            if self.callbacks.call(
                    trial_split=trial_split,
                    epoch_number=i,
                    total_epochs=self.epochs,
                    input_train=train_data_container,
                    pred_train=y_pred_train,
                    input_val=validation_data_container,
                    pred_val=y_pred_val,
                    context=context.copy().set_execution_phase(
                        ExecutionPhase.VALIDATION),
                    is_finished_and_fitted=False,
            ):
                break
            # Saves the metrics
            trial_split.save_parent_trial()

        return trial_split
Example #2
0
    def fit_trial_split(
            self,
            trial_split: TrialSplit,
            train_data_container: DataContainer,
            validation_data_container: DataContainer,
            context: ExecutionContext
    ) -> TrialSplit:
        """
        Train pipeline using the training data container.
        Track training, and validation metrics for each epoch.

        :param train_data_container: train data container
        :param validation_data_container: validation data container
        :param trial_split: trial to execute
        :param context: execution context

        :return: executed trial
        """
        early_stopping = False

        for i in range(self.epochs):
            self.print_func('\nepoch {}/{}'.format(i + 1, self.epochs))
            trial_split = trial_split.fit_trial_split(train_data_container.copy(), context)
            y_pred_train = trial_split.predict_with_pipeline(train_data_container.copy(), context)
            y_pred_val = trial_split.predict_with_pipeline(validation_data_container.copy(), context)

            if self.callbacks.call(
                    trial=trial_split,
                    epoch_number=i,
                    total_epochs=self.epochs,
                    input_train=train_data_container,
                    pred_train=y_pred_train,
                    input_val=validation_data_container,
                    pred_val=y_pred_val,
                    is_finished_and_fitted=early_stopping
            ):
                break

        return trial_split