0
votes

So I just see in a tutorial that the author didn't import sklearn when using predict function of pickled model.

the code below is working:

!pip install scikit-learn
import pickle
model = pickle.load(open("model.pkl", "rb"), encoding="bytes")
out = model.predict([[20, 0, 1, 1, 0]])
print(out)

But if I uninstall the sklearn, the predict function is not working.

the code below is not working:

!pip uninstall scikit-learn
import pickle
model = pickle.load(open("model.pkl", "rb"), encoding="bytes")
out = model.predict([[20, 0, 1, 1, 0]])
print(out)

So, how does it work? as far as i understand pickle doesn't depend on scikit-learn. Does the serialized model do import sklearn?