ScikitLearn中的多标签网格搜索

2024-04-24 12:56:10 发布

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

我是scikit learn新手,我想用scikit learn 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)

发生在行中“网格.fit(X,Y)”。 回溯:

^{pr2}$

我用scikit学习0.15。在

编辑1。这段代码在Linux下运行得非常好,但在windows7 64位上就不行了


Tags: 代码searchpipelinenpcomponentsrange标签scikit