老师,报错请问是什么原因
来源:5-9 使用scikit-learn解决回归问题
慕运维7479159
2018-04-10
grid_search = GridSearchCV(knn_reg, param_grid, n_jobs=2, verbose=1)
grid_search.fit(X_train, y_train)
Fitting 3 folds for each of 60 candidates, totalling 180 fits
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "D:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "D:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\PythonProject\Regression.py", line 52, in <module>
grid_search.fit(X_train, y_train)
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py", line 639, in fit
cv.split(X, y, groups)))
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 749, in __call__
n_jobs = self._initialize_backend()
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 547, in _initialize_backend
**self._backend_args)
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py", line 305, in configure
'[joblib] Attempting to do parallel computing '
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
1回答
-
报错的地方在于并行方面,我不确定是你的电脑不支持二核还是操作系统上有什么限制。请尝试n_jobs=1或者n_jobs=-1。如果还有问题请先尝试运行使用课程的官方代码:https://github.com/liuyubobobo/Play-with-Machine-Learning-Algorithms
122018-04-10
相似问题