#     print(feature)
        # print('feature counts: {0}'.format(len(features)))

        X_train = vect_val.transform(X_train)
        X_val = vect_val.transform(X_val)
        print('******** GridSearch ********')
        param_grid = {
            'n_estimators': [40, 60, 80, 100, 120],
            'learning_rate': [0.1, 0.15, 0.2],
            'max_depth': [6, 7, 8, 9, 10]
        }
        scorer = make_scorer(f2)

        gs = GridSearch(model=GradientBoostingClassifier())
        gs.fit(X_train, y_train, param_grid, X_val, y_val, scoring=scorer)
        print('params: ', gs.get_best_params())
        print('Test Score for Optimized Parameters:', gs.score(X_val, y_val))

    # print('******** GradientBoostingClassifier ********')
    # gb = GradientBoostingClassifier(learning_rate=0.1, n_estimators=80, max_depth=7)
    # gb, preds_train, preds = train_and_predict(gb, X_train, y_train, X_val)
    # print_scores(y_val, preds, y_train, preds_train)
    #
    # print('******** AdamBoostingClassifier ********')
    # ada = AdaBoostClassifier()
    # ada, preds_train, preds = train_and_predict(ada, X_train, y_train, X_val)
    # print_scores(y_val, preds, y_train, preds_train)
    #
    # print('******** XgBoostClassifier ********')
    # xgb = XGBClassifier()
    # xgb, preds_train, preds = train_and_predict(xgb, X_train, y_train, X_val)
Exemple #2
0
print("Length of Train/Test:",len(X_train),len(X_dev))

params = {
    'lr' : np.random.uniform(0,1,[5]).tolist() + [1.0],
    'ada' : np.random.uniform(0,1,[5]).tolist() + [1.0],
    'et' : np.random.uniform(0,1,[5]).tolist() + [1.0],
    'xgb' : np.random.uniform(0,1,5).tolist() + [1.0],
    'gb' : np.random.uniform(0,1,[5]).tolist() + [1.0],
    'rf' : np.random.uniform(0,1,[5]).tolist() + [1.0], 
    'br' : np.random.uniform(0,1,5).tolist() + [1.0], 
    'lasso' : np.random.uniform(0,1,[5]).tolist() + [1.0], 
    'lrf' : [math.floor,math.ceil,avg],
    'adaf' : [math.floor,math.ceil,avg],
    'etf' : [math.floor,math.ceil,avg],
    'xgbf' : [math.floor,math.ceil,avg],
    'gbf' : [math.floor,math.ceil,avg],
    'rff' :[math.floor,math.ceil,avg],
    'brf' : [math.floor,math.ceil,avg],
    'lassof' : [math.floor,math.ceil,avg],
}


model = GridSearch(N2C2Classifier(),param_grid=params)

model.fit(X_train,y_train,X_dev,y_dev,verbose=True)

print(model.get_best_params())
print(model.get_best_score())