def run_test_predict(self):
     self.options.code_dir = self.options.output
     self.options.output = os.devnull
     __target_temp = None
     if self.options.target:
         __tempfile = NamedTemporaryFile()
         df = pd.read_csv(self.options.input)
         if self.target_type == TargetType.TRANSFORM:
             target_df = df[self.options.target]
             __target_temp = NamedTemporaryFile()
             target_df.to_csv(__target_temp.name, index=False)
         df = df.drop(self.options.target, axis=1)
         # convert to R-friendly missing fields
         if self._get_fit_run_language() == RunLanguage.R:
             df = handle_missing_colnames(df)
         df.to_csv(__tempfile.name, index=False)
         self.options.input = __tempfile.name
     if self.target_type == TargetType.TRANSFORM:
         CMRunTests(self.options, self.run_mode,
                    self.target_type).check_transform_server(__target_temp)
     else:
         try:
             CMRunTests(self.options, self.run_mode,
                        self.target_type).check_prediction_side_effects()
         except DrumPredException as e:
             self.logger.warning(e)
Beispiel #2
0
 def run_test_predict(self):
     self.run_mode = RunMode.SCORE
     self.options.code_dir = self.options.output
     self.options.output = os.devnull
     if self.options.target:
         __tempfile = NamedTemporaryFile()
         df = pd.read_csv(self.options.input)
         df = df.drop(self.options.target, axis=1)
         # convert to R-friendly missing fields
         if self._get_fit_run_language() == RunLanguage.R:
             df = handle_missing_colnames(df)
         df.to_csv(__tempfile.name, index=False)
         self.options.input = __tempfile.name
     self._run_fit_and_predictions_pipelines_in_mlpiper()
Beispiel #3
0
    def _add_weights_cmd(weights, input_csv, r_fit=False):
        df = pd.read_csv(input_csv)
        colname = "some-colname"
        weights_data = pd.Series(np.random.randint(1, 3, len(df)))
        __keep_this_around = NamedTemporaryFile("w")
        if weights == WEIGHTS_ARGS:
            df[colname] = weights_data
            if r_fit:
                df = handle_missing_colnames(df)
            df.to_csv(__keep_this_around.name)
            return " --row-weights " + colname, __keep_this_around.name, __keep_this_around
        elif weights == WEIGHTS_CSV:
            weights_data.to_csv(__keep_this_around.name)
            return " --row-weights-csv " + __keep_this_around.name, input_csv, __keep_this_around

        return "", input_csv, __keep_this_around