python - 使用pickle加载模式时出现UnicodeDecodeError
问题描述
我正在尝试使用 pickle 加载随机森林模型。该模型是使用版本 0.20.3 (scikit-learn) 构建的。
# LOAD RF MODEL FROM DISK
n_estimators = 100
model_dir = "/home/DATA/Moz/models/"
model_name = "rf_{}_trees_B4_7classes.pkl".format(n_estimators)
model_path = os.path.join(model_dir, model_name)
rf = pickle.load(open(model_path, "rb"))
print("Model {} loaded from disk!".format(model_name))
我得到的错误如下:
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-6-3a315512bee1> in <module>
5 model_name = "rf_{}_trees_B4_7classes.pkl".format(n_estimators)
6 model_path = os.path.join(model_dir, model_name)
----> 7 rf = pickle.load(open(model_path, "rb"))
8
9 print("Model {} loaded from disk!".format(model_name))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa2 in position 29: ordinal not in range(128)
解决方案
推荐阅读
- c# - 为什么尝试为 MySql 创建 using 指令会产生“缺少 using 指令”错误?
- r - 在 r 中绘制没有谷歌地图 API 的城市地图
- python - 在 Python 中循环无限嵌套的字典
- json - Avro Schema 格式异常 - “SecurityClassification” 不是定义的名称
- python - Python烧瓶路线:什么是'?到底是什么意思?
- ios - [NSNull 长度]:无法识别的选择器发送到实例 0x10f8c6fc0' swift 4 iOS
- c++ - 如果模板没有可变参数,则 Lambda 被推导出为 std::function
- javascript - NodeJS 的 https 模块是否遵循重定向?
- excel - VBA - 汇总到主工作表
- c# - C# Selenium:等到下拉加载/显示值?