Exemplo n.º 1
0
 def _set_ml_task(self, y):
     """ Set and validate the ML task.
     
     If ML task is not set, it trys to guess ML task based on count of unique values in the target. 
     Then it performs validation.
     """
     # if not set, guess
     if self._ml_task is None:
         target_unique_cnt = len(np.unique(y[~pd.isnull(y)]))
         if target_unique_cnt == 2:
             self._ml_task = BINARY_CLASSIFICATION
         elif target_unique_cnt <= 20:
             self._ml_task = MULTICLASS_CLASSIFICATION
         else:
             self._ml_task = REGRESSION
     # validation
     if self._ml_task not in AlgorithmsRegistry.get_supported_ml_tasks():
         raise Exception("Unknow Machine Learning task {}."
                         " Supported tasks are: {}".format(
                             self._ml_task,
                             AlgorithmsRegistry.get_supported_ml_tasks()))
     if self._ml_task == REGRESSION:
         if "stratify" in self._validation:
             del self._validation["stratify"]
     logger.info("AutoML task to be solved: {}".format(self._ml_task))
     print(f"AutoML task to be solved: { self._ml_task}")
Exemplo n.º 2
0
    def _validate_ml_task(self):
        """ Validates ml_task parameter"""
        if isinstance(self.ml_task, str) and self.ml_task == "auto":
            return

        if self.ml_task not in AlgorithmsRegistry.get_supported_ml_tasks():
            raise ValueError(
                f"Expected 'ml_task' to be {' or '.join(AlgorithmsRegistry.get_supported_ml_tasks())}, got '{self.ml_task}''"
            )