ConfusionMatrix
Introduction
ConfusionMatrix
is a widget that display a given confusion matrix with color-coded visualization for better interpretation. It also shows row and column totals.
ConfusionMatrix
allows users to customize the axis labels, detect cell clicking events, and control it from Python code.
Function signature
prepare data for widget
or
Parameters
data
pd.DataFrame()
or dict
Matrix table data
columns
list
List of columns names
x_label
str
Columns label
y_label
str
Rows label
widget_id
str
ID of the widget
data
Matrix table data in different formats:
Pandas Dataframe
Python dict with structure
x_label
Columns label.
type: str
default value: "Predicted Values"
y_label
Rows label.
type: str
default value: "Actual Values"
widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
loading
Get or set table loading
status property.
to_json()
Convert table data to json.
to_pandas()
Convert table data to pandas dataframe.
read_json(value: dict)
Read and set table data from json.
read_pandas(value: pd.DataFrame)
Read and set table data from pandas dataframe.
get_selected_cell(state)
Get selected table cell info.
@click
Decodator function is handled when table cell is pressed.
Mini App Example
You can find this example in our Github repository:
ui-widgets-demos/charts and plots/004_confusion_matrix/src/main.py
Import libraries
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
Prepare function that creates example pandas table
Create data for table.
Initialize ConfusionMatrix
widget
ConfusionMatrix
widgetCreate app layout
Prepare a layout for app using Card
widget with the content
parameter and place widget that we've just created in the Container
widget.
Create app using layout
Create an app object with layout parameter.
Last updated