I want to mock two methods (predict_proba and classes_) of a sklearn model. I have a function that receives a template and text, and returns a label and a score.
import numpy as np
from unittest.mock import MagicMock
def model_predict_proba(model, text):
pred_proba_model = model.predict_proba([text])
score = pred_proba_model.max()
label = model.classes_[np.argmax(pred_proba_model)]
return label, score
def test_model_predict_proba():
mock_model = MagicMock()
mock_model.predict_proba.return_value = np.array([0.90, 0.23])
mock_model.classes_.return_value= np.array(['FOOD', 'DRINK'])
text = 'Apple pie'
expected = ("FOOD", 0.90)
result = model_predict_proba(mock_model, text)
assert result == expected
When I run this test, I get the following error message:
Can someone help me?
