ageron / handson-ml2

A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Apache License 2.0
27.26k stars 12.6k forks source link

[BUG] Chapter 2 Visualizing Geographical Data - 'save_fig' is not defined #551

Closed gordontytler closed 2 years ago

gordontytler commented 2 years ago

I think the save_fig function definition is missing in

https://colab.research.google.com/github/ageron/handson-ml2/blob/master/02_end_to_end_machine_learning_project.ipynb#scrollTo=Visualizing_Geographical_Data

To Reproduce I copied this code from colab and pasted into Jupyter running locally

housing.plot(kind="scatter", x="longitude", y="latitude")
save_fig("bad_visualization_plot")
NameError                                 Traceback (most recent call last)
<ipython-input-37-04b7bb0c99fe> in <module>
      1 housing.plot(kind="scatter", x="longitude", y="latitude")
----> 2 save_fig("bad_visualization_plot")

NameError: name 'save_fig' is not defined

Expected behavior Either no call to save_fig or a function definition provided. Not sure if this is matplotlib.pyplot.savefig

ageron commented 2 years ago

Hi @gordontytler , Thanks for your feedback. The save_fig() function is defined in the very first cell of this notebook. It's just a thin wrapper around matplotlib's savefig() function, which sets the file name, PNG format, 300 dpi resolution, and optionally a tight layout. You can safely delete the save_fig() calls if you want, they're just here to save the figures for the book. Hope this helps.