Coder Social home page Coder Social logo

Comments (2)

marcotcr avatar marcotcr commented on June 2, 2024

You can apply it to the multi-label case, but you have to be careful about what the explanation means. You can either have an anchor for the presence of a certain label in the prediction, or an anchor for the whole set of labels. Let's assume your model takes in a 2d numpy array, and returns prediction probabilities for each label such that anything above a certain threshold is predicted. If you want to get an anchor for the presence of a specific label in the prediction, you have to wrap the prediction function as follows:

def get_wrapped_prediction_function(predict_fn, label, threshold=0.5):
    def wrapped_predict_fn(data):
        preds = predict_fn(data)
        return (preds[:, label] > threshold).astype(int)
    return wrapped_predict_fn

If you want to explain the whole set (i.e. the anchor is telling you what is sufficient to get ALL of the predicted labels), you could do something like:

def get_wrapped_predict_fn(predict_fn, instance, threshold=0.5):
    labels = predict_fn(instance.reshape(1, -1)) > threshold)
    def wrapped_predict_fn(data):
        preds = predict_fn(data)
        return np.all((preds[:, labels] > threshold), axis=1).astype(int)
    return wrapped_predict_fn

In either case, what I've done is binarize the original prediction function to output 1 if the condition you want an anchor for is true, and 0 otherwise. This wrapped function is what you should use with the explainer.

from anchor.

limesun avatar limesun commented on June 2, 2024

Thanks, Marco!

from anchor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.