Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Numpy 在管道内使用分层Kfold_Numpy_Machine Learning_Scikit Learn - Fatal编程技术网

Numpy 在管道内使用分层Kfold

Numpy 在管道内使用分层Kfold,numpy,machine-learning,scikit-learn,Numpy,Machine Learning,Scikit Learn,我需要输入一些数据并对其进行缩放,然后使用交叉验证搜索模型的最佳超参数集(随机森林和逻辑回归分类器)。另外,我想把整个事情包装成一条管道 目前,我使用以下代码: param_grid = [{'solver':['liblinear',], 'Cs':[5, 10], 'penalty':['l1','l2'], 'tol':[0.1, 0.001, 0.0001], 'max_iter':[50,100,200]},

我需要输入一些数据并对其进行缩放,然后使用交叉验证搜索模型的最佳超参数集(随机森林和逻辑回归分类器)。另外,我想把整个事情包装成一条管道

目前,我使用以下代码:

param_grid = [{'solver':['liblinear',],
           'Cs':[5, 10], 'penalty':['l1','l2'], 
           'tol':[0.1, 0.001, 0.0001],
           'max_iter':[50,100,200]},
      {'solver':['newton-cg', 'lbfgs', 'sag'],
       'Cs':[5, 10,], 'penalty':['l2'], 
       'tol':[0.1, 0.001, 0.0001],
       'max_iter':[50,100,200]}
       ]

clf = LogisticRegressionCV()
grid = GridSearchCV( estimator=clf, param_grid = param_grid)

pipe = Pipeline([('impute', Imputer(strategy='mean', axis=1)),
             ('scale', StandardScaler()),
             ('grid', grid_search)])

cv = StratifiedKFold(Ytrain, n_folds = 5, shuffle=True, random_state=2016)

score = cross_val_score(pipe, Xtrain, Ytrain, cv=cv)
print("Mean validation score: {0:.3f} (std: {1:.5f})".format(np.mean(score),np.std(score)))

然而,我有一种感觉,这种数据缩放和插补的方式在全球范围内发生,这是不正确的。我如何首先应用K折叠,然后分别对每个零件进行插补和缩放,然后进行模型拟合?

我认为您使用的方法是正确的。“全球”是什么意思?对于交叉验证的每一次,将重新初始化输入器和定标器。