sklearn Version Issues Solution

sckiit learning version for Machine Learning Projects

Shivam Vatshayan
2 min readJan 2, 2024
Photo by Markus Winkler on Unsplash

Issue you may be facing (example):

C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\base.py:348: InconsistentVersionWarning: Trying to unpickle estimator DecisionTreeClassifier from version 1.2.2 when using version 1.3.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations
warnings.warn(
Traceback (most recent call last):
File “c:\Users\User\Downloads\malware-main 2–20231217T100622Z-001\malware-main 2\app.py”, line 7, in <module>
model = joblib.load(“malware_model.pkl”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\joblib\numpy_pickle.py”, line 658, in load
obj = _unpickle(fobj, filename, mmap_mode)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\joblib\numpy_pickle.py”, line 577, in _unpickle
obj = unpickler.load()
^^^^^^^^^^^^^^^^
File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\pickle.py”, line 1213, in load
dispatch[key[0]](self)
File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\joblib\numpy_pickle.py”, line 402, in load_build
Unpickler.load_build(self)
File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\pickle.py”, line 1718, in load_build
setstate(state)
File “sklearn\tree\tree.pyx”, line 728, in sklearn.tree._tree.Tree.setstate_
File “sklearn\tree\_tree.pyx”, line 1434, 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’)]

Solution :

Directly Run this Command on your VSC Terminal.

pip install scikit-learn==1.2.2

Now run your project code or [python app.py] command and enjoy !!

Thank you :)

--

--

Shivam Vatshayan

Blockchain Developer || Project Developer || Software Engineer