... matplot gif: hyper


The final example demonstrates how you can use a gif to explain what a hyperparameter does in a machine learning model.

import gif
import numpy as np
import matplotlib.pylab as plt
from IPython.display import Image
from sklearn.ensemble import RandomForestRegressor

def frame(i):
    mod = RandomForestRegressor(n_estimators=1, max_depth=i)
    mod.fit(x.reshape(-1, 1), y)
    plt.plot(x, y)
    plt.plot(x, mod.predict(x.reshape(-1, 1)))

frames = [frame(i) for i in range(100)]
gif.save(frames, "rf.gif", duration=300)

A thing to remember: gifs can help explain something but it should never replace a simple line chart. Don't over-use them.

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.