ValueError: node array from the pickle has an incompatible dtype

After the recent update, my app has stopped working and instead gives a Valueerror.

The entire error is:

File "/app/caustic-consumption-prediction/", line 10, in predict
    clf = pickle.load(f)
File "sklearn/tree/_tree.pyx", line 714, in sklearn.tree._tree.Tree.__setstate__
File "sklearn/tree/_tree.pyx", line 1418, in sklearn.tree._tree._check_node_ndarray
ValueError: node array from the pickle has an incompatible dtype:
- expected: {'names': ['left_child', 'right_child', 'feature', 'threshold', 'impurity', 'n_node_samples', 'weighted_n_node_samples', 'missing_go_to_left'], 'formats': ['<i8', '<i8', '<i8', '<f8', '<f8', '<i8', '<f8', 'u1'], 'offsets': [0, 8, 16, 24, 32, 40, 48, 56], 'itemsize': 64}
- got     : [('left_child', '<i8'), ('right_child', '<i8'), ('feature', '<i8'), ('threshold', '<f8'), ('impurity', '<f8'), ('n_node_samples', '<i8'), ('weighted_n_node_samples', '<f8')]

The app is running into this issue while trying to load a pickle model. I tried to use joblib to load a sav model but got stuck at the same error.

The link to the github repository for the app is:

Can someone please look into this?

1 Like

Hi Praneesh! I had the exact same issue during the day while deploying a model on a site, what I found on how to fix it (which it worked for me) is to have both scikit-learn versions as the same, just verify which one you had when you generated the model, and make sure that it’s the same as the one in your requirements.txt. Hope this fixes your issue!

how to check same version

I got same issue today
ValueError: node array from the pickle has an incompatible dtype:
Refer below screen shot :

Read the docs on model persistence, specifically:

When an estimator is unpickled with a scikit-learn version that is inconsistent with the version the estimator was pickled with, a InconsistentVersionWarning is raised. This warning can be caught to obtain the original version the estimator was pickled with:

from sklearn.exceptions import InconsistentVersionWarning
warnings.simplefilter("error", InconsistentVersionWarning)

   est = pickle.loads("model_from_prevision_version.pickle")
except InconsistentVersionWarning as w:

Keep reading for ways to avoid or mitigate issues like this in the future.

downgrade the version using
pip install scikit-learn==1.2.2


It worked for me, thank you!!!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.