【问题标题】:Kernel dies when running GridSearchCV运行 GridSearchCV 时内核死机
【发布时间】:2019-07-18 16:33:08
【问题描述】:

我正在尝试使用 GridSearchCV 为我的 RandomForestRegressor 找到最佳参数,但是每次我运行以下代码时,内核都会在我的 Jupiter 笔记本中死掉。有什么我可以做的吗?


def tuning(estimator, X, label, grid, one_by_one=False):

    data=Data(X, label)

    if one_by_one:
        extra_cl_random = GridSearchCV(estimator=estimator, param_grid=grid)

    else:
        extra_cl_random = RandomizedSearchCV(estimator=estimator, param_distributions=grid, n_iter=500, cv=3)

    extra_cl_random.fit(*data.train())

    best = extra_cl_random.best_estimator_
    tscore = best.score(*data.train())
    vscore = best.score(*data.valid())
    params = best.get_params()

    print('vscore:', vscore)
    print('best_params:', params) 

n_estimators = [int(x) for x in np.linspace(start = 10, stop = 200, num = 10)]
max_features = ['auto', 'sqrt', 'log2', None]
max_depth = [int(x) for x in np.linspace(10, 300, num = 10)]
max_depth.append(None)
min_samples_split = [2, 5, 10] 
min_samples_leaf = [1, 2, 4]
bootstrap = [True, False]
criterion = ['mse', 'mae']
random_state = [100]

random_grid = {'n_estimators': n_estimators,
               'max_features': max_features,
               'max_depth': max_depth,
               'min_samples_split': min_samples_split,
               'min_samples_leaf': min_samples_leaf,
               'bootstrap': bootstrap,
               'criterion': criterion,
               'random_state': random_state}

tuning(RandomForestRegressor(), columns, label, random_grid)

''' 

The message I get is "The kernel appears to have died. It will restart automatically."

【问题讨论】:

    标签: python jupyter-notebook


    【解决方案1】:

    遇到同样的问题,如果您使用的是 Mac,那么 做:

    import os
    os.environ['KMP_DUPLICATE_LIB_OK']='True'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 2019-03-02
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多