Calmcode - matplot gif: hyper

Hyper

1 2 3 4 5

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

@gif.frame
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)))
    plt.title(f"max_depth={i}")

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

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