使用python读取autogluon模型报错

文章内容涉及到Python代码在预测阶段遇到的文件找不到错误,主要与模型文件的路径和加载有关。提到了使用joblib和pickle库加载模型时的路径转义和文件完整性问题,以及尝试使用不同库加载模型的方法。此外,还讨论了模型保存路径的兼容性和Jupyter与PyCharm环境下的差异。

主要代码:

#!D:/workplace/python
# -*- coding: utf-8 -*-
# @File  : performance_predict.py
# @Author:Romulushe
# @Time    : 2023/7/5 10:39
# @Software: PyCharm
# @Use: PyCharm
#读取数据
import numpy as np
import pandas as pd
#加载模型
import joblib
model_best=joblib.load('./data/worker5_best_0705.pkl')

# 读取数据
data=pd.read_csv("./data/t2_raw_0705.csv")
del data['Unnamed: 0']
# print(data)
#预测数据
try:
    p1=model_best.predict(data)
    print(p1)
except Exception as e:
    print(e)

报错详情:

"D:\Program Files (x86)\anaconda\envs\ag\python.exe" E:/文档/Projects/Pycharm/HR_system/0705_new_pro/v1/performance_predict.py
[Errno 2] No such file or directory: '../data/AUO-train/model/AM/worker5/worker5.pkl\\models\\ExtraTreesMSE_BAG_L1\\model.pkl'

Process finished with exit code 0

问题分析:
The error message you encountered suggests that there is a missing file or directory. Specifically, the file '../data/AUO-train/model/AM/worker5/worker5.pkl\\models\\ExtraTreesMSE_BAG_L1\\model.pkl' could not be found.

Here are a few things you can try to resolve this issue:

  1. Verify the file path: Double-check if the file 'model.pkl' exists in the specified location: '../data/AUO-train/model/AM/worker5/worker5.pkl/models/ExtraTreesMSE_BAG_L1'. Make sure the file name, case sensitivity, and directory structure are correct.

  2. Check for typos: Ensure that the file path specified in your code is accurate and there are no typographical errors.

  3. Check the file permissions: Make sure you have appropriate read permissions for the file and its parent directories.

  4. Confirm the working directory: Verify that the script is being executed from the correct working directory. The relative path '../data/AUO-train/model/AM/worker5/worker5.pkl/models/ExtraTreesMSE_BAG_L1/model.pkl' should be relative to the current working directory.

  5. Confirm the file availability: If you are working on a shared system or network, check if the file is accessible to you or if it has been moved or deleted.

By addressing these points, you should be able to troubleshoot the issue and resolve the “No such file or directory” error.
中文翻译
你遇到的错误信息表明缺少文件或目录。具体来说,文件'../data/AUO-train/model/AM/worker5/worker5.pkl/models/ExtraTreesMSE_BAG_L1/model.pkl'无法找到。

以下是几个可能解决这个问题的步骤:

  1. 验证文件路径:仔细检查指定位置'../data/AUO-train/model/AM/worker5/worker5.pkl/models/ExtraTreesMSE_BAG_L1'中是否存在文件'model.pkl'。确保文件名、大小写和目录结构都是正确的。

  2. 检查拼写错误:确保代码中指定的文件路径准确无误,没有拼写错误。

  3. 检查文件权限:确保你对该文件及其父目录具有适当的读取权限。

  4. 确认工作目录:验证脚本是否从正确的工作目录执行。相对路径'../data/AUO-train/model/AM/worker5/worker5.pkl/models/ExtraTreesMSE_BAG_L1/model.pkl'应该相对于当前工作目录。

  5. 确认文件的可用性:如果你是在共享系统或网络上工作,请检查文件是否对你可访问,或者是否已被移动或删除。

通过解决上述问题,你应该能够解决“找不到文件或目录”的错误。

建模过程
在这里插入图片描述
优化建模过程,重新建模

#!D:/workplace/python
# -*- coding: utf-8 -*-
# @File  : train0705_new.py
# @Author:Romulushe
# @Time    : 2023/7/5 11:15
# @Software: PyCharm
# @Use: PyCharm
#读取数据
import numpy as np
import pandas as pd
#准备数据
t2=pd.read_csv("./t2_raw_0705.csv")
del t2['Unnamed: 0']
# print(t2)

# 这里是直接进来一个.csv格式的表单,我这里粗略处理下,得到训练集和测试集
train_df2 = t2.sample(frac=0.8, axis=0, random_state=2022)
test_df2 = t2[~t2.index.isin(train_df2.index)]
#
# #保存数据
t2.to_csv("./raw_0705.csv")
train_df2.to_csv("./train_0705.csv")
test_df2.to_csv("./test_0705.csv")
#
# # #员工自评AutoML
import os,sys
base_path = os.path.dirname(os.path.realpath(sys.argv[0]))
# print('base_path:',base_path)
# new_path=os.path.join(base_path, 'data')
# print('new path:',new_path)

from autogluon.tabular import TabularDataset, TabularPredictor
import warnings
warnings.filterwarnings('ignore')
train_data = TabularDataset(train_df2)

# 预测标签
label = '员工自评'

# 模型保存文件名
save_path = base_path+'\worker0705.pkl'

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值