Matrix
binary_confusion_matrix(data, positive_class_label='positive class', negative_class_label='negative class', title='Confusion matrix', normalize=None, show_scale=False, color_scale='Plasma', size=None, plotly_kwargs=None, show=True, write_html_path=None)
¶
Creates a confusion matrix for binary classification.
Example:
from blitzly.plots.matrix import binary_confusion_matrix
import numpy as np
data = np.array([[1, 0, 1, 1, 0, 1], [0, 0, 1, 1, 0, 1]])
binary_confusion_matrix(data, write_html_path="the_blitz.html")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[pd.DataFrame, NDArray]
|
The data which should be plotted. |
required |
positive_class_label |
Optional[str]
|
The label of the positive class. |
'positive class'
|
negative_class_label |
Optional[str]
|
The label of the negative class. |
'negative class'
|
title |
Optional[str]
|
The title of the confusion matrix. |
'Confusion matrix'
|
normalize |
Optional[str]
|
Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized. |
None
|
show_scale |
Optional[bool]
|
Whether to show the color scale. |
False
|
color_scale |
Optional[str]
|
The color scale of the confusion matrix. |
'Plasma'
|
size |
Optional[Tuple[int, int]]
|
The size of the plot. |
None
|
plotly_kwargs |
Optional[dict]
|
Additional keyword arguments for Plotly. |
None
|
show |
bool
|
Whether to show the figure. |
True
|
write_html_path |
Optional[str]
|
The path to which the histogram should be written as an HTML file. If None, the histogram will not be saved. |
None
|
Returns:
Name | Type | Description |
---|---|---|
BaseFigure |
BaseFigure
|
The confusion matrix. |
Source code in blitzly/plots/matrix.py
cramers_v_corr_matrix(data, title="Cramer's V correlation matrix", show_scale=False, size=(700, 700), decimal_places=3, plotly_kwargs=None, show=True, write_html_path=None)
¶
Cramer's V correlation matrix. It can be used to get the correlations between nominal variables.
Example:
from blitzly.matrix import cramers_v_corr_matrix
import pandas as pd
df = pd.DataFrame(
{
"foo": ["1", "1", "1", "2", "2", "2"],
"bar": ["3", "2", "3", "7", "5", "7"],
"blitzly": ["9", "3", "4", "6", "7", "9"],
"licht": ["1", "1", "1", "2", "2", "2"],
}
)
fig = cramers_v_corr_matrix(df)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
pd.DataFrame
|
The data which should be plotted. All columns need to be nominal/categorical. |
required |
title |
Optional[str]
|
The title of the correlation matrix. |
"Cramer's V correlation matrix"
|
show_scale |
Optional[bool]
|
Whether to show the color scale. |
False
|
decimal_places |
Optional[int]
|
The number of decimal places to round the values to. This only applies to the values shown on the plot. |
3
|
size |
Optional[Tuple[int, int]
|
Size of the plot. |
(700, 700)
|
plotly_kwargs |
Optional[dict]
|
Additional keyword arguments for Plotly. |
None
|
show |
bool
|
Whether to show the figure. |
True
|
write_html_path |
Optional[str]
|
The path to which the histogram should be written as an HTML file. |
None
|
Returns:
Name | Type | Description |
---|---|---|
BaseFigure |
BaseFigure
|
The figure. |
Source code in blitzly/plots/matrix.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
pearson_corr_matrix(data, title='Pearson correlation matrix', show_scale=False, size=None, decimal_places=4, labels=None, row_var=True, plotly_kwargs=None, show=True, write_html_path=None)
¶
Creates Pearson product-moment correlation coefficients matrix
using NumPy's corrcoef
function.
Please refer to the NumPy documentation for cov
for more detail. The relationship between the correlation coefficient matrix, R, and the covariance matrix, C, is:
The values of R are between -1 and 1, inclusive.
Example:
from blitzly.matrix import pearson_corr_matrix
import numpy as np
import pandas as pd
data = np.array(
[
[0.77395605, 0.43887844, 0.85859792],
[0.69736803, 0.09417735, 0.97562235],
[0.7611397, 0.78606431, 0.12811363],
]
)
df = pd.DataFrame(data, columns=["foo", "bar", "blitzly"])
pearson_corr_matrix(df, write_html_path="the_blitz.html")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[pd.DataFrame, NDArray]
|
The data which should be plotted. |
required |
title |
Optional[str]
|
The title of the correlation matrix. |
'Pearson correlation matrix'
|
show_scale |
Optional[bool]
|
Whether to show the color scale. |
False
|
decimal_places |
Optional[int]
|
The number of decimal places to round the values to. This only applies to the values shown on the plot. |
4
|
size |
Optional[Tuple[int, int]
|
Size of the plot. |
None
|
labels |
Optional[List[str]]
|
The labels of the columns. If a Pandas DataFrame is passed, the column names will be used. |
None
|
row_var |
Optional[bool]
|
If rowvar is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. |
True
|
plotly_kwargs |
Optional[dict]
|
Additional keyword arguments for Plotly. |
None
|
show |
bool
|
Whether to show the figure. |
True
|
write_html_path |
Optional[str]
|
The path to which the histogram should be written as an HTML file. If None, the histogram will not be saved. |
None
|