Esempio n. 1
0
    def fit(self, source_df, y, experiment: ExperimentBackend) -> pd.DataFrame:
        X, y = source_df.values, y
        default_params = self.generate_default_model_parameter(
            X, y, experiment)
        with experiment.mark_time(prefix='fit'):
            models, oof = self.run_oof_train(X,
                                             y,
                                             default_params,
                                             experiment=experiment)

        self._fitted_models = models
        experiment.mark('n_cv', len(models))
        return pd.DataFrame(oof)
Esempio n. 2
0
    def _fit_model(self, X: np.ndarray, y: np.ndarray, default_params: dict,
                   validation_set: tuple, indexes_set: tuple,
                   experiment: ExperimentBackend) -> PrePostProcessModel:
        """
        fit a new model class.

        Notes:
            in model_params, add scaling parameters for target / input (ex. target_scaling = False)

        Args:
            X: training feature. numpy array. shape = (n_train, n_features)
            y: target. shape = (n_train, n_classes)
            default_params: parameters pass into model constructor
            validation_set:
            indexes_set:
            experiment:

        Returns:
            trained model
        """
        model_params = self.get_model_params_on_each_fold(
            default_params, indexes_set)
        model = self.create_model(model_params)

        # MEMO: validation data are not transform so validation score is invalid (in boosting model, eval_set)
        model._before_fit(X, y)
        x_valid, y_valid = validation_set
        x_valid = model.input_transformer.transform(x_valid)
        y_valid = model.target_transformer.transform(y_valid)

        fit_params = self.get_fit_params_on_each_fold(model_params,
                                                      training_set=(X, y),
                                                      validation_set=(x_valid,
                                                                      y_valid),
                                                      indexes_set=indexes_set,
                                                      experiment=experiment)
        if fit_params is None:
            fit_params = {}

        with experiment.mark_time('fit'):
            model.fit(X, y, **fit_params)
        return model