@pytest.mark.differential
def test_model_prediction_differentials(client):
test_inputs_df = load_dataset(file_name="test.csv")
old_model_inputs_df = test_inputs_df.rename(
columns=SECONDARY_VARIABLES_TO_RENAME
)
new_model_response = client.post(
"v1/predictions/gradient", json=test_inputs_df.to_dict(orient="records")
)
new_model_predictions = json.loads(new_model_response.data)["predictions"]
old_model_response = client.post(
"v1/predictions/regression",
json=old_model_inputs_df.to_dict(orient="records"),
)
old_model_predictions = json.loads(old_model_response.data)["predictions"]
# We just pass in the first 10 rows as the two models' validation differs
# which means they filter out a slightly different number of rows
# which would cause the differential tests to fail.
compare_differences(
expected_predictions=new_model_predictions[:10],
actual_predictions=old_model_predictions[:10],
# you would adjust the rel_tol level parameter on your model.
# right now this is extremely permissive of variation.
rel_tol=0.2,
)
이전 모델과 현재 모델에서 각각 예측 결과를 가져온 다음, 결과값의 개수, 예측 스코어 값을 비교한다.
예측 스코어를 비교할 떄는 직접 정의한 compare_differences 함수를 사용하며 이 때 relative tolerance를 주어 이전 버전과 현재 버전의 스코어 값 간의 최대 차이를 설정할 수 있다.
Differential test