Beispiel #1
0
def opti_forest(data, n_jobs=1,n_iter=10):
    model = RandomForestRegressor()
    param_dist = {'n_estimators': rint(15, 30),
                  # 'criterion': ['mse','mae'],  # not in 0.18 but in 0.19
                  'min_samples_split': rint(2, 10),
                  'min_samples_leaf': rint(1, 5),
                  'min_weight_fraction_leaf': [0.02],# opti said this is good
                  'max_features': [None], # None is best
                  'min_impurity_split': [0.03, 0.02, 0.01, 0.04],  # min_impurity_decrease
                  "bootstrap": [True],  # false conflicts with oob score thing
                  "oob_score": [False]}

    X,y = getXY(data,data.keys())
    blu = rsearch(model, param_distributions=param_dist, n_iter=n_iter,n_jobs=n_jobs)
    blu.fit(X, y)
    print blu.best_params_
    print blu.best_score_
def optimize_xgb(data, n_jobs=1, n_iter=10):
    model = xgboost.XGBRegressor()
    param_dist = {
        'max_depth': [14],  # 13 and 14 are bestd
        'learning_rate': [0.03],  # rate id 0.022 and nesti of 94 is also ok
        'n_estimators': [65],
        'booster': ['gbtree', 'dart'],
        'gamma': [0, 0.005, 0.001],
        'min_child_weight': [3],  # best
        'max_delta_step': [1],  # best
        'reg_alpha': uniform(.8, 1),
        'reg_lambda': uniform(0.6, 1)
    }

    X, y = ss.getXY(data, list(data.keys()))
    #X = xgboost.DMatrix(X)
    #y= xgboost.DMatrix(y)
    blu = rsearch(model,
                  param_distributions=param_dist,
                  n_iter=n_iter,
                  n_jobs=n_jobs)
    blu.fit(X, y)
    print(blu.best_params_)
    print(blu.best_score_)