m0_46663101
m0_46663101
采纳率0%
2021-03-04 16:11

导入sklearn报错an integer is required (got type bytes)

anaconda中代码

from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_score
from sklearn.metrics import mean_squared_error

出现报错

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-2f2624b90715> in <module>
----> 1 from sklearn.linear_model import LinearRegression
      2 from sklearn.model_selection import cross_val_score
      3 from sklearn.metrics import mean_squared_error

~\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
     62 else:
     63     from . import __check_build
---> 64     from .base import clone
     65     from .utils._show_versions import show_versions
     66 

~\anaconda3\lib\site-packages\sklearn\base.py in <module>
     12 from scipy import sparse
     13 from .externals import six
---> 14 from .utils.fixes import signature
     15 from .utils import _IS_32BIT
     16 from . import __version__

~\anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>
     12 from .murmurhash import murmurhash3_32
     13 from .class_weight import compute_class_weight, compute_sample_weight
---> 14 from . import _joblib
     15 from ..exceptions import DataConversionWarning
     16 from .fixes import _Sequence as Sequence

~\anaconda3\lib\site-packages\sklearn\utils\_joblib.py in <module>
     20         from joblib import parallel_backend, register_parallel_backend
     21 else:
---> 22     from ..externals import joblib
     23     from ..externals.joblib import logger
     24     from ..externals.joblib import dump, load

~\anaconda3\lib\site-packages\sklearn\externals\joblib\__init__.py in <module>
    117 from .numpy_pickle import load
    118 from .compressor import register_compressor
--> 119 from .parallel import Parallel
    120 from .parallel import delayed
    121 from .parallel import cpu_count

~\anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py in <module>
     26 from .my_exceptions import TransportableException
     27 from .disk import memstr_to_bytes
---> 28 from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
     29                                  ThreadingBackend, SequentialBackend,
     30                                  LokyBackend)

~\anaconda3\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py in <module>
     20     from .pool import MemmappingPool
     21     from multiprocessing.pool import ThreadPool
---> 22     from .executor import get_memmapping_executor
     23 
     24     # Compat between concurrent.futures and multiprocessing TimeoutError

~\anaconda3\lib\site-packages\sklearn\externals\joblib\executor.py in <module>
     12 from .disk import delete_folder
     13 from ._memmapping_reducer import get_memmapping_reducers
---> 14 from .externals.loky.reusable_executor import get_reusable_executor
     15 
     16 

~\anaconda3\lib\site-packages\sklearn\externals\joblib\externals\loky\__init__.py in <module>
     10 
     11 from .backend.context import cpu_count
---> 12 from .backend.reduction import set_loky_pickler
     13 from .reusable_executor import get_reusable_executor
     14 from .cloudpickle_wrapper import wrap_non_picklable_objects

~\anaconda3\lib\site-packages\sklearn\externals\joblib\externals\loky\backend\reduction.py in <module>
    123 # global variable to change the pickler behavior
    124 try:
--> 125     from sklearn.externals.joblib.externals import cloudpickle  # noqa: F401
    126     DEFAULT_ENV = "cloudpickle"
    127 except ImportError:

~\anaconda3\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\__init__.py in <module>
      1 from __future__ import absolute_import
      2 
----> 3 from .cloudpickle import *
      4 
      5 __version__ = '0.8.0'

~\anaconda3\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py in <module>
    150 
    151 
--> 152 _cell_set_template_code = _make_cell_set_template_code()
    153 
    154 

~\anaconda3\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py in _make_cell_set_template_code()
    131         )
    132     else:
--> 133         return types.CodeType(
    134             co.co_argcount,
    135             co.co_kwonlyargcount,

TypeError: an integer is required (got type bytes)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • muyashui Jack_Yang(数据分析及可视化) 21天前

    代码没有问题, 可能是sklearn 安装有问题

    点赞 评论 复制链接分享