Grid search error

时间秒杀一切 提交于 2019-12-24 07:02:29

问题


I've been trying to perform a grid search, but something seems to be off. My code is:

grid_search_0 = GridSearchCV(estimator=Pipeline([('vectorizer', CountVectorizer()), ('tfidf', TfidfTransformer()), ('clf', LinearSVC())]),
             param_grid={'C': 3**np.arange(-3, 3, dtype='float'),
                         'gamma': 3**np.arange(-6, 0, dtype='float'), },
             cv=10,
             scoring=make_scorer(roc_auc_score, needs_threshold=True),
             verbose=1,
             n_jobs=-1,)

and I get the error

ImportError: [joblib] Attempting to do parallel computing without protecting your import on a system that does not support forking. To use parallel-computing in a script, you must protect your main loop using "if __name__ == '__main__'". Please see the joblib documentation on Parallel for more information

Has anyone encountered and solved this before? What am I doing wrong?


回答1:


This is what the error message suggests doing, does this work for you?

if __name__ == '__main__':

    grid_search_0 = GridSearchCV(estimator=Pipeline([('vectorizer', CountVectorizer()), ('tfidf', TfidfTransformer()), ('clf', LinearSVC())]),
             param_grid={'C': 3**np.arange(-3, 3, dtype='float'),
                         'gamma': 3**np.arange(-6, 0, dtype='float'), },
             cv=10,
             scoring=make_scorer(roc_auc_score, needs_threshold=True),
             verbose=1,
             n_jobs=-1)

for more on why this is important, see this Stack Overflow question/answer



来源:https://stackoverflow.com/questions/43716570/grid-search-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!