运行时出现KeyError None。适用于gridsearch

2024-04-18 05:15:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经设置了树参数和分层折叠。现在,将GridSearchCV与DecisionContreeClassifier一起使用,并运行.fit方法。然而,我得到了一个关键错误:无

使用Jupyter笔记本,并且以前运行过used GridSearchCV,没有出现任何错误,不确定此数据帧失败的原因

tree = DecisionTreeClassifier(np.random.seed(17), class_weight = 'balanced')

max_depth_values = [5, 6, 7, 8, 9]
max_features_values = [4, 5, 6, 7]
tree_params = {'max_depth': max_depth_values, 'max_features': max_features_values}

skf = StratifiedKFold(n_splits=5, shuffle=True, random_state = np.random.seed(17))

tree_grid = GridSearchCV(tree, tree_params, cv=skf, scoring='roc_auc')

tree_grid.fit(X, y)
The code fails with the below error and I am not sure whats causing this

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-45-3ea31d6abb73> in <module>
      3 tree_grid = GridSearchCV(tree, tree_params, cv=skf, scoring='roc_auc')
      4 
----> 5 tree_grid.fit(X, y)

KeyError: None

Tags: tree错误nprandomparamscvmaxgrid