InteractiveCharts

This tool allows you to interactively "draw" a model.

Parameters

Name Type Description Default
dataf the dataframe to make a single interactive chart for required
labels the labels to be drawn, if str we assume a column from the dataframe is chosen, if list we required
color you can manually override the color of the dots to be determined by a column in a dataframe. This setting is useful when you want to input a list of labels but still want to color the dots based on a column value. None

Usage:

from sklego.datasets import load_penguins
from hulearn.experimental.interactive import InteractiveCharts

df = load_penguins(as_frame=True)
charts = InteractiveCharts(df, labels="species")

add_chart(self, x, y, size=5, alpha=0.5, width=400, height=400, legend=True)

Show source code in experimental/interactive.py
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
    def add_chart(self, x, y, size=5, alpha=0.5, width=400, height=400, legend=True):
        """
        Generate an interactive chart to a cell.

        The supported actions include:

        - Add patch or multi-line: Double tap to add the first vertex, then use tap to add each subsequent vertex,
        to finalize the draw action double tap to insert the final vertex or press the <<esc> key.
        - Move patch or ulti-line: Tap and drag an existing patch/multi-line, the point will be dropped once
        you let go of the mouse button.
        - Delete patch or multi-line: Tap a patch/multi-line to select it then press <<backspace>> key while
        the mouse is within the plot area.

        Arguments:
            x: the column from the dataset to place on the x-axis
            y: the column from the dataset to place on the y-axis
            size: the size of the drawn points
            alpha: the alpha (see-through-ness) of the drawn points
            width: the width of the chart
            height: the height of the chart
            legend: show a legend as well

        Usage:

        ```python
        from sklego.datasets import load_penguins
        from hulearn.experimental.interactive import InteractiveCharts

        df = load_penguins(as_frame=True)
        charts = InteractiveCharts(df, labels="species")

        # Next notebook cell
        charts.add_chart(x="bill_length_mm", y="bill_depth_mm")
        # Next notebook cell
        charts.add_chart(x="flipper_length_mm", y="body_mass_g")

        # After drawing a model, export the data
        json_data = charts.data()
        ```
        """
        chart = SingleInteractiveChart(
            dataf=self.dataf.copy(),
            labels=self.labels,
            x=x,
            y=y,
            size=size,
            alpha=alpha,
            width=width,
            height=height,
            color=self.color,
            legend=legend,
        )
        self.charts.append(chart)
        chart.show()

Generate an interactive chart to a cell.

The supported actions include:

  • Add patch or multi-line: Double tap to add the first vertex, then use tap to add each subsequent vertex, to finalize the draw action double tap to insert the final vertex or press the < key.
  • Move patch or ulti-line: Tap and drag an existing patch/multi-line, the point will be dropped once you let go of the mouse button.
  • Delete patch or multi-line: Tap a patch/multi-line to select it then press <> key while the mouse is within the plot area.

Parameters

Name Type Description Default
x the column from the dataset to place on the x-axis required
y the column from the dataset to place on the y-axis required
size the size of the drawn points 5
alpha the alpha (see-through-ness) of the drawn points 0.5
width the width of the chart 400
height the height of the chart 400
legend show a legend as well True

Usage:

from sklego.datasets import load_penguins
from hulearn.experimental.interactive import InteractiveCharts

df = load_penguins(as_frame=True)
charts = InteractiveCharts(df, labels="species")

# Next notebook cell
charts.add_chart(x="bill_length_mm", y="bill_depth_mm")
# Next notebook cell
charts.add_chart(x="flipper_length_mm", y="body_mass_g")

# After drawing a model, export the data
json_data = charts.data()

parallel_coordinates

Creates an interactive parallel coordinates chart to help with classification tasks.

Parameters

Name Type Description Default
dataf the dataframe to render required
label the column that represents the label, will be used for coloring required
height the height of the chart, in pixels 200

Usage:

from hulearn.datasets import load_titanic
from hulearn.experimental.interactive import parallel_coordinates

df = load_titanic(as_frame=True)
parallel_coordinates(df, label="survived", height=200)