auto_sklearn autosklearn AttributeError: 'NoneType' object has no attribute 'info'

 

 
Traceback (most recent call last):
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/automl.py", line 634, in fit
    self._logger = self._get_logger(dataset_name)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/automl.py", line 390, in _get_logger
    self.logging_server.start()
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/process.py", line 112, in start
    self._popen = self._Popen(self)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/context.py", line 291, in _Popen
    return Popen(process_obj)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/popen_forkserver.py", line 35, in __init__
    super().__init__(process_obj)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/popen_forkserver.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError:
        An attempt has been made to start a new process before the     current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your     child processes and you have forgotten to use the proper idiom      in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program     is not going to be frozen to produce an executable.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/automl.py", line 961, in fit
    self._logger.exception(e)
AttributeError: 'NoneType' object has no attribute 'exception'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/forkserver.py", line 281, in main
    old_handlers)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/forkserver.py", line 317, in _serve_one
    code = spawn._main(child_r)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/spawn.py", line 114, in _main
    prepare(preparation_data)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/multiprocessing/spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/data/pigenhancer/transformer_test/auto_sklearn_demo01_iris_classification.py", line 34, in <module>
    model.fit(X_train, y_train)# 预测并计算准确率得分
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/estimators.py", line 1454, in fit
    dataset_name=dataset_name,
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/estimators.py", line 540, in fit
    self.automl_.fit(load_models=self.load_models, **kwargs)
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/automl.py", line 2313, in fit
    is_classification=True,
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/automl.py", line 964, in fit
    self._fit_cleanup()
  File "/home/software/anaconda3/envs/bert_env/lib/python3.7/site-packages/autosklearn/automl.py", line 1064, in _fit_cleanup
    self._logger.info("Closing the dask infrastructure")
AttributeError: 'NoneType' object has no attribute 'info'

 

 print("Precision", sklearn.metrics.precision_score(y_test, predictions))

ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].

 Target is multiclass but average=‘binary’. Please choose another average setting, one of [None, ‘micro’, ‘macro’, ‘weighted’].

原代码如下,是要求某数据集的F1(精度和召回率组合成单一的指标)。

from sklearn.metrics import precision_score, recall_score

precision_score(y_train, y_train_pred)


解决办法

原代码基础上添加了average=‘micro’。

from sklearn.metrics import precision_score, recall_score

precision_score(y_train, y_train_pred, average='micro')


average参数定义了该指标的计算方法,二分类时average参数默认是binary;多分类时,可选参数有micro、macro、weighted和samples。

None:返回每个班级的分数。否则,这将确定对数据执行的平均类型。

binary:仅报告由指定的类的结果pos_label。仅当targets(y_{true,pred})是二进制时才适用。

micro:通过计算总真阳性,假阴性和误报来全球计算指标。也就是把所有的类放在一起算(具体到precision),然后把所有类的TP加和,再除以所有类的TP和FN的加和。因此micro方法下的precision和recall都等于accuracy。

macro:计算每个标签的指标,找出它们的未加权平均值。这不会考虑标签不平衡。也就是先分别求出每个类的precision再求其算术平均。

weighted:计算每个标签的指标,并找到它们的平均值,按支持加权(每个标签的真实实例数)。这会改变“宏观”以解决标签不平衡问题; 它可能导致F分数不在精确度和召回之间。

samples:计算每个实例的指标,并找出它们的平均值(仅对于不同的多标记分类有意义 accuracy_score)。

参考:https://blog.csdn.net/datongmu_yile/article/details/81750737
 链接:https://blog.csdn.net/weixin_44436677/article/details/105985358

posted @ 2023-10-08 17:50  emanlee  阅读(23)  评论(0编辑  收藏  举报