June 25, 2022

Welcome to the wonderful world of widgets. ¶

Today's widget is an answer that traverses kernal density estimates (KDE), bandwidth sliders, and geysers.

Q: What is this geyser's eruption interval? Eruptions are triggered when the geyser's superheated water builds up enough pressure underground. Silica drops out of the cooling water as the water rises to the surface; forming an underground protective coating.

STEPS

  1. click Binder to access interactive Jupyter Notebook
  2. import ipywidgets, seaborn, pyplot, ipython display
  3. load Seaborn "geyser" dataset
  4. KDE plot
  5. KDE w/ integer slider (or float slider) plot
  6. adjust bandwidth slider to determine answer
In [1]:
from IPython.display import HTML

HTML("""
"<iframe width="560" height="315" src="https://www.youtube.com/embed/A3x65YP7rkQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"
""")
Out[1]:
""
In [6]:
#avoid ssh certificate error message
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
sb.get_dataset_names()
Out[6]:
['anagrams',
 'anscombe',
 'attention',
 'brain_networks',
 'car_crashes',
 'diamonds',
 'dots',
 'exercise',
 'flights',
 'fmri',
 'gammas',
 'geyser',
 'iris',
 'mpg',
 'penguins',
 'planets',
 'taxis',
 'tips',
 'titanic']
In [7]:
# load "" dataset
data = sb.load_dataset("geyser")
data.tail()
Out[7]:
duration waiting kind
267 4.117 81 long
268 2.150 46 short
269 4.417 90 long
270 1.817 46 short
271 4.467 74 long
In [8]:
# plot "waiting" column as x-axis

# outline width (lw), fill to shade, color default is blue

# bandwidth adjust (bw_adjust):
#   inc for more jagged peaks
#   dec for smoother peaks

sb.kdeplot(data.waiting, lw=3, fill=True, color="orange", bw_adjust=1)
plt.xlim(0, 120)
plt.ylim(0, 0.038)

# default xlabel is {column name}; default ylabel is "Density"
plt.xlabel("Wait Time (minutes)")
plt.ylabel("Kernal Density Estimate")
plt.suptitle("Geyser Eruption Wait Time")
plt.title("Seaborn Geyser Dataset")
Out[8]:
Text(0.5, 1.0, 'Seaborn Geyser Dataset')

References
https://www.geeksforgeeks.org/seaborn-kdeplot-a-comprehensive-guide/
https://www.nps.gov/yell/learn/education/classrooms/how-yellowstone-geysers-erupt.htm
https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html
ipynb to Binder