def test_filter_3(self): """ Unit test filter 3 """ xpl = SmartExplainer() mock_data = {'var_dict': 1, 'contrib_sorted': 2, 'x_sorted': 3} xpl.data = mock_data mock_state = Mock() xpl.state = mock_state xpl.filter(positive=True) mock_state.init_mask.assert_called() mock_state.hide_contributions.assert_not_called() mock_state.cap_contributions.assert_not_called() mock_state.sign_contributions.assert_called() mock_state.combine_masks.assert_called() mock_state.cutoff_contributions.assert_not_called() assert hasattr(xpl, 'mask') mock_state.compute_masked_contributions.assert_called() assert hasattr(xpl, 'masked_contributions')
def init_sme_to_pickle_test(): """ Init sme to pickle test TODO: Docstring Returns ------- [type] [description] """ current = Path(path.abspath(__file__)).parent.parent.parent pkl_file = path.join(current, 'data/xpl.pkl') xpl = SmartExplainer() contributions = pd.DataFrame([[-0.1, 0.2, -0.3], [0.1, -0.2, 0.3]]) y_pred = pd.DataFrame(data=np.array([1, 2]), columns=['pred']) dataframe_x = pd.DataFrame([[1, 2, 3], [1, 2, 3]]) xpl.compile(contributions=contributions, x=dataframe_x, y_pred=y_pred, model=LinearRegression()) xpl.filter(max_contrib=2) return pkl_file, xpl
def test_filter_1(self, mock_check_features_name): """ Unit test filter 1 Parameters ---------- mock_check_features_name : [type] [description] """ xpl = SmartExplainer() mock_check_features_name.return_value = [1, 2] mock_data = {'var_dict': 1, 'contrib_sorted': 2, 'x_sorted': 3} xpl.data = mock_data mock_state = Mock() xpl.state = mock_state xpl.filter(features_to_hide=['X1', 'X2']) mock_state.init_mask.assert_called() mock_state.hide_contributions.assert_called() mock_state.cap_contributions.assert_not_called() mock_state.sign_contributions.assert_not_called() mock_state.combine_masks.assert_called() mock_state.cutoff_contributions.assert_not_called() assert hasattr(xpl, 'mask') mock_state.compute_masked_contributions.assert_called() assert hasattr(xpl, 'masked_contributions')