Skip to content

Use generic dispatch on model type for _get_single_model_contribution #3

@adamsardar

Description

@adamsardar

What

Break out logic from _get_grouped_contribution so that contributions and refactors are easier. Measure is likely one of cyclomatic complexity, so consider adding the C901 lint as well for a simpler DoD.

https://github.com/lvgig/model_interpreter/blob/0ecb43ce1e40ac7160527a56953419dec40c1a4b/model_interpreter/interpreter.py#L217

Why

Came up in context of review #2; it is very hard to reason about what is happening here.

Generic dispatch is a great OOP means of breaking out logical complexity from if-elfif-else chains and decrease the amount of cognitive bandwidth required to process code.

How

What are the types of model covered by the function? For each, create an implementation of 'getting grouped contributions' and then use a generic dispatched to choose which is the correct method. Then you only need to figure out how to tell the 'chooser' (aka the generic) how to choose the right kind - I'd base this off the model type passed in or potentially the model attributes from sklearn etc.

Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions