jeetendra swami
jeetendra swami

Reputation: 1

Error: _pickle.UnpicklingError: invalid load key, '\x09'

I am getting above error when I try to create a pickle file out of explainer.save file.

Below is the code I am using:

import os
import xgboost as xgb
import pickle
def convert_explainer_save_to_pkl(save_file, pkl_file):
    print(f"Converting {save_file} to {pkl_file}")
    with open(save_file, 'rb') as file:
        explainer = pickle.load(file)
    with open(pkl_file, 'wb') as file:
        pickle.dump(explainer, file)
    print(f"Explainer has been saved as {pkl_file}")

# Change working directory to /root
os.chdir('/root')

# Debugging: Print current working directory and list files
print("Current working directory:", os.getcwd())
print("Files in the current directory:", os.listdir('.'))

# Convert shap_explainer.save to shap_explainer.pkl
convert_explainer_save_to_pkl('shap_explainerEI.save', 'shap_explainer.pkl')

# Convert shap_explainerEI.save to shap_explainerEI.pkl
convert_explainer_save_to_pkl('shap_explainer.save', 'shap_explainerEI.pkl')

Error:

Converting shap_explainerEI.save to shap_explainer.pkl
    convert_explainer_save_to_pkl('shap_explainerEI.save', 'shap_explainer.pkl')
  File "/root/jsontopkl.py", line 16, in convert_explainer_save_to_pkl
    explainer = pickle.load(file)
_pickle.UnpicklingError: invalid load key, '\x09'.

Infrastructure:

Upvotes: 0

Views: 30

Answers (0)

Related Questions