1

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?

saremisona
  • 359
  • 1
  • 4
  • 11
  • Possible duplicate of [Why is it important to protect the main loop when using joblib.Parallel?](http://stackoverflow.com/questions/29545605/why-is-it-important-to-protect-the-main-loop-when-using-joblib-parallel) – Vivek Kumar May 02 '17 at 05:29

1 Answers1

2

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

Community
  • 1
  • 1
Max Power
  • 8,265
  • 13
  • 50
  • 91
  • I have this problem while using jupyter so this does not solve the problem – Simon Jun 29 '18 at 15:32
  • @Simon, do you get the same error as the questioner here, or a different error message in jupyter? If you post a SO question with your issue and link to it here, I'll take a look. – Max Power Jul 03 '18 at 21:10
  • I think it was an issue with an older version of joblib, seems to work in 0.12. If it re-occurs I will post a new question – Simon Jul 21 '18 at 19:08