scikit-learn でグリッドサーチをやろうとしたら
ImportErrorが出てしまうという問題に遭遇しました。
自分の環境は Python2.7 Windows7です。
コア数を指定しない(n_jobsを設定しない)ことでこのエラーを回避できます。
エラーメッセージ
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
例
gs = GridSearchCV(clf, param, n_jobs=-1)
↑これだとエラーが出る
gs = GridSearchCV(clf, param)
↑これだと動く
これは Windows を使用している場合に発生するエラーのようです。
またこういったバグが直されているであろう Python3.X を使った方がいいよ、
という意見もフォーラムでありました。
参考
https://github.com/scikit-learn-contrib/hdbscan/issues/22
https://github.com/joblib/joblib/issues/354