Exemplo n.º 1
0
def _choose_classifier(job: Job):
    method, config = get_method_config(job)
    config.pop('classification_method', None)
    logger.info("Using method {} with config {}".format(method, config))
    if method == ClassificationMethods.KNN.value:
        classifier = KNeighborsClassifier(**config)
    elif method == ClassificationMethods.RANDOM_FOREST.value:
        classifier = RandomForestClassifier(**config)
    elif method == ClassificationMethods.DECISION_TREE.value:
        classifier = DecisionTreeClassifier(**config)
    elif method == ClassificationMethods.XGBOOST.value:
        classifier = XGBClassifier(**config)
    elif method == ClassificationMethods.MULTINOMIAL_NAIVE_BAYES.value:
        classifier = MultinomialNB(**config)
    elif method == ClassificationMethods.ADAPTIVE_TREE.value:
        classifier = HAT(**config)
    elif method == ClassificationMethods.HOEFFDING_TREE.value:
        classifier = HoeffdingTree(**config)
    elif method == ClassificationMethods.SGDCLASSIFIER.value:
        classifier = SGDClassifier(**config)
    elif method == ClassificationMethods.PERCEPTRON.value:
        classifier = Perceptron(**config)
    elif method == ClassificationMethods.NN.value:
        config['encoding'] = job.encoding.value_encoding
        config['is_binary_classifier'] = _check_is_binary_classifier(
            job.labelling.type)
        classifier = NNClassifier(**config)
    else:
        raise ValueError("Unexpected classification method {}".format(method))
    return classifier
Exemplo n.º 2
0
def _choose_classifier(job: Job):
    if job.type == JobTypes.UPDATE.value:
        classifier = _load_model(job.incremental_train)
        # TODO: check if this instruction still makes sense
        # are we updating a predictive_model with its own methods?
        assert classifier[0].__class__.__name__ == job.method
    else:
        method, config = get_method_config(job)
        config.pop('classification_method', None)
        print("Using method {} with config {}".format(method, config))
        if method == ClassificationMethods.KNN.value:
            classifier = KNeighborsClassifier(**config)
        elif method == ClassificationMethods.RANDOM_FOREST.value:
            classifier = RandomForestClassifier(**config)
        elif method == ClassificationMethods.DECISION_TREE.value:
            classifier = DecisionTreeClassifier(**config)
        elif method == ClassificationMethods.XGBOOST.value:
            classifier = XGBClassifier(**config)
        elif method == ClassificationMethods.MULTINOMIAL_NAIVE_BAYES.value:
            classifier = MultinomialNB(**config)
        elif method == ClassificationMethods.ADAPTIVE_TREE.value:
            classifier = HAT(**config)
        elif method == ClassificationMethods.HOEFFDING_TREE.value:
            classifier = HoeffdingTree(**config)
        elif method == ClassificationMethods.SGDCLASSIFIER.value:
            classifier = SGDClassifier(**config)
        elif method == ClassificationMethods.PERCEPTRON.value:
            classifier = Perceptron(**config)
        elif method == ClassificationMethods.NN.value:
            config['encoding'] = job.encoding.value_encoding
            config['is_binary_classifier'] = _check_is_binary_classifier(job.labelling.type)
            classifier = NNClassifier(**config)
        else:
            raise ValueError("Unexpected classification method {}".format(method))
    return classifier
Exemplo n.º 3
0
def _choose_time_series_predictor(job: Job) -> TimeSeriesPredictorMixin:
    method, config = get_method_config(job)
    config.pop('time_series_prediction_method', None)
    print("Using method {} with config {}".format(method, config))
    if method == TimeSeriesPredictionMethods.RNN.value:
        config['encoding'] = job.encoding.value_encoding
        time_series_predictor = RNNTimeSeriesPredictor(**config)
    else:
        raise ValueError("Unexpected time series prediction method {}".format(method))
    return time_series_predictor
    def test_get_method_config(self):
        job = create_test_job(
            predictive_model=create_test_predictive_model(
                predictive_model=PredictiveModels.CLASSIFICATION.value,
                prediction_method=ClassificationMethods.RANDOM_FOREST.value
            )
        )

        method, config = get_method_config(job)

        self.assertEqual(ClassificationMethods.RANDOM_FOREST.value, method)
        self.assertEqual({
            'max_depth': None,
            'max_features': 'auto',
            'n_estimators': 10,
        }, config)
Exemplo n.º 5
0
def _choose_regressor(job: Job) -> RegressorMixin:
    method, config = get_method_config(job)
    config.pop('regression_method', None)
    print("Using method {} with config {}".format(method, config))
    if method == RegressionMethods.LINEAR.value:
        regressor = LinearRegression(**config)
    elif method == RegressionMethods.RANDOM_FOREST.value:
        regressor = RandomForestRegressor(**config)
    elif method == RegressionMethods.LASSO.value:
        regressor = Lasso(**config)
    elif method == RegressionMethods.XGBOOST.value:
        regressor = XGBRegressor(**config)
    elif method == RegressionMethods.NN.value:
        config['encoding'] = job.encoding.value_encoding
        regressor = NNRegressor(**config)
    else:
        raise ValueError("Unexpected regression method {}".format(method))
    return regressor