Ejemplo n.º 1
0
    def validate_contributions(self, contributions):
        """
        Check len of list if _case is "classification"
        Check contributions object type if _case is "regression"
        Check type of contributions and transform into (list of) pd.Dataframe if necessary

        Parameters
        ----------
        contributions : pandas.DataFrame, np.ndarray or list

        Returns
        -------
            pandas.DataFrame or list
        """
        check_contribution_object(self._case, self._classes, contributions)
        return self.state.validate_contributions(contributions, self.data["x_preprocessed"])
Ejemplo n.º 2
0
    def test_check_contribution_object_1(self):
        """
        Unit test check_contribution_object 1
        """
        contributions_1 = [
            np.array([[2, 1], [8, 4]]),
            np.array([[5, 5], [0, 0]])
        ]

        contributions_2 = np.array([[2, 1], [8, 4]])
        model = lambda: None
        model._classes = np.array([1, 3])
        model.predict = types.MethodType(self.predict, model)
        model.predict_proba = types.MethodType(self.predict_proba, model)
        _case = "classification"
        _classes = list(model._classes)

        check_contribution_object(_case, _classes, contributions_1)
        assert len(contributions_1) == len(_classes)
        assert isinstance(contributions_1, list)

        check_contribution_object("regression", None, contributions_2)
        assert isinstance(contributions_2, np.ndarray)

        with self.assertRaises(ValueError):
            check_contribution_object(_case, _classes, contributions_2)
            check_mask_params("regression", None, contributions_1)