<commit_before>import sklearn

from onl.nok.sklearn.classifier.Classifier import Classifier


class AdaBoostClassifier(Classifier):


    @staticmethod
    def get_supported_methods():
        return [
            'predict'
        ]


    @staticmethod
    def is_supported_method(method_name):
        support = method_name in AdaBoostClassifier.get_supported_methods()
        if not support:
            raise ValueError('The classifier does not support the given method.')
        return support


    @staticmethod
    def port(model, method_name='predict', class_name="Tmp"):
        if AdaBoostClassifier.is_supported_method(method_name):
            if method_name == 'predict':
                return AdaBoostClassifier.predict(model, class_name=class_name)
        return False


    @staticmethod
    def predict(model, class_name='Tmp'):
        method_name = 'predict'

        if model.algorithm not in ('SAMME.R'):
            # raise ValueError("algorithm %s is not supported" % model.algorithm)
            return False

        # Check type of base estimators:
        if not isinstance(model.base_estimator, sklearn.tree.tree.DecisionTreeClassifier):
            return False

        # Check number of base estimators:
        if not model.n_estimators > 0:
            return False

        # TODO: Use local variables
        # n_features = model.estimators_[0].n_features_
        # n_classes = model.n_classes_

        function_names = []
        functions = []<commit_msg>Add exceptions<commit_after>import sklearn

from onl.nok.sklearn.classifier.Classifier import Classifier


class AdaBoostClassifier(Classifier):


    @staticmethod
    def get_supported_methods():
        return [
            'predict'
        ]


    @staticmethod
    def is_supported_method(method_name):
        support = method_name in AdaBoostClassifier.get_supported_methods()
        if not support:
            raise ValueError('The classifier does not support the given method.')
        return support


    @staticmethod
    def port(model, method_name='predict', class_name="Tmp"):
        if AdaBoostClassifier.is_supported_method(method_name):
            if method_name == 'predict':
                return AdaBoostClassifier.predict(model, class_name=class_name)
        return False


    @staticmethod
    def predict(model, class_name='Tmp'):
        method_name = 'predict'

        # Check the used algorithm type:
        if model.algorithm not in ('SAMME.R'):
            raise ValueError('The classifier does not support the given algorithm %s.', model.algorithm)

        # Check type of base estimators:
        if not isinstance(model.base_estimator, sklearn.tree.tree.DecisionTreeClassifier):
            raise ValueError('The classifier does not support the given base estimator %s.', model.base_estimator)

        # Check number of base estimators:
        if not model.n_estimators > 0:
            raise ValueError('The classifier has not any base estimators.')

        # TODO: Use local variables
        # n_features = model.estimators_[0].n_features_
        # n_classes = model.n_classes_

        function_names = []
        functions = []
{'fraction_non_alphanumeric': 0.07769738911607424, 'fraction_numerical': 0.0012582573136206354, 'mean_word_length': 2.5972850678733033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519412', 'n_tokens_mistral': 881, 'n_tokens_neox': 835, 'n_words': 226}