Scikit learn 管道上的GridSearchCV:最佳参数似乎是错误的

Scikit learn 管道上的GridSearchCV:最佳参数似乎是错误的,scikit-learn,Scikit Learn,我正在一个由StandardScaler,SelectKBest&Lasso组成的管道上进行网格搜索。我从以下代码中得到的最佳参数与最小化网格分数的参数组合不匹配: numComponents=np.arange(20,220,20) alphas=np.logspace(-6,0,15) pipe = Pipeline(steps=[('normalize', StandardScaler()), ('selectK', SelectKBest(f_regression)), ('l

我正在一个由
StandardScaler,SelectKBest&Lasso
组成的管道上进行网格搜索。我从以下代码中得到的最佳参数与最小化网格分数的参数组合不匹配:

numComponents=np.arange(20,220,20)
alphas=np.logspace(-6,0,15)

pipe = Pipeline(steps=[('normalize', StandardScaler()), ('selectK', SelectKBest(f_regression)),     ('lasso', Lasso())])

gsObj = gridCV(pipe, dict(selectK__k=numComponents.tolist(), lasso__alpha=alphas.tolist()),     scoring='mean_squared_error', cv=10, n_jobs=3, pre_dispatch=3)
gsObj.fit(X_train, y_train)

cvMse=np.array([-score[1] for score in gsObj.grid_scores_]).reshape(len(numComponents),     len(alphas))
optNumComponents=gsObj.best_params_['selectK__k']
optAlpha=gsObj.best_params_['lasso__alpha']
最低的
cvMse
出现在
numComponents
index=5,
alpha
index=7,而
gsObj.best_params u-optNumComponents
index=2,
optAlpha
index=9

我把
网格分数
改成:
len(numComponents)x len(alphas)
(因此假设分数是按这种方式排序的)?

引用,
网格分数
是scikit learn 0.14.1中命名元组的列表,并且

包含参数网格中所有参数组合的分数。每个条目对应一个参数设置。每个命名元组都具有以下属性: 参数,一组参数设置 平均验证分数,交叉验证的平均分数 cv_验证_分数,每个折叠的分数列表


因此,不应该依赖于此列表中的任何顺序,而是应该检查项目以找出它们包含的参数。您似乎假设参数按代码中的顺序排列,但参数网格是一个
dict
,它不能保证其键的顺序。

scikit学习示例中的以下内容是否不正确
scores=np.array(scores).重塑(len(C_范围),len(gamma_范围))
@csankar69该示例似乎对dict中的排序进行了假设,因此是的,它是错误的。另一方面,在GridSearchCV中使用管道并进行并行计算(即,
n_jobs>1
)是可以的,对吗?我不同意。顺序是按字母顺序排列的。字母顺序最大的元素变化最快。这在
\uuuu init\uuuu
中得到了保证。这不对吗?