ynlu.sdk.evaluation.plot package

Submodules

ynlu.sdk.evaluation.plot.confusion_matrix_plot module

ynlu.sdk.evaluation.plot.confusion_matrix_plot.plot_confusion_matrix(confusion_matrix: numpy.ndarray, indices: List[str], normalize: bool = False, output_path: str = None, title: str = 'Confusion Matrix', figure_size: Tuple[int, int] = (8, 6), cmap: <module 'matplotlib.cm' from '/home/docs/checkouts/readthedocs.org/user_builds/yoctol-nlu-py/envs/latest/lib/python3.5/site-packages/matplotlib/cm.py'> = <matplotlib.colors.LinearSegmentedColormap object>, font_style_path: str = None, dpi: int = 300, block: bool = True) → None[source]

Plot confusion matrix

Args:
confusion_matrix (a squared numpy matrix):
The outcome of sklearn.metrics.confusion_matrix is expected.
indices (list of string):
List of strings to index the matrix. The expected indices should be the same as the input argument labels when you generate confusion matrix.
normalize (bool):
If True,
\[\text{confusion matrix}_{ij} = \frac{\text{confusion matrix}_{ij}}{\sum_{j=1}^{n}\text{confusion matrix}_{ij}}\]
output_path (string, default = None):
The place where the output figure would be stored. If it is None, the figure will be shown on screen automatically.
title (string, default = “Confusion Matrix”):
The title of the figure.
figure_size (a pair of integers, default = (8, 6)):
The height and width of the output figure.
cmap (color map):
Matplotlib built-in colormaps.
font_style_path (path of font style):
If None, simhei.ttf will be used as default font style. Chinese characters are supported in this font style.
dpi (int, default = 300):
The resolution in dots per inch.
block (bool):
If False, the figure will not be shown up even if output_path is None. This argument is left for unittest.

Returns: None

Example:
>>> import numpy as np
>>> from ynlu.sdk.evaluation.plot import plot_confusion_matrix
>>> plot_confusion_matrix(
        confusion_matrix=np.random.rand(4,4),
        indices=["a", "b", "c", "d"],
    )

ynlu.sdk.evaluation.plot.line_plot module

ynlu.sdk.evaluation.plot.line_plot.plot_lines(data: List[dict], title: str = 'figure', x_axis_name: str = 'x', y_axis_name: str = 'y', figure_size: Tuple[int, int] = (8, 6), output_path: str = None, color_palette: <function color_palette at 0x7fce2baf2ae8> = None, font_style_path: str = None, dpi: int = 300, block: bool = True) → None[source]

Plot y versus x as lines and/or markers

Args:
data (list of dictionaries):
Dictionaries containing arguments and key words for matplotlib.pyplot.plot. Basic arguments are: x, y, label (the name of line).
title (string, default = “figure”):
The title of the figure.
x_axis_name (string, default = “x”):
The name to be shown on x axis.
y_axis_name(string, default = “y”):
The name to be shown on y axis.
figure_size (a pair of integers, default = (8, 6)):
The height and width of the output figure.
output_path (string, default = None):
The place where the output figure would be stored. If it is None, the figure will be shown on screen automatically.
color_palette (seaborn color palette object):
Please take a look at https://seaborn.pydata.org/generated/seaborn.color_palette.html for more details.
font_style_path (path of font style):
If None, simhei.ttf will be used as default font style. Chinese characters are supported in this font style.
dpi (int, default = 300):
The resolution in dots per inch.
block (bool):
if False, the figure will not be shown up even if output_path is None. This argument is left for unittest.

Returns: None

Example:
>>> from ynlu.sdk.evaluation.plot import plot_lines
>>> plot_lines(
        data=[
            {"x": [1, 2, 3], "y": [4, 5, 6], "label": "line1"},
            {"x": [6, 7, 8], "y": [9, 10, 11], "label": "line2"},
        ],
    )

ynlu.sdk.evaluation.plot.utils module

ynlu.sdk.evaluation.plot.utils.plt_set_font_style(font_style_path: str = None)[source]

Setting font style of figure plotting by matplotlib

By calling the function plt_set_font_style() before saving or showing a figure, the font style “SimHei” will apply to all the text in a figure. This type of font style supports Chinese characters. If you prefer other font styles, just give where it’s stored as an input argument to plt_set_font_style(), and all the text in the figure will be presented in that style.

Args:
font_style_path (path of font style):
If None, simhei.ttf will be used as default font style.

Returns: None

Module contents