Beispiel #1
0
def print_models_overview():
    print(f"\nIgel's supported models overview: \n")
    reg_algs = list(models_dict.get("regression").keys())
    clf_algs = list(models_dict.get("classification").keys())
    cluster_algs = list(models_dict.get("clustering").keys())
    df_algs = (pd.DataFrame.from_dict(
        {
            "regression": reg_algs,
            "classification": clf_algs,
            "clustering": cluster_algs,
        },
        orient="index",
    ).transpose().fillna("----"))

    df = tableize(df_algs)
    print(df)
Beispiel #2
0
def show_model_info(model_name: str, model_type: str):
    if not model_name:
        print(f"Please enter a supported model")
        print_models_overview()
    else:
        if not model_type:
            print(
                f"Please enter a type argument to get help on the chosen model\n"
                f"type can be whether regression, classification or clustering \n"
            )
            print_models_overview()
            return
        if model_type not in ("regression", "classification", "clustering"):
            raise Exception(
                f"{model_type} is not supported! \n"
                f"model_type need to be regression, classification or clustering"
            )

        models = models_dict.get(model_type)
        model_data = models.get(model_name)
        model, link, *cv_class = model_data.values()
        print(
            f"model type: {model_type} \n"
            f"model name: {model_name} \n"
            f"sklearn model class: {model.__name__} \n"
            f"{'-' * 60}\n"
            f"You can click the link below to know more about the optional arguments\n"
            f"that you can use with your chosen model ({model_name}).\n"
            f"You can provide these optional arguments in the yaml file if you want to use them.\n"
            f"link:\n{link} \n")
Beispiel #3
0
    def _create_model(self, **kwargs):
        """
        fetch a model depending on the provided type and algorithm by the user and return it
        @return: class of the chosen model
        """
        model_type: str = self.model_props.get('type')
        model_algorithm: str = self.model_props.get('algorithm')
        model_args = None
        if not model_type or not model_algorithm:
            raise Exception(f"model_type and algorithm cannot be None")
        algorithms: dict = models_dict.get(
            model_type)  # extract all algorithms as a dictionary
        model = algorithms.get(
            model_algorithm)  # extract model class depending on the algorithm
        logger.info(
            f"Solving a {model_type} problem using ===> {model_algorithm}")
        if not model:
            raise Exception("Model not found in the algorithms list")
        else:
            model_props_args = self.model_props.get('arguments', None)
            if model_props_args and type(model_props_args) == dict:
                model_args = model_props_args
            elif not model_props_args or model_props_args.lower() == "default":
                model_args = None

            model_class = model.get('class')
            logger.info(f"model arguments: \n"
                        f"{self.model_props.get('arguments')}")
            model = model_class(**kwargs) if not model_args else model_class(
                **model_args)
            return model, model_args
Beispiel #4
0
    def _create_model(self, **kwargs):
        """
        fetch a model depending on the provided type and algorithm by the user and return it
        @return: class of the chosen model
        """
        model_type: str = self.model_props.get("type")
        model_algorithm: str = self.model_props.get("algorithm")
        use_cv = self.model_props.get("use_cv_estimator", None)

        model_args = None
        if not model_type or not model_algorithm:
            raise Exception(f"model_type and algorithm cannot be None")
        algorithms: dict = models_dict.get(
            model_type
        )  # extract all algorithms as a dictionary
        model = algorithms.get(
            model_algorithm
        )  # extract model class depending on the algorithm
        logger.info(
            f"Solving a {model_type} problem using ===> {model_algorithm}"
        )
        if not model:
            raise Exception("Model not found in the algorithms list")
        else:
            model_props_args = self.model_props.get("arguments", None)
            if model_props_args and type(model_props_args) == dict:
                model_args = model_props_args
            elif not model_props_args or model_props_args.lower() == "default":
                model_args = None

            if use_cv:
                model_class = model.get("cv_class", None)
                if model_class:
                    logger.info(
                        f"cross validation estimator detected. "
                        f"Switch to the CV version of the {model_algorithm} algorithm"
                    )
                else:
                    logger.info(
                        f"No CV class found for the {model_algorithm} algorithm"
                    )
            else:
                model_class = model.get("class")
            logger.info(
                f"model arguments: \n" f"{self.model_props.get('arguments')}"
            )
            model = (
                model_class(**kwargs)
                if not model_args
                else model_class(**model_args)
            )
            return model, model_args
Beispiel #5
0
 def _create_model(self):
     """
     fetch a model depending on the provided type and algorithm by the user and return it
     @return: class of the chosen model
     """
     model_type = self.model_props.get('type')
     model_algorithm = self.model_props.get('algorithm')
     if not model_type or not model_algorithm:
         raise Exception(f"model_type and algorithm cannot be None")
     algorithms = models_dict.get(model_type)  # extract all algorithms as a dictionary
     model = algorithms.get(model_algorithm)  # extract model class depending on the algorithm
     logger.info(f"Solving a {model_type} problem using ===> {model_algorithm}")
     if not model:
         raise Exception("Model not found in the algorithms list")
     else:
         return model