请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

使用网格搜索时jupyter报错

在运行gridSearch时出错,一堆报错内容看不太懂…

UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-12-94e3e7f4c057> in <module>
     15 knn_reg = KNeighborsRegressor()
     16 grid_search = GridSearchCV(knn_reg, param_grid, n_jobs=-1, verbose=1)
---> 17 grid_search.fit(X_train_standard, y_train)

C:\anaconda\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)
    644                                     verbose=self.verbose)
    645         results = {}
--> 646         with parallel:
    647             all_candidate_params = []
    648             all_out = []

C:\anaconda\lib\site-packages\joblib\parallel.py in __enter__(self)
    709     def __enter__(self):
    710         self._managed_backend = True
--> 711         self._initialize_backend()
    712         return self
    713 

C:\anaconda\lib\site-packages\joblib\parallel.py in _initialize_backend(self)
    720         try:
    721             n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
--> 722                                              **self._backend_args)
    723             if self.timeout is not None and not self._backend.supports_timeout:
    724                 warnings.warn(

C:\anaconda\lib\site-packages\joblib\_parallel_backends.py in configure(self, n_jobs, parallel, prefer, require, idle_worker_timeout, **memmappingexecutor_args)
    493             n_jobs, timeout=idle_worker_timeout,
    494             env=self._prepare_worker_env(n_jobs=n_jobs),
--> 495             context_id=parallel._id, **memmappingexecutor_args)
    496         self.parallel = parallel
    497         return n_jobs

C:\anaconda\lib\site-packages\joblib\executor.py in get_memmapping_executor(n_jobs, **kwargs)
     18 
     19 def get_memmapping_executor(n_jobs, **kwargs):
---> 20     return MemmappingExecutor.get_memmapping_executor(n_jobs, **kwargs)
     21 
     22 

C:\anaconda\lib\site-packages\joblib\executor.py in get_memmapping_executor(cls, n_jobs, timeout, initializer, initargs, env, temp_folder, context_id, **backend_args)
     40         _executor_args = executor_args
     41 
---> 42         manager = TemporaryResourcesManager(temp_folder)
     43 
     44         # reducers access the temporary folder in which to store temporary

C:\anaconda\lib\site-packages\joblib\_memmapping_reducer.py in __init__(self, temp_folder_root, context_id)
    529             # exposes exposes too many low-level details.
    530             context_id = uuid4().hex
--> 531         self.set_current_context(context_id)
    532 
    533     def set_current_context(self, context_id):

C:\anaconda\lib\site-packages\joblib\_memmapping_reducer.py in set_current_context(self, context_id)
    533     def set_current_context(self, context_id):
    534         self._current_context_id = context_id
--> 535         self.register_new_context(context_id)
    536 
    537     def register_new_context(self, context_id):

C:\anaconda\lib\site-packages\joblib\_memmapping_reducer.py in register_new_context(self, context_id)
    558                 new_folder_name, self._temp_folder_root
    559             )
--> 560             self.register_folder_finalizer(new_folder_path, context_id)
    561             self._cached_temp_folders[context_id] = new_folder_path
    562 

C:\anaconda\lib\site-packages\joblib\_memmapping_reducer.py in register_folder_finalizer(self, pool_subfolder, context_id)
    588         # semaphores and pipes
    589         pool_module_name = whichmodule(delete_folder, 'delete_folder')
--> 590         resource_tracker.register(pool_subfolder, "folder")
    591 
    592         def _cleanup():

C:\anaconda\lib\site-packages\joblib\externals\loky\backend\resource_tracker.py in register(self, name, rtype)
    189         '''Register a named resource, and increment its refcount.'''
    190         self.ensure_running()
--> 191         self._send('REGISTER', name, rtype)
    192 
    193     def unregister(self, name, rtype):

C:\anaconda\lib\site-packages\joblib\externals\loky\backend\resource_tracker.py in _send(self, cmd, name, rtype)
    202 
    203     def _send(self, cmd, name, rtype):
--> 204         msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii')
    205         if len(name) > 512:
    206             # posix guarantees that writes to a pipe of less than PIPE_BUF

UnicodeEncodeError: 'ascii' codec can't encode characters in position 18-20: ordinal not in range(128)``

正在回答 回答被采纳积分+3

1回答

liuyubobobo 2020-06-12 02:58:56

你这样直接赋值粘贴报错信息我也看不懂。我只能说根据出错信息,是字符编码造成的错误。我不确定是不是你的数据集中有特征使用的是中文字符?我也没有用 sklearn 处理过中文自然语言处理的问题,不确定 sklearn 对词的支持如何。

0 回复 有任何疑惑可以回复我~
  • 提问者 vinT #1
    波波老师,我是在运行第五章09-Regression-in-scikit-learn中使用kNN Regressor网格搜索中报错的,用的就是课件里的代码,没有使用中文字符。之前在kNN那章中使用网格搜索也遇到同样的问题。会不会是我的电脑问题?
    回复 有任何疑惑可以回复我~ 2020-06-12 10:52:12
  • liuyubobobo 回复 提问者 vinT #2
    额?我刚刚又在我的环境下运行了一遍课程代码,没有问题。sklearn 已经升到 0.22。只有网格搜索有这个问题吗?其他代码都没有问题吗?你的代码所在的目录是否包含中文字符?试一试在完全的英文字符目录下运行?
    回复 有任何疑惑可以回复我~ 2020-06-12 15:01:52
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信