예제 #1
0
def adaptive_test(X_train,
                  X_test,
                  y_train,
                  y_test,
                  n_iter=100,
                  n_jobs=4,
                  cv=3):
    classifier = tree.DecisionTreeClassifier()

    auc = make_scorer(roc_auc_score)

    rand_list = {
        "max_leaf_nodes": [2, 3, 4, 5],
        "max_features": stats.uniform(0.5, 0.25)
    }

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=2017,
                                     scoring=auc)
    rand_search.fit(X_train, y_train)

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #2
0
def adaptive_test(X_train,
                  X_test,
                  y_train,
                  y_test,
                  n_iter=100,
                  n_jobs=4,
                  cv=3):
    classifier = neighbors.KNeighborsClassifier()

    auc = make_scorer(roc_auc_score)

    rand_list = {
        "n_neighbors": [4, 5, 6, 7, 8, 9],
        "leaf_size": [25, 30, 35],
        "algorithm": ['ball_tree', 'kd_tree', 'brute'],
        "p": [1, 2]
    }

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=2017,
                                     scoring=auc)
    rand_search.fit(X_train, y_train)

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #3
0
def adaptive_test(X_train,
                  X_test,
                  y_train,
                  y_test,
                  n_iter=100,
                  n_jobs=4,
                  cv=3):
    cat_features = [0, 1, 6]

    classifier = CatBoost()
    auc = make_scorer(roc_auc_score)

    rand_list = {
        'iterations': [1, 2, 5, 10, 20, 50, 100, 200],
        'depth': [*range(1, 11)],
        'learning_rate':
        [.005, .01, .02, .05, .1, .2, .5, 1.0, 2.0, 5.0, 10.0],
        'loss_function': ['Logloss']
    }

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=2017,
                                     scoring=auc)

    rand_search.fit(X_train, y_train)

    y_pre = rand_search.best_estimator_.predict(X_test,
                                                prediction_type='Class')

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #4
0
def adaptive_test(X_train,
                  X_test,
                  y_train,
                  y_test,
                  n_iter=100,
                  n_jobs=4,
                  cv=3):
    classifier = naive_bayes.BernoulliNB()

    auc = make_scorer(roc_auc_score)

    rand_list = {
        "alpha": stats.uniform(0.5, 1),
        "binarize": stats.uniform(0.0, 0.5)
    }

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=2017,
                                     scoring=auc)
    rand_search.fit(X_train, y_train)

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #5
0
def adaptive_test(X_train,
                  X_test,
                  y_train,
                  y_test,
                  n_iter=100,
                  n_jobs=4,
                  cv=3):
    classifier = svm.SVC()

    auc = make_scorer(roc_auc_score)

    rand_list = {"C": stats.uniform(0.5, 10), "gamma": stats.uniform(0.05, 1)}

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=2017,
                                     scoring=auc)
    rand_search.fit(X_train, y_train)

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #6
0
def adaptive_test(X_train,
                  X_test,
                  y_train,
                  y_test,
                  n_iter=100,
                  n_jobs=4,
                  cv=3):
    classifier = linear_model.LogisticRegression()

    auc = make_scorer(roc_auc_score)

    rand_list = {
        "tol": stats.uniform(1e-6, 1e-4),
        "C": stats.uniform(0.5, 1),
        "max_iter": [100, 150, 200]
    }

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=2017,
                                     scoring=auc)
    rand_search.fit(X_train, y_train)

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #7
0
def adaptive_test(X_train, X_test, y_train, y_test, n_iter=100, n_jobs=4, cv=3):
    classifier = XGBClassifier()

    auc = make_scorer(roc_auc_score)

    rand_list = {"learning_rate": stats.uniform(1e-6, 1e-2),
                 "n_estimators" : [100, 300, 500]}


    rand_search = RandomizedSearchCV(classifier, param_distributions=rand_list,
                                     n_iter=n_iter, n_jobs=n_jobs, cv=cv, random_state=2017, scoring=auc)
    rand_search.fit(X_train, y_train)

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #8
0
def adaptive_test(X_train, X_test, y_train, y_test, n_iter=50, n_jobs=4, cv=2):
    classifier = SklearnHelper()

    auc = make_scorer(roc_auc_score)

    rand_list = {"v": [1], "threshold": stats.uniform(-.99, 1.99)}

    rand_search = RandomizedSearchCV(classifier,
                                     param_distributions=rand_list,
                                     n_iter=n_iter,
                                     n_jobs=n_jobs,
                                     cv=cv,
                                     random_state=42,
                                     scoring=auc)
    rand_search.fit(X_train, np.int8(y_train))

    y_pre = rand_search.predict(X_test)

    return rand_search_result(rand_search.best_params_, y_test, y_pre)
예제 #9
0
def basic_test():
    classifier = fris_stolp(.5, 1)
    classifier.fit(X_train.values, np.int8(y_train.values))
    res = classifier.predict(X_test.values)
    print(res)
    return rand_search_result({}, y_test, res)