Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.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
Python ScikitLearn中的多标签网格搜索_Python_Machine Learning_Scikit Learn - Fatal编程技术网

Python ScikitLearn中的多标签网格搜索

Python ScikitLearn中的多标签网格搜索,python,machine-learning,scikit-learn,Python,Machine Learning,Scikit Learn,我是scikit学习新手,我想通过scikit学习GridSearch找到多标签分类问题的最佳参数。我不能让它工作,我很确定标签有问题 我的代码如下所示: X, Y = load_svmlight_file( TRAIN_FILE, dtype=np.float64, multilabel=True ) clf_pipeline = OneVsRestClassifier( Pipeline([('pca', RandomizedPCA()),

我是scikit学习新手,我想通过scikit学习GridSearch找到多标签分类问题的最佳参数。我不能让它工作,我很确定标签有问题

我的代码如下所示:

X, Y = load_svmlight_file( TRAIN_FILE, dtype=np.float64, multilabel=True )

clf_pipeline = OneVsRestClassifier(
            Pipeline([('pca', RandomizedPCA()),
                      ('clf', SVC())
                      ]))
#grid search parameters
c_range = 10.0 ** np.arange(-2, 9)
gamma_range = 10.0 ** np.arange(-5, 4)
n_components_range = (10, 100, 200)
degree_range = (1, 2, 3, 4)

#grid search
param_grid = dict(estimator__clf__gamma=gamma_range,
              estimator__clf__c=c_range,
              estimator__clf__degree=degree_range,
              estimator__pca__n_components=n_components_range)

grid = GridSearchCV(clf_pipeline, param_grid, verbose=2)
grid.fit(X, Y)
在线网格中出现。fitX,Y。 回溯:

File "C:\Python27\lib\site-packages\sklearn\grid_search.py", line 597, in fit
    return self._fit(X, y, ParameterGrid(self.param_grid))
File "C:\Python27\lib\site-packages\sklearn\grid_search.py", line 359, in _fit
    cv = check_cv(cv, X, y, classifier=is_classifier(estimator))
File "C:\Python27\lib\site-packages\sklearn\cross_validation.py", line 1361, in _check_cv
    cv = StratifiedKFold(y, cv, indices=needs_indices)
File "C:\Python27\lib\site-packages\sklearn\cross_validation.py", line 429, in __init__
    label_test_folds = test_folds[y == label]
IndexError: too many indices for array
我使用scikit学习0.15


编辑1。该代码在Linux中运行良好,但在Windows 7 64位上运行不正常。这很可能是数据的问题。您可能需要检查数据文件并重新查看加载。数据是通过标准程序load_svmlight_file加载的,其中数据本身只是tdf idf向量。只用于分类还可以,但不适用于GridSearch您的代码看起来与此非常相似:您是否考虑过这个问题?我怀疑它是否真的适用于Linux。没有实现。