Hello,
I have trained my model (privately) on a dataset, then I downloaded it (model.joblib
) and I get the following error.
I tried all sorts of solutions I found on internet; e.g. versions incompatibility between sklearn and joblib, etc.
At the end, it comes down to the fact that I don’t know what versions HF used to train the model… it’s not mentioned anywhere in the files it generated…
I already spent hours on this… as a non-ML expert, I thought I’d save time but it seems I spent hours debugging and looking for solutions…
I also checked documentation, I didn’t find anything related to my issue…
FYI sklearn = 1.3.0
& joblib = 1.3.1
import json
import joblib
model = joblib.load('model.joblib')
config = json.load(open('config.json'))
features = config['features']
# data = pd.read_csv("data.csv")
data = data[features]
data.columns = ["feat_" + str(col) for col in data.columns]
predictions = model.predict(data) # or model.predict_proba(data)
predictions
Could you please help ??
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[5], line 8
2 import joblib
3 # import sklearn
4
5 # import sklearn.external.joblib as joblib
6 # import joblib
----> 8 model = joblib.load('model.joblib')
9 config = json.load(open('config.json'))
11 features = config['features']
File ~/.local/lib/python3.10/site-packages/joblib/numpy_pickle.py:658, in load(filename, mmap_mode)
652 if isinstance(fobj, str):
653 # if the returned file object is a string, this means we
654 # try to load a pickle file generated with an version of
655 # Joblib so we load it with joblib compatibility function.
656 return load_compatibility(fobj)
--> 658 obj = _unpickle(fobj, filename, mmap_mode)
659 return obj
File ~/.local/lib/python3.10/site-packages/joblib/numpy_pickle.py:577, in _unpickle(fobj, filename, mmap_mode)
575 obj = None
576 try:
--> 577 obj = unpickler.load()
...
-> 1213 dispatch[key[0]](self)
1214 except _Stop as stopinst:
1215 return stopinst.value
KeyError: 118