logo

... human learn: draw



Notes

What if we can make drawings that become classification models? Let's first grab another dataset.

# Make sure you `python -m pip install scikit-lego`
from sklego.datasets import load_penguins
from hulearn.experimental.interactive import InteractiveCharts

df = load_penguins(as_frame=True).dropna()

Let's now make some interactive charts.

from hulearn.experimental.interactive import InteractiveCharts

clf = InteractiveCharts(df, labels="species")

# Run this in a seperate cell. 
clf.add_chart(x="bill_length_mm", y="bill_depth_mm")

# Run this in a seperate cell. 
clf.add_chart(x="flipper_length_mm", y="body_mass_g")

This allows you to draw polygons that could function as a classification model.

from hulearn.classification import InteractiveClassifier

model = InteractiveClassifier(json_desc=clf.data())

# The `.fit(X, y)` is a formality form scikit-learn. 
# It isn't "learning" anything when you run that code.
preds = model.fit(X, y).predict_proba(X)

These preds can be plotted via;

import matplotlib.pylab as plt

plt.figure(figsize=(12, 3))
for i in range(3):
    plt.subplot(131 + i)
    plt.scatter(X['bill_length_mm'], X['bill_depth_mm'], c=preds[:, i])
    plt.xlabel('bill_length_mm')
    plt.ylabel('bill_depth_mm')
    plt.title(model.classes_[i])

import matplotlib.pylab as plt

plt.figure(figsize=(12, 3))
for i in range(3):
    plt.subplot(131 + i)
    plt.scatter(X['flipper_length_mm'], X['body_mass_g'], c=preds[:, i])
    plt.xlabel('flipper_length_mm')
    plt.ylabel('body_mass_g')
    plt.title(model.classes_[i])

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.