API reference¶
ExPSVM¶
- class explainpolysvm.expsvm.ExPSVM(sv=None, dual_coef=None, intercept=None, kernel_d=None, kernel_r=None, kernel_gamma=None, p=None, svm_model=None, transform=False, feature_names=None, problem_type=None)[source]¶
Bases:
objectExplain polynomial SVM.
Transformed a trained SVM model into a linear model where each term in the model corresponds to an interaction between the original features. The model assumes the SVM is trained with a polynomial kernel defined as K(x,y|d,r,gamma) = (r + gamma*(x^Ty))^d. Here, r is the constant term of the polynomial kernel, d the polynomial degree, gamma a kernel coefficient determining the relative weight of higher components, and x and y feature vectors.
The transformation to a linear kernel makes use of the fact that interactions containing the exact same constituents, all have the same value. For example, the interaction x1*x1*x3*x5, that is, feature 1 multiplied by itself as well as feature 3 and 5, is equal to X1*x3*x5*x1. Thus, we only need to calculate one of these interactions. In the linear model, the total contribution from this interaction is calculated from the value of one of the interaction multiplied by the number of identical interactions.
- Parameters:
sv (numpy.ndarray of shape (n_SV, n_features)) – Support vectors. Optional, use only if no scikit-learn model is provided.
p (int) – Number of features in original space. Calculated from sv if not provided. Optional, use only if no scikit-learn model is provided.
dual_coef (numpy.ndarray of shape (n_SV, 1)) – SVM dual coefficients. Same as
dual_coef_in sklearn’s SVC. Calculated as dual_coef[i] = alpha[i]*y[i] for classification and dual_coef[i] = alpha[i] - alpha_star[i] for regression. Optional, use only if no scikit-learn model is provided.intercept (float) – The constant in the SVM decision function. Optional, use only if no scikit-learn model is provided.
kernel_d (int) – Degree of the polynomial kernel. Optional, use only if no scikit-learn model is provided.
kernel_r (float) – Independent term of the polynomial kernel. Optional, use only if no scikit-learn model is provided.
kernel_gamma (float or {'scale', 'auto'}) – Kernel coefficient controlling the relative importance of higher-order terms. Optional, use only if no scikit-learn model is provided.
svm_model (sklearn.svm.SVC) – Trained Scikit-learn SVC model. Use to simplify creation of ExPSVM object. Parameters are extracted automatically from the SVC object.
transform (bool) – Set to True to transform SVM model at creation of ExPSVM object. Otherwise, a call to transform_svm() is required. The transformation is done using transform_svm() without any input and may become computationally heavy if kernel dimension and the number of features are large. Default is False.
feature_names (List of strings) – List of feature names in the original space.
problem_type (str) – Type of ml algorithm. Currently implemented are: ‘class’ (or ‘classification’), ‘reg’ (or ‘regression’)
- _interactions¶
List of unique indices that are explicitly included in the linear transformations. Formatted as [‘i,j,k,l’, ‘i,i,k,l’,…], for example. n_interactions is the number of explicit interactions in the linear model.
- Type:
numpy.ndarray of str of shape (n_interactions,)
- _perm_count¶
List of number of permutations of each index in _interactions.
- Type:
numpy.ndarray of int of shape (n_interactions,)
- _interaction_dims¶
List of dimensionality of each interaction in _interactions. For example, interaction x1*x2*x3 has dimensionality 3.
- Type:
numpy.ndarray of int of shape (n_interactions,)
- _poly_coef¶
Cache of the poly_coef property, empty until the property is first used. Contains constants relating to the dimensionality of the interaction, i.e. different constant for first order interactions compared to second order interactions. Calculated as (kernel_d choose d)*r^(kernel_d - d) where d is the dimensionality of the interaction.
- Type:
- interaction_mask¶
Boolean array with True for every element that should be kept in the linear transformation. The mask is used to select the most important features and reduce the size of the linear model.
- Type:
numpy.ndarray of bool of shape (n_interactions,)
- linear_model¶
Linear model transformed from the polynomial SVM model. Used to extract feature importance and calculate the decision function.
- Type:
numpy.ndarray of float of shape (n_interactions, 1)
- linear_model_is_masked¶
Flag to propagate the information that the linear_model has already been masked and does not contain all interactions. Used when calculating the decision function and the feature importance when evaluated on individual observations.
- Type:
- property poly_coef: dict¶
Constants of the polynomial kernel, one per degree of the kernel.
The constant of degree d is (kernel_d choose d)*r^(kernel_d - d), which is the factor that the interactions of degree d carry in the linear model. The kernel coefficient gamma is not included, since the linear model and the degree contributions apply it differently.
The constants only depend on the kernel parameters, so they are calculated once, at the first use, and stored in _poly_coef.
Degree 0 is included, and is used by the degree contributions. It has no counterpart in _interactions, _perm_count and _interaction_dims, which describe interactions and therefore start at degree 1: degree 0 contributes a constant rather than an interaction, and that constant is zero for a trained SVM since the dual coefficients sum to zero.
- Returns:
poly_coef – Constant of each degree, of degree 0, 1,…, kernel_d.
- Return type:
- get_interactions(**kwargs)[source]¶
Returns numpy array of strings of interactions. Example: The interaction x1*x1*x2*x3 is returned as ‘1,1,2,3’.
- Parameters:
kwargs (Arguments passed to get_interaction_index(). Used to reduce number of interactions.)
- Returns:
Interactions – Array of strings with interactions.
- Return type:
Numpy ndarray of shape (n_interactions,) of str.
- get_perm_count(**kwargs)[source]¶
Returns numpy array of number of permutations of the interactions in _interactions. Example: The interaction x1*x1*x2*x3 has 4!/2!=12 possible interactions.
- Parameters:
kwargs (Arguments passed to get_interaction_index(). Used to reduce the number of interactions.)
- Returns:
Permutation count – Array of the number of permutations for each interaction in _interactions.
- Return type:
Numpy ndarray of shape (n_interactions,)
- get_interaction_dim(**kwargs)[source]¶
Returns numpy array of the dimension of each interaction in _interactions. Example: The interaction x1*x1*x2*x3 has dimension 4.
- Parameters:
kwargs (Arguments passed to get_interaction_index(). Used to reduce number of interactions.)
- Returns:
Interaction dimensions – Array of the dimension of the interactions in _interactions.
- Return type:
Numpy ndarray of shape (n_interactions,)
- get_linear_model(**kwargs)[source]¶
Returns numpy array of the linear model transformed from the polynomial SVM. kwargs can be supplied to include only selected interactions, as controlled by get_interaction_index(). If the linear model was masked in transform_svm(), the selection is applied among the interactions of the masked model.
- Parameters:
kwargs (Arguments passed to get_interaction_index(). Used to reduce the number of interactions.)
- Returns:
Linear model – Linear model of the polynomial SVM model.
- Return type:
Numpy ndarray of shape (n_interactions, 1)
- set_feature_names(feature_names)[source]¶
Set names for the features in original space :param feature_names: List of feature names :type feature_names: List of strings
- get_interaction_index(interaction_strs=None, d=None, mask=False)[source]¶
Returns indices of interactions from _interactions based on a list of interaction strings and/or interaction dimension and/or interactions included in interaction_mask. If multiple of interaction_strs, d, and mask are provided, the intersection of the provided inputs are used. That is, if both interaction_strs and d ir provided, only indices of interactions of dimension d that are also in interaction_strs are returned.
- Parameters:
- Returns:
ind – Boolean array with True at elements that satisfy all inputs.
- Return type:
Numpy ndarray of shape (n_interactions,)
- transform_svm(reduce_memory=False, mask=False)[source]¶
Calculate and set a compressed linear version of the polynomial SVM model.
- Parameters:
reduce_memory (Boolean) – Set to True to reduce memory usage by looping over support vectors instead of transforming all at once. Default is False.
mask (Boolean) – Set to True to apply mask to the linear model, reducing the number of elements of the model. Note that masking can alternatively be applied when calculating decision functions, to, for example, evaluate feature selection.
- Returns:
self – Instance with linear model.
- Return type:
Instance
- decision_function_components(x, include_intercept=True, output_interaction_names=False, reduce_memory=False, mask=False, format_interaction_names=False)[source]¶
Returns the components of the decision function for the observation(s) x.
- Parameters:
x (Numpy ndarray of shape (n_observations, n_features)) – Observations to calculate decision function for.
include_intercept (Boolean) – Set to True (default) to prepend the intercept to both the decision function component values and the interaction names.
output_interaction_names (Boolean) – If True, return also the names of the interactions.
reduce_memory (Boolean) – Set to True to reduce memory requirements when calculating the compressed linear transform of x. Default is False.
mask (Boolean) – Set to True to apply interaction_mask to the decision function, removing some interactions. Default is False.
format_interaction_names (Boolean) – Set to True to format the interaction names using the feature names, if they exist. Default is False.
- Returns:
df_comp – The components of the decision function. df_comp[0] correspond to the independent component, remaining are given in the same order as _interactions.
- Return type:
Numpy ndarray of shape (n_observations, n_interactions+1)
- decision_function(x, reduce_memory=False, mask=False)[source]¶
Returns the decision function value for observation(s) x.
- Parameters:
x (Numpy ndarray of shape (n_observations, n_features)) – Observations to calculate decision function for.
reduce_memory (Boolean) – Set to True to reduce memory requirements when calculating the compressed linear transform of x. Default is False.
mask (Boolean) – Set to True to apply interaction_mask to the decision function, removing some interactions. Default is False.
- Returns:
X – Decision function for each observation.
- Return type:
Numpy ndarray of shape (n_observations,)
- degree_contributions(x, include_intercept=False, include_d0=False, reduce_memory=False, chunk_size=None)[source]¶
Returns the contribution of each degree of the polynomial kernel to the decision function.
The contributions are additive: together with the intercept they sum to decision_function(x). Where feature_importance() and decision_function_components() describe which interactions matter, the degree contributions describe how much of the decision function each polynomial degree is responsible for, which informs the choice of kernel degree for a problem.
This calculation does not use the compressed linear model, so it neither requires a call to transform_svm() nor grows with the number of interactions. The interaction mask is not applied: the degree contributions always describe the full model.
Note that the contribution of degree 0 is zero for a trained SVM, since the dual coefficients of a trained SVM sum to zero. It is available through include_d0 as a check of the model.
- Parameters:
x (Numpy ndarray of shape (n_observations, n_features) or (n_features,)) – Observations to calculate the degree contributions for.
include_intercept (Boolean) – Set to True to prepend the intercept to the contributions. Default is False.
include_d0 (Boolean) – Set to True to include the contribution of degree 0. Default is False.
reduce_memory (Boolean) – Set to True to handle the observations in chunks, reducing memory usage. Default is False.
chunk_size (int) – Number of observations to handle at a time. Overrides reduce_memory.
- Returns:
contributions – Contribution of each degree of the polynomial kernel to the decision function, of degree 1, 2,…, kernel_d. The contribution of degree 0 is prepended if include_d0 is True and the intercept is prepended if include_intercept is True.
- Return type:
Numpy ndarray of shape (n_observations, kernel_d)
- degree_importance(x=None, agg='mean', magnitude=True, error='std', include_d0=False, reduce_memory=False, chunk_size=None)[source]¶
Aggregate the degree contributions of a set of observations into one value per degree.
Signed contributions of a degree cancel each other out when averaged over observations, so the default aggregates the magnitude of the contributions. Set magnitude to False to aggregate the signed contributions, which shows in which direction a degree pushes the decision function on average.
- Parameters:
x (Numpy ndarray of shape (n_observations, n_features) or (n_features,)) – Observations to aggregate the degree contributions of. The support vectors of the SVM are used if no observations are provided.
agg (str) – Aggregation of the contributions over the observations. One of ‘mean’ (default), ‘median’ and ‘sum’.
magnitude (Boolean) – If True (default) aggregate the magnitude of the contributions, otherwise aggregate the signed contributions.
error (str) – Spread of the contributions over the observations. One of ‘std’ (default), ‘sem’ for the standard error of the mean, ‘iqr’ for the interquartile range, and None for no spread.
include_d0 (Boolean) – Set to True to include the contribution of degree 0. Default is False.
reduce_memory (Boolean) – Set to True to handle the observations in chunks, reducing memory usage. Default is False.
chunk_size (int) – Number of observations to handle at a time. Overrides reduce_memory.
- Returns:
importance (Numpy ndarray of shape (kernel_d,)) – Aggregated contribution of each degree.
spread (Numpy ndarray of shape (kernel_d,) or None) – Spread of the contribution of each degree over the observations. None if error is None.
degree_names (List of strings) – Names of the degrees.
- feature_importance(sort=True, format_names=False, magnitude=True, include_intercept=True, **kwargs)[source]¶
Calculate feature importance and return feature importance, feature names and sorting order.
- Parameters:
sort (Boolean) – If True (default) sort the features in order of importance.
format_names (Boolean) – If True, format interaction strings using format_interaction_names().
magnitude (Boolean) – If True (default) return the absolute value of the feature importance, otherwise return the signed importance.
include_intercept (Boolean) – If True (default) append intercept to list of feature importance.
kwargs (Arguments passed to get_linear_model.)
- Returns:
feat_importance (Numpy ndarray of shape (n_interactions,)) – Array with feature importance.
feat_names (Numpy ndarray of shape (n_interactions,)) – Names of the features.
sort_order (Numpy ndarray of shape (n_interactions,)) – Sorting order to get feat_names from _interactions.
- feature_selection(n_interactions=None, frac_interactions=None, frac_importance=None)[source]¶
Return the most important features given either: a set number of interactions; a fraction of the interactions; or a fraction of the interaction importance.
Importance is measured by the magnitude of the interaction in the linear model.
At least one interaction is always selected. Fractions small enough to select no interaction at all are rounded up to a single interaction.
If the linear model was masked in transform_svm(), the selection is made among the interactions of the masked model. The returned mask still spans all interactions in _interactions, so it can be passed to set_mask() as usual.
- Parameters:
n_interactions (int) – Number of the most important interactions to select.
frac_interactions (float in range [0,1]) – Fraction of the most important interactions to select.
frac_importance (float in range [0,1]) – Select number of interactions given by the total contribution to the decision function.
- Returns:
interaction_mask – Boolean array where True at elements that are judges as important by the input constraints.
- Return type:
Boolean numpy ndarray of shape (n_interactions,)
- set_mask(mask=None, interaction_strs=None, **kwargs)[source]¶
Set mask for the compressed linear transformation of the polynomial SVM.
- Parameters:
mask (Boolean Numpy ndarray of shape (n_interactions,).) – Interactions to include.
interaction_strs (List[str]) – Interactions to include in the mask. Interactions should have format: ‘i,j,k,…’, e.g. ‘0,0’.
kwargs (Arguments passed to feature_selection().)
- Returns:
self – Instance with interaction_mask.
- Return type:
Instance.
- format_interaction_names(interaction_strs)[source]¶
Return formatted interaction strings from ‘i,i,j,k’ to ‘x_{i}^{2}x_{j}x_{k}’. Excludes unused features.
Example: The interaction_strs = [‘0,0,1’, ‘0,1,2’, ‘0,1,0,2’] is returned as [‘x_{0}^{2}x_{1}’, ‘x_{0}x_{1}x_{2}’, ‘x_{0}^{2}x_{1}x_2’].
- plot_model_bar(n_features=10, magnitude=False, include_intercept=False, **kwargs)[source]¶
Visualize the weights of the interactions in the decision function of an SVM trained with polynomial kernel using a bar chart. Interactions are ordered from the highest weight to the lowest.
- Parameters:
n_features (Int) – Number of features to show. Remaining features will be ignored
magnitude (Boolean) – Set to True to visualize the magnitude of the importance. If False the weight will be shown with it’s corresponding sign. Default is False.
include_intercept (Boolean) – Set to True to include the intercept among the weights. Default is False.
figsize (Tuple of two integers) – Size of the pyplot graph. Should be of the format [w, h] or (w, h) where w and h are integers.
kwargs (Comma-separated list key-value pairs) – Arguments to forward to plot._bar.bar.
- Return type:
matplotlib.figure.Figure or None
- plot_sample_waterfall(x, n_features=None, **kwargs)[source]¶
Visualize interaction importance for a single observation using a waterfall graph.
- Parameters:
x (np.ndarray) – Sample to visualize. Should have shape (n_original_features,).
n_features (int) – Number of features to explicitly show. Any remaining features will be bunched together into a “Remaining” bar. Default is 10. n_features is set to n_original_features if n_original_features < n_features.
kwargs (Comma-separated list key-value pairs) – Arguments to forward to plot._waterfall.waterfall
- Return type:
matplotlib.figure.Figure or None
- plot_sample_waterfall_degree(x, n_degree=None, **kwargs)[source]¶
Visualize the contribution of each degree of the polynomial kernel for a single observation using a waterfall graph.
The contributions are calculated with degree_contributions() and therefore neither require a call to transform_svm() nor grow with the number of interactions.
- Parameters:
x (np.ndarray) – Sample to visualize. Should have shape (n_original_features,).
n_degree (int) – Number of degrees to explicitly show. Any remaining degrees will be bunched together into a “Remaining” bar. Default is the degree of the polynomial kernel. n_degree is set to the degree of the kernel if a larger value is provided.
kwargs (Comma-separated list key-value pairs) – Arguments to forward to plot._waterfall.waterfall
- Return type:
matplotlib.figure.Figure or None
- plot_degree_importance(x=None, agg='mean', magnitude=True, error='std', style='bar', include_intercept=False, include_d0=False, rotation=0, reduce_memory=False, chunk_size=None, **kwargs)[source]¶
Visualize the contribution of each degree of the polynomial kernel over a set of observations.
A waterfall graph, as used by plot_sample_waterfall_degree() for a single observation, is not meaningful here: aggregated contributions no longer add up to the decision function value of any particular observation. Two visualizations are available instead.
With style ‘bar’, the aggregated contribution of each degree is drawn as a bar with error bars of the spread over the observations. When the magnitude of the contributions is aggregated, which is the default, the aggregated signed contribution is added as a marker on each bar. A marker close to zero on a tall bar means that the degree contributes to individual decisions but has no preferred direction over the observations.
With style ‘box’, the signed contributions of the observations are summarized in a box plot per degree, which shows the spread without choosing an aggregation.
- Parameters:
x (Numpy ndarray of shape (n_observations, n_features) or (n_features,)) – Observations to visualize the degree contributions of. The support vectors of the SVM are used if no observations are provided.
agg (str) – Aggregation of the contributions over the observations. One of ‘mean’ (default), ‘median’ and ‘sum’. Not used by style ‘box’.
magnitude (Boolean) – If True (default) aggregate the magnitude of the contributions, otherwise aggregate the signed contributions. Not used by style ‘box’.
error (str) – Spread of the contributions over the observations. One of ‘std’ (default), ‘sem’ for the standard error of the mean, ‘iqr’ for the interquartile range, and None for no spread. Not used by style ‘box’.
style (str) – Type of graph. One of ‘bar’ (default) and ‘box’.
include_intercept (Boolean) – Set to True to include the intercept of the SVM, which is the same for every observation. Style ‘bar’ adds it as a bar beside the degrees and style ‘box’ as a horizontal line, since a box of a constant carries no information. Default is False.
include_d0 (Boolean) – Set to True to include the contribution of degree 0. Default is False.
rotation (int) – Rotation of the x-tick labels in degrees. Default is 0, since the names of the degrees are short and few. Increase it if the labels of a high degree kernel overlap.
reduce_memory (Boolean) – Set to True to handle the observations in chunks, reducing memory usage. Default is False.
chunk_size (int) – Number of observations to handle at a time. Overrides reduce_memory.
kwargs (Comma-separated list key-value pairs) – Arguments to forward to plot._bar.bar or plot._box.box.
- Return type:
matplotlib.figure.Figure or None
Interaction utilities¶
- class explainpolysvm.expsvm.InteractionUtils(interaction_dim, n_feature)[source]¶
Bases:
objectFeature interaction utilities.
Helper class to identify and enumerate interactions.
Interactions of dimension d can be viewed as elements of a rank-d tensor. The tensor is permutation symmetric, i.e. to elements with indices that are permutations of each other are equal. The tensors are also assumed to have the same number of elements in each dimension.
For example: The values at locations (i,i,k), (i,k,i) and (k,i,i) are all assumed to be identical.
This type of tensors occur any time a vector is multiplied by itself but along different dimensions, e.g. x*x^T.
- Parameters:
- create_unique_index()[source]¶
Create set of interactions where the order of the indexes does not matter. That is, the interaction is symmetric such that the elements at index (i,j,k,l) and (i,k,j,l) are identical for any number of features and interaction dimension.
- Returns:
List[str].
- Returns:
idx_strs – List of indices of unique interaction such that values at permuted interactions are equal.
- Return type:
List[str]
- explainpolysvm.expsvm.dict2array(di)[source]¶
Flatten dict to array. Dict is assumed to have structure {1:array_1, 2:array_2,…} where array_x are 2d arrays where rows are assumed belonging together.
Example: The array {1:np.array([[1, 2, 3], [1, 2, 3]]),2:np.array([[1, 2, 3, 4, 6, 9], [1, 2, 3, 4, 6, 9]])} is returned as [[1, 2, 3, 1, 2, 3, 4, 6, 9], [1, 2, 3, 1, 2, 3, 4, 6, 9]]
- Parameters:
di (dict) – Dictionary to transform
- Returns:
Array – Concatenated arrays in the dict. Concatenated along axis 1.
- Return type:
Numpy ndarray
Plotting¶
The plotting helpers are backend-agnostic in the sense that they take bar heights or widths and
labels, and return a matplotlib.figure.Figure when called with show=False. The
ExPSVM.plot_* methods prepare the data and forward keyword arguments to them.
- explainpolysvm.plot.bar(bar_heights, labels, show=True, figsize=(5, 4), xlabel=None, ylabel=None, title=None, yerr=None, markers=None, marker_label=None, rotation=90)[source]¶
Create a bar chart.
- Parameters:
bar_heights (Numpy array of floats) – Heights of bars.
labels (List of strings) – List of labels to use for the x-ticks.
show (Boolean) – Set to True (default) to run plt.show() at the very end of this function. Otherwise, return the figure for postprocessing.
figsize (Tuple of two integers) – Size of the pyplot graph. Should be of the format [w, h] or (w, h) where w and h are integers.
xlabel (String) – (Optional) X-label to add to the plot
ylabel (String) – (Optional) Y-label to add to the plot
title (String) – (Optional) Title to add to the plot
yerr (Numpy array of floats) – (Optional) Spread of each bar, drawn as error bars.
markers (Numpy array of floats) – (Optional) One value per bar, drawn as a marker on top of the bars. Used to show a second quantity, such as the signed mean beside bars of the mean magnitude.
marker_label (String) – (Optional) Label of the markers. A legend is added to the plot if provided.
rotation (Int) – Rotation of the x-tick labels in degrees. Default is 90, which keeps long interaction names readable. Use 0 for short labels, such as the names of the polynomial degrees.
- Return type:
matplotlib.figure.Figure or None
- explainpolysvm.plot.box(box_data, labels, show=True, figsize=(5, 4), xlabel=None, ylabel=None, title=None, show_zero=True, rotation=90, hline=None, hline_label=None, hline_color='tab:orange')[source]¶
Create a box plot, one box per column of box_data.
- Parameters:
box_data (Numpy ndarray of shape (n_observations, n_boxes)) – Values to summarize. One box is drawn per column.
labels (List of strings) – List of labels to use for the x-ticks. One label per column of box_data.
show (Boolean) – Set to True (default) to run plt.show() at the very end of this function. Otherwise, return the figure for postprocessing.
figsize (Tuple of two integers) – Size of the pyplot graph. Should be of the format [w, h] or (w, h) where w and h are integers.
xlabel (String) – (Optional) X-label to add to the plot
ylabel (String) – (Optional) Y-label to add to the plot
title (String) – (Optional) Title to add to the plot
show_zero (Boolean) – Set to True (default) to add a horizontal line at zero, separating positive from negative contributions.
rotation (Int) – Rotation of the x-tick labels in degrees. Default is 90. Use 0 for short labels, such as the names of the polynomial degrees.
hline (Float) – (Optional) Value of a horizontal line drawn across the plot. Used to show a constant beside the boxes, such as the intercept of the model.
hline_label (String) – (Optional) Label of the horizontal line. A legend is added to the plot if provided.
hline_color (String) – Matplotlib color of the horizontal line. Default is ‘tab:orange’, the color used for the medians of the boxes.
- Return type:
matplotlib.figure.Figure or None
- explainpolysvm.plot.waterfall(bar_widths, labels, show=True, show_values=False, show_sum=False, figsize=(5, 4), xlim=None, positive_color='tab:red', negative_color='tab:blue')[source]¶
Create a waterfall chart.
- Parameters:
bar_widths (np.ndarray) – Widths of bins. Should have shape (n_original_features,).
labels (List of strings) – List of labels for the bars
show (Boolean) – Set to True (default) to run plt.show() at the very end of this function. Otherwise, return the figure for postprocessing.
show_values (Boolean) – Set to True to add label with the bar width beside each bar. Default is False.
show_sum (Boolean) – Set to True to add the sum of the bars at the bottom of the graph. Default is False
figsize (Tuple of two integers) – Size of the pyplot graph. Should be of the format [w, h] or (w, h) where w and h are integers.
xlim (List of two integers or None) – Custom limits to x-axis. This is useful to prettify the plots in case show_labels=True. This is due to the difficulties to get the extents of pyplot.text text boxes in a useful format. This input may be removed in the future in case a way of ensuring that the labels are confined to the inside of the drawing area is found.
positive_color (str) – Matplotlib color to use for the interactions with positive contribution. Default is ‘tab:blue’.
negative_color (str) – Matplotlib color to use for the interactions with negative contribution. Default is ‘tab:red’.
- Return type:
matplotlib.figure.Figure or None