PyImpetus icon indicating copy to clipboard operation
PyImpetus copied to clipboard

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

Open yutianfanxing opened this issue 2 years ago • 8 comments

Hi, I have met a problem when I run the Regression Tutorial, just run use the code in the tutorial, when I run at the block Modelling with Decision Tree using PyImpetus, it has an error ascii' codec can't encode characters in position 18-20: ordinal not in range(128) , I just don't know how to fix it. image

yutianfanxing avatar Jun 29 '22 03:06 yutianfanxing

Hello! Before running PyImpetus, can/have you simply run the decision tree regressor on the entire data without feature selection? If that does not produce any error then we can confirm that the problem is on PyImpetus' side and we can proceed with further debugging.

atif-hassan avatar Jun 29 '22 05:06 atif-hassan

yeah, I have run the decision tree regressor, It can run successfully. image

yutianfanxing avatar Jun 29 '22 06:06 yutianfanxing

I ran the same notebook on my end and it ran without any issues. Are you using the same data as specified in the notebook? In any case, could you copy-paste the entire error stack? It is not possible to understand the issue unless the entire error stack trace is provided.

atif-hassan avatar Jun 29 '22 20:06 atif-hassan

of crouse. `UnicodeEncodeError Traceback (most recent call last) in 9 # Fit this above object on the train part and transform the train dataset into selected feature subset 10 # NOTE: x_train has to be a dataframe and y_train has to be a numpy array ---> 11 x_train = model.fit_transform(x_train, y_train) 12 # Transform the test set as well 13 # NOTE: x_test has to be a dataframe

D:\anaconda\envs\pytorch\lib\site-packages\PyImpetus.py in fit_transform(self, data, Y) 642 # Y - Target variable 643 def fit_transform(self, data, Y): --> 644 self.fit(data, Y) 645 return self.transform(data) 646

D:\anaconda\envs\pytorch\lib\site-packages\PyImpetus.py in fit(self, data, Y) 609 610 else: --> 611 final_MB, final_feat_imp = self._find_MB(data.copy(), Y) 612 613 # Sort the features according to their importance

D:\anaconda\envs\pytorch\lib\site-packages\PyImpetus.py in _find_MB(self, data, Y) 530 531 # Growth phase --> 532 MB = self._grow(data, Y) 533 534 # Shrink phase. This is the final MB

D:\anaconda\envs\pytorch\lib\site-packages\PyImpetus.py in _grow(self, data, Y) 474 # Since each feature's importance is checked individually, we can therefore run them in parallel 475 parallel = Parallel(n_jobs=self.n_jobs, verbose=self.verbose) --> 476 feats_and_pval = parallel(delayed(self._PPI)(data[col].values, Y, None, col) for col in data.columns) 477 #feats_and_pval = [self._CPI(data[col].values, Y, None, col) for col in tqdm(data.columns)] 478

D:\anaconda\envs\pytorch\lib\site-packages\joblib\parallel.py in call(self, iterable) 971 972 if not self._managed_backend: --> 973 n_jobs = self._initialize_backend() 974 else: 975 n_jobs = self._effective_n_jobs()

D:\anaconda\envs\pytorch\lib\site-packages\joblib\parallel.py in _initialize_backend(self) 738 """Build a process or thread pool and return the number of workers""" 739 try: --> 740 n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self, 741 **self._backend_args) 742 if self.timeout is not None and not self._backend.supports_timeout:

D:\anaconda\envs\pytorch\lib\site-packages\joblib_parallel_backends.py in configure(self, n_jobs, parallel, prefer, require, idle_worker_timeout, **memmappingexecutor_args) 492 SequentialBackend(nesting_level=self.nesting_level)) 493 --> 494 self._workers = get_memmapping_executor( 495 n_jobs, timeout=idle_worker_timeout, 496 env=self._prepare_worker_env(n_jobs=n_jobs),

D:\anaconda\envs\pytorch\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

D:\anaconda\envs\pytorch\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

D:\anaconda\envs\pytorch\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):

D:\anaconda\envs\pytorch\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):

D:\anaconda\envs\pytorch\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

D:\anaconda\envs\pytorch\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():

D:\anaconda\envs\pytorch\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):

D:\anaconda\envs\pytorch\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) `

yutianfanxing avatar Jun 30 '22 00:06 yutianfanxing

Okay, I guess I will need your code and data to figure this one out. Do you mind emailing me a folder containing the data and corresponding code? Here is my email address: [email protected]

atif-hassan avatar Jun 30 '22 02:06 atif-hassan

The error is not reproducible on my machine and it runs just fine. Maybe change the following line df = pd.read_csv("slice_localization_data.csv") to df = pd.read_csv("slice_localization_data.csv", encoding="UTF-8")

Other than this, it is hard for me to help you out since the error is not reproducible on my side.

atif-hassan avatar Jun 30 '22 06:06 atif-hassan

Thanks your advice , but It doesn't work, I find the same problem in stack overflow https://stackoverflow.com/questions/64176343/unicodeencodeerror-ascii-codec-cant-encode-characters-in-position-18-23-ord

------------------ 原始邮件 ------------------ 发件人: "Atif @.>; 发送时间: 2022年6月30日(星期四) 下午2:22 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [atif-hassan/PyImpetus] 'ascii' codec can't encode characters in position 18-20: ordinal not in range(128) (Issue #8)

The error is not reproducible on my machine and it runs just fine. Maybe change the following line df = pd.read_csv("slice_localization_data.csv") to df = pd.read_csv("slice_localization_data.csv", encoding="UTF-8")

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

yutianfanxing avatar Jun 30 '22 06:06 yutianfanxing

I fix up this problem just do like this. https://stackoverflow.com/questions/64176343/unicodeencodeerror-ascii-codec-cant-encode-characters-in-position-18-23-ord

yutianfanxing avatar Jun 30 '22 06:06 yutianfanxing