diff --git a/eli5/base.py b/eli5/base.py index bb07249..44834a6 100644 --- a/eli5/base.py +++ b/eli5/base.py @@ -11,7 +11,7 @@ @attrs -class Explanation(object): +class Explanation: """ An explanation for classifier or regressor, it can either explain weights or a single prediction. """ @@ -49,7 +49,7 @@ def _repr_html_(self): @attrs -class FeatureImportances(object): +class FeatureImportances: """ Feature importances with number of remaining non-zero features. """ def __init__(self, importances, remaining): @@ -64,7 +64,7 @@ def from_names_values(cls, names, values, std=None, **kwargs): @attrs -class TargetExplanation(object): +class TargetExplanation: """ Explanation for a single target or class. Feature weights are stored in the :feature_weights: attribute, and features highlighted in text in the :weighted_spans: attribute. @@ -92,7 +92,7 @@ def __init__(self, @attrs -class FeatureWeights(object): +class FeatureWeights: """ Weights for top features, :pos: for positive and :neg: for negative, sorted by descending absolute value. Number of remaining positive and negative features are stored in @@ -111,7 +111,7 @@ def __init__(self, @attrs -class FeatureWeight(object): +class FeatureWeight: def __init__(self, feature: Feature, weight: float, std: Optional[float] = None, value=None): self.feature = feature self.weight = weight @@ -120,7 +120,7 @@ def __init__(self, feature: Feature, weight: float, std: Optional[float] = None, @attrs -class WeightedSpans(object): +class WeightedSpans: """ Holds highlighted spans for parts of document - a DocWeightedSpans object for each vectorizer, and other features not highlighted anywhere. """ @@ -140,7 +140,7 @@ def __init__(self, @attrs -class DocWeightedSpans(object): +class DocWeightedSpans: """ Features highlighted in text. :document: is a pre-processed document before applying the analyzer. :weighted_spans: holds a list of spans for features found in text (span indices correspond to @@ -161,7 +161,7 @@ def __init__(self, @attrs -class TransitionFeatureWeights(object): +class TransitionFeatureWeights: """ Weights matrix for transition features. """ def __init__(self, class_names: list[str], coef): self.class_names = class_names @@ -169,7 +169,7 @@ def __init__(self, class_names: list[str], coef): @attrs -class TreeInfo(object): +class TreeInfo: """ Information about the decision tree. :criterion: is the name of the function to measure the quality of a split, :tree: holds all nodes of the tree, and :graphviz: is the tree rendered in graphviz .dot format. @@ -182,7 +182,7 @@ def __init__(self, criterion: str, tree: 'NodeInfo', graphviz: str, is_classific @attrs -class NodeInfo(object): +class NodeInfo: """ A node in a binary tree. Pointers to left and right children are in :left: and :right: attributes. """ diff --git a/eli5/formatters/html.py b/eli5/formatters/html.py index dc59709..2f601ec 100644 --- a/eli5/formatters/html.py +++ b/eli5/formatters/html.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import from itertools import groupby -from typing import List, Optional, Tuple +from html import escape +from typing import Optional import numpy as np from jinja2 import Environment, PackageLoader @@ -32,16 +31,15 @@ )) -def format_as_html(explanation, # type: Explanation - include_styles=True, # type: bool - force_weights=True, # type: bool +def format_as_html(explanation: Explanation, + include_styles=True, + force_weights=True, show=fields.ALL, - preserve_density=None, # type: Optional[bool] - highlight_spaces=None, # type: Optional[bool] - horizontal_layout=True, # type: bool - show_feature_values=False # type: bool - ): - # type: (...) -> str + preserve_density: Optional[bool] = None, + highlight_spaces: Optional[bool] = None, + horizontal_layout=True, + show_feature_values=False, + ) -> str: """ Format explanation as html. Most styles are inline, but some are included separately in