def test_compute__report_done(): inspector = InspectorShap(model=MockModel(), algotype='kmeans', cluster_probability=False) report_value = pd.DataFrame([[1, 2], [2, 3]], columns=['cluster_id', 'column_a']) inspector.cluster_report = report_value pd.testing.assert_frame_equal(inspector.compute(), report_value)
def test_slice_cluster_no_inputs_not_complementary(global_summary_df, global_X_shap, global_y, global_predicted_proba): inspector = InspectorShap(model=MockModel(), algotype='kmeans') summary = global_summary_df inspector.summary_df = summary inspector.cluster_report = summary inspector.X_shap = X_shap = global_X_shap inspector.y = y = global_y inspector.predicted_proba = predicted_proba = global_predicted_proba target_cluster_id = 1 correct_mask = returned_mask = [ True, False, False, False, True, False, False, False ] inspector.get_cluster_mask.return_value = correct_mask with patch.object(InspectorShap, 'compute') as mocked_compute: with patch.object(InspectorShap, 'get_cluster_mask') as mock_get_cluster_mask: mock_get_cluster_mask.return_value = returned_mask shap_out, y_out, pred_out = inspector.slice_cluster( target_cluster_id, complementary=False) # Ensure mocked_compute not called mocked_compute.accert_not_called() # Ensure mock_get_cluster_mask called with correct arguments mock_get_cluster_mask.assert_called_once() pd.testing.assert_frame_equal( mock_get_cluster_mask.call_args[0][0], summary) assert mock_get_cluster_mask.call_args[0][ 1] == target_cluster_id # Check outputs pd.testing.assert_frame_equal(shap_out, X_shap[correct_mask]) pd.testing.assert_series_equal(y_out, y[correct_mask]) pd.testing.assert_series_equal(pred_out, predicted_proba[correct_mask])