Ejemplo n.º 1
0
def test_data_split_identical():
    X_, y_ = X[:40], np.array([0] * 20 + [1] * 20)
    for md in [
            model.SVM(),
            model.KNN(),
            model.XGBoost(),
            model.LinearModel(),
            model.DecisionTree()
    ]:
        a = evaluation.estimate(md, X_train, X_test, y_train, y_test)
        b = evaluation.estimate(md, X_train, X_test, y_train, y_test)
        assert a == b
        a = evaluation.cross_validation(md,
                                        X_,
                                        y_,
                                        scoring='both',
                                        n_splits=2,
                                        n_jobs=1)
        b = evaluation.cross_validation(md,
                                        X_,
                                        y_,
                                        scoring='both',
                                        n_splits=2,
                                        n_jobs=1)
        assert np.all(a['f1'] == b['f1'])
        assert np.all(a['roc_auc'] == b['roc_auc'])
Ejemplo n.º 2
0
def test_estimate():
    for md in [
            model.SVM(),
            model.KNN(),
            model.XGBoost(),
            model.LinearModel(),
            model.DecisionTree()
    ]:
        evaluation.estimate(md, X_train, X_test, y_train, y_test)
Ejemplo n.º 3
0
def test_clone():
    models = [
        model.LinearModel(),
        model.SVM(),
        model.DecisionTree(),
        model.MultiClassesLearner('KNN', {'n_neighbors': 1}),
        model.KNN(),
        model.XGBoost(),
    ]
    from sklearn.base import clone
    for md in models:
        clone(md)
Ejemplo n.º 4
0
def test_cross_validation():
    for md in [
            model.SVM(),
            model.MultiClassesLearner('KNN', {'n_neighbors': 1}),
            model.KNN(),
            model.XGBoost(),
            model.LinearModel(),
            model.DecisionTree(),
    ]:
        try:
            evaluation.cross_validation(md,
                                        X,
                                        y,
                                        scoring='both',
                                        n_jobs=1,
                                        n_splits=2)
        except Exception as e:
            print(md.__class__)
            raise e
Ejemplo n.º 5
0
def test_get_params():
    models = [
        model.LinearModel(),
        model.SVM(),
        model.DecisionTree(),
        model.MultiClassesLearner('KNN', {'n_neighbors': 1}),
        model.KNN(),
        model.XGBoost(),
    ]

    for md in models:
        params = md.get_params()
        try:
            assert 'normalizer_name' in params
            assert 'sample_method' in params
            if not isinstance(md, model.KNN):
                assert 'balanced_learning' in params
        except AssertionError as e:
            print(params)
            print(md.__class__)
            raise e
Ejemplo n.º 6
0
def test_xgboost():
    m = model.XGBoost(n_jobs=1)
    print(evaluation.cross_validation(m, X, y, n_jobs=1))