Skip to content

Conversation

tomaszmf
Copy link

The explainer used model.predict() which for classification returns the predicted class label, which is then cast to 0 or 1. The correct approach is to use model.predict_proba() instead.

This fix also adds some unit tests to ensure code quality. Minor PEP related refactoring has also been done.

By Tomasz Rudny, Alistair Garfoot @ MindFoundry (http://mindfoundry.ai)

The explainer used model.predict() which for classification returns the predicted class label, which is then cast to 0 or 1. The correct approach is to use model.predict_proba() instead.

This fix also adds some unit tests to ensure code quality. Minor PEP related refactoring has also been done.

By Tomasz Rudny, Alistair Garfoot @ MindFoundry (http://mindfoundry.ai)
Copy link
Contributor

@bondyra bondyra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that due to lack of explicitly defined interfaces we must call hasattr to check if classifier has probability prediction method.
This check should not be a part of actual algorithm though. I suggest moving this conditional expression to short property, like this:

@property  
def _prediction_function(self):
    if hasattr(self.clf, 'predict_proba'):
        return self.clf.predict_proba
    else:
         return self.clf.predict

This property that returns function could be then called in the explain procedures to get predictions, e.g.:

predictions = self._prediction_function(data)[:, 0]

Doing it this way, we would no longer need to duplicate code in the class.

@pbiecek
Copy link
Member

pbiecek commented Nov 1, 2018

@tomaszmf what about comment from @ bondyra?
Should I merge this PR?

@tomaszmf
Copy link
Author

tomaszmf commented Nov 2, 2018

Hi, Yes, I need to address it. Will do next week.

Could you please wait with the merge till then? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants