Overfitting 解答
Goals¶
In this lab, you will explore:
- the situations where overfitting can occur
- some of the solutions
In [2]:
!pip install matplotlib
%matplotlib widget
import matplotlib.pyplot as plt
from ipywidgets import Output
from plt_overfit import overfit_example, output
plt.style.use('./deeplearning.mplstyle')
Collecting matplotlib
Downloading matplotlib-3.10.7-cp314-cp314-win_amd64.whl.metadata (11 kB)
Collecting contourpy>=1.0.1 (from matplotlib)
Downloading contourpy-1.3.3-cp314-cp314-win_amd64.whl.metadata (5.5 kB)
Collecting cycler>=0.10 (from matplotlib)
Downloading cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB)
Collecting fonttools>=4.22.0 (from matplotlib)
Downloading fonttools-4.61.0-cp314-cp314-win_amd64.whl.metadata (115 kB)
Collecting kiwisolver>=1.3.1 (from matplotlib)
Downloading kiwisolver-1.4.9-cp314-cp314-win_amd64.whl.metadata (6.4 kB)
Collecting numpy>=1.23 (from matplotlib)
Downloading numpy-2.3.5-cp314-cp314-win_amd64.whl.metadata (60 kB)
Requirement already satisfied: packaging>=20.0 in d:\anaconda3\envs\jupyter_env\lib\site-packages (from matplotlib) (25.0)
Collecting pillow>=8 (from matplotlib)
Downloading pillow-12.0.0-cp314-cp314-win_amd64.whl.metadata (9.0 kB)
Collecting pyparsing>=3 (from matplotlib)
Downloading pyparsing-3.2.5-py3-none-any.whl.metadata (5.0 kB)
Requirement already satisfied: python-dateutil>=2.7 in d:\anaconda3\envs\jupyter_env\lib\site-packages (from matplotlib) (2.9.0.post0)
Requirement already satisfied: six>=1.5 in d:\anaconda3\envs\jupyter_env\lib\site-packages (from python-dateutil>=2.7->matplotlib) (1.17.0)
Downloading matplotlib-3.10.7-cp314-cp314-win_amd64.whl (8.3 MB)
---------------------------------------- 0.0/8.3 MB ? eta -:--:--
- -------------------------------------- 0.3/8.3 MB ? eta -:--:--
-- ------------------------------------- 0.5/8.3 MB 1.1 MB/s eta 0:00:07
----- ---------------------------------- 1.0/8.3 MB 1.9 MB/s eta 0:00:04
------ --------------------------------- 1.3/8.3 MB 1.8 MB/s eta 0:00:04
-------- ------------------------------- 1.8/8.3 MB 1.8 MB/s eta 0:00:04
---------- ----------------------------- 2.1/8.3 MB 1.8 MB/s eta 0:00:04
----------- ---------------------------- 2.4/8.3 MB 1.6 MB/s eta 0:00:04
------------ --------------------------- 2.6/8.3 MB 1.6 MB/s eta 0:00:04
------------- -------------------------- 2.9/8.3 MB 1.6 MB/s eta 0:00:04
--------------- ------------------------ 3.1/8.3 MB 1.5 MB/s eta 0:00:04
--------------- ------------------------ 3.1/8.3 MB 1.5 MB/s eta 0:00:04
---------------- ----------------------- 3.4/8.3 MB 1.4 MB/s eta 0:00:04
----------------- ---------------------- 3.7/8.3 MB 1.4 MB/s eta 0:00:04
------------------- -------------------- 3.9/8.3 MB 1.4 MB/s eta 0:00:04
-------------------- ------------------- 4.2/8.3 MB 1.4 MB/s eta 0:00:03
--------------------- ------------------ 4.5/8.3 MB 1.4 MB/s eta 0:00:03
---------------------- ----------------- 4.7/8.3 MB 1.4 MB/s eta 0:00:03
------------------------ --------------- 5.0/8.3 MB 1.3 MB/s eta 0:00:03
------------------------- -------------- 5.2/8.3 MB 1.3 MB/s eta 0:00:03
-------------------------- ------------- 5.5/8.3 MB 1.3 MB/s eta 0:00:03
-------------------------- ------------- 5.5/8.3 MB 1.3 MB/s eta 0:00:03
--------------------------- ------------ 5.8/8.3 MB 1.3 MB/s eta 0:00:02
----------------------------- ---------- 6.0/8.3 MB 1.3 MB/s eta 0:00:02
----------------------------- ---------- 6.0/8.3 MB 1.3 MB/s eta 0:00:02
------------------------------ --------- 6.3/8.3 MB 1.2 MB/s eta 0:00:02
------------------------------- -------- 6.6/8.3 MB 1.2 MB/s eta 0:00:02
--------------------------------- ------ 6.8/8.3 MB 1.2 MB/s eta 0:00:02
----------------------------------- ---- 7.3/8.3 MB 1.3 MB/s eta 0:00:01
------------------------------------ --- 7.6/8.3 MB 1.3 MB/s eta 0:00:01
--------------------------------------- 8.1/8.3 MB 1.3 MB/s eta 0:00:01
--------------------------------------- 8.1/8.3 MB 1.3 MB/s eta 0:00:01
---------------------------------------- 8.3/8.3 MB 1.3 MB/s 0:00:06
Downloading contourpy-1.3.3-cp314-cp314-win_amd64.whl (232 kB)
Downloading cycler-0.12.1-py3-none-any.whl (8.3 kB)
Downloading fonttools-4.61.0-cp314-cp314-win_amd64.whl (2.3 MB)
---------------------------------------- 0.0/2.3 MB ? eta -:--:--
---- ----------------------------------- 0.3/2.3 MB ? eta -:--:--
--------- ------------------------------ 0.5/2.3 MB 1.6 MB/s eta 0:00:02
------------- -------------------------- 0.8/2.3 MB 1.6 MB/s eta 0:00:01
------------------ --------------------- 1.0/2.3 MB 1.5 MB/s eta 0:00:01
---------------------- ----------------- 1.3/2.3 MB 1.4 MB/s eta 0:00:01
------------------------------- -------- 1.8/2.3 MB 1.5 MB/s eta 0:00:01
------------------------------------ --- 2.1/2.3 MB 1.5 MB/s eta 0:00:01
------------------------------------ --- 2.1/2.3 MB 1.5 MB/s eta 0:00:01
---------------------------------------- 2.3/2.3 MB 1.4 MB/s 0:00:01
Downloading kiwisolver-1.4.9-cp314-cp314-win_amd64.whl (75 kB)
Downloading numpy-2.3.5-cp314-cp314-win_amd64.whl (12.9 MB)
---------------------------------------- 0.0/12.9 MB ? eta -:--:--
---------------------------------------- 0.0/12.9 MB ? eta -:--:--
--------------------------------------- 0.3/12.9 MB ? eta -:--:--
- -------------------------------------- 0.5/12.9 MB 1.3 MB/s eta 0:00:10
-- ------------------------------------- 0.8/12.9 MB 1.1 MB/s eta 0:00:11
--- ------------------------------------ 1.0/12.9 MB 1.2 MB/s eta 0:00:11
--- ------------------------------------ 1.0/12.9 MB 1.2 MB/s eta 0:00:11
---- ----------------------------------- 1.3/12.9 MB 1.1 MB/s eta 0:00:11
---- ----------------------------------- 1.3/12.9 MB 1.1 MB/s eta 0:00:11
---- ----------------------------------- 1.6/12.9 MB 951.2 kB/s eta 0:00:12
----- ---------------------------------- 1.8/12.9 MB 985.4 kB/s eta 0:00:12
------ --------------------------------- 2.1/12.9 MB 1.0 MB/s eta 0:00:11
------- -------------------------------- 2.4/12.9 MB 968.3 kB/s eta 0:00:11
------- -------------------------------- 2.4/12.9 MB 968.3 kB/s eta 0:00:11
-------- ------------------------------- 2.6/12.9 MB 915.5 kB/s eta 0:00:12
-------- ------------------------------- 2.6/12.9 MB 915.5 kB/s eta 0:00:12
-------- ------------------------------- 2.9/12.9 MB 875.9 kB/s eta 0:00:12
--------- ------------------------------ 3.1/12.9 MB 904.6 kB/s eta 0:00:11
--------- ------------------------------ 3.1/12.9 MB 904.6 kB/s eta 0:00:11
--------- ------------------------------ 3.1/12.9 MB 904.6 kB/s eta 0:00:11
----------- ---------------------------- 3.7/12.9 MB 890.6 kB/s eta 0:00:11
----------- ---------------------------- 3.7/12.9 MB 890.6 kB/s eta 0:00:11
------------ --------------------------- 3.9/12.9 MB 884.8 kB/s eta 0:00:11
------------ --------------------------- 3.9/12.9 MB 884.8 kB/s eta 0:00:11
------------ --------------------------- 4.2/12.9 MB 876.0 kB/s eta 0:00:10
------------- -------------------------- 4.5/12.9 MB 888.0 kB/s eta 0:00:10
-------------- ------------------------- 4.7/12.9 MB 886.4 kB/s eta 0:00:10
-------------- ------------------------- 4.7/12.9 MB 886.4 kB/s eta 0:00:10
-------------- ------------------------- 4.7/12.9 MB 886.4 kB/s eta 0:00:10
--------------- ------------------------ 5.0/12.9 MB 859.2 kB/s eta 0:00:10
---------------- ----------------------- 5.2/12.9 MB 874.2 kB/s eta 0:00:09
---------------- ----------------------- 5.2/12.9 MB 874.2 kB/s eta 0:00:09
----------------- ---------------------- 5.5/12.9 MB 857.9 kB/s eta 0:00:09
----------------- ---------------------- 5.5/12.9 MB 857.9 kB/s eta 0:00:09
----------------- ---------------------- 5.8/12.9 MB 839.1 kB/s eta 0:00:09
----------------- ---------------------- 5.8/12.9 MB 839.1 kB/s eta 0:00:09
------------------ --------------------- 6.0/12.9 MB 823.3 kB/s eta 0:00:09
------------------ --------------------- 6.0/12.9 MB 823.3 kB/s eta 0:00:09
------------------- -------------------- 6.3/12.9 MB 807.6 kB/s eta 0:00:09
------------------- -------------------- 6.3/12.9 MB 807.6 kB/s eta 0:00:09
------------------- -------------------- 6.3/12.9 MB 807.6 kB/s eta 0:00:09
-------------------- ------------------- 6.6/12.9 MB 788.6 kB/s eta 0:00:09
-------------------- ------------------- 6.6/12.9 MB 788.6 kB/s eta 0:00:09
--------------------- ------------------ 6.8/12.9 MB 766.6 kB/s eta 0:00:08
--------------------- ------------------ 6.8/12.9 MB 766.6 kB/s eta 0:00:08
--------------------- ------------------ 6.8/12.9 MB 766.6 kB/s eta 0:00:08
--------------------- ------------------ 7.1/12.9 MB 751.4 kB/s eta 0:00:08
--------------------- ------------------ 7.1/12.9 MB 751.4 kB/s eta 0:00:08
---------------------- ----------------- 7.3/12.9 MB 739.2 kB/s eta 0:00:08
---------------------- ----------------- 7.3/12.9 MB 739.2 kB/s eta 0:00:08
---------------------- ----------------- 7.3/12.9 MB 739.2 kB/s eta 0:00:08
----------------------- ---------------- 7.6/12.9 MB 728.6 kB/s eta 0:00:08
------------------------ --------------- 7.9/12.9 MB 728.4 kB/s eta 0:00:07
------------------------ --------------- 7.9/12.9 MB 728.4 kB/s eta 0:00:07
------------------------- -------------- 8.1/12.9 MB 730.2 kB/s eta 0:00:07
------------------------- -------------- 8.4/12.9 MB 737.0 kB/s eta 0:00:07
------------------------- -------------- 8.4/12.9 MB 737.0 kB/s eta 0:00:07
--------------------------- ------------ 8.9/12.9 MB 754.3 kB/s eta 0:00:06
---------------------------- ----------- 9.2/12.9 MB 764.8 kB/s eta 0:00:05
----------------------------- ---------- 9.4/12.9 MB 775.6 kB/s eta 0:00:05
------------------------------ --------- 9.7/12.9 MB 787.0 kB/s eta 0:00:05
------------------------------- -------- 10.2/12.9 MB 812.7 kB/s eta 0:00:04
--------------------------------- ------ 10.7/12.9 MB 840.2 kB/s eta 0:00:03
---------------------------------- ----- 11.0/12.9 MB 852.6 kB/s eta 0:00:03
---------------------------------- ----- 11.3/12.9 MB 853.6 kB/s eta 0:00:02
----------------------------------- ---- 11.5/12.9 MB 864.6 kB/s eta 0:00:02
------------------------------------ --- 11.8/12.9 MB 871.7 kB/s eta 0:00:02
------------------------------------- -- 12.1/12.9 MB 874.9 kB/s eta 0:00:01
-------------------------------------- - 12.3/12.9 MB 876.5 kB/s eta 0:00:01
-------------------------------------- - 12.6/12.9 MB 887.0 kB/s eta 0:00:01
---------------------------------------- 12.9/12.9 MB 893.3 kB/s 0:00:14
Downloading pillow-12.0.0-cp314-cp314-win_amd64.whl (7.1 MB)
---------------------------------------- 0.0/7.1 MB ? eta -:--:--
---------------------------------------- 0.0/7.1 MB ? eta -:--:--
- -------------------------------------- 0.3/7.1 MB ? eta -:--:--
---- ----------------------------------- 0.8/7.1 MB 1.5 MB/s eta 0:00:05
----- ---------------------------------- 1.0/7.1 MB 1.5 MB/s eta 0:00:05
------- -------------------------------- 1.3/7.1 MB 1.4 MB/s eta 0:00:05
-------- ------------------------------- 1.6/7.1 MB 1.5 MB/s eta 0:00:04
----------- ---------------------------- 2.1/7.1 MB 1.5 MB/s eta 0:00:04
------------- -------------------------- 2.4/7.1 MB 1.5 MB/s eta 0:00:04
-------------- ------------------------- 2.6/7.1 MB 1.5 MB/s eta 0:00:03
---------------- ----------------------- 2.9/7.1 MB 1.5 MB/s eta 0:00:03
---------------- ----------------------- 2.9/7.1 MB 1.5 MB/s eta 0:00:03
----------------- ---------------------- 3.1/7.1 MB 1.4 MB/s eta 0:00:03
------------------- -------------------- 3.4/7.1 MB 1.4 MB/s eta 0:00:03
---------------------- ----------------- 3.9/7.1 MB 1.4 MB/s eta 0:00:03
---------------------- ----------------- 3.9/7.1 MB 1.4 MB/s eta 0:00:03
----------------------- ---------------- 4.2/7.1 MB 1.4 MB/s eta 0:00:03
------------------------ --------------- 4.5/7.1 MB 1.3 MB/s eta 0:00:03
-------------------------- ------------- 4.7/7.1 MB 1.3 MB/s eta 0:00:02
----------------------------- ---------- 5.2/7.1 MB 1.4 MB/s eta 0:00:02
-------------------------------- ------- 5.8/7.1 MB 1.4 MB/s eta 0:00:01
----------------------------------- ---- 6.3/7.1 MB 1.5 MB/s eta 0:00:01
------------------------------------ --- 6.6/7.1 MB 1.5 MB/s eta 0:00:01
---------------------------------------- 7.1/7.1 MB 1.5 MB/s 0:00:04
Downloading pyparsing-3.2.5-py3-none-any.whl (113 kB)
Installing collected packages: pyparsing, pillow, numpy, kiwisolver, fonttools, cycler, contourpy, matplotlib
---------------------------------------- 0/8 [pyparsing]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
----- ---------------------------------- 1/8 [pillow]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
---------- ----------------------------- 2/8 [numpy]
--------------- ------------------------ 3/8 [kiwisolver]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
-------------------- ------------------- 4/8 [fonttools]
------------------------------ --------- 6/8 [contourpy]
------------------------------ --------- 6/8 [contourpy]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
----------------------------------- ---- 7/8 [matplotlib]
---------------------------------------- 8/8 [matplotlib]
Successfully installed contourpy-1.3.3 cycler-0.12.1 fonttools-4.61.0 kiwisolver-1.4.9 matplotlib-3.10.7 numpy-2.3.5 pillow-12.0.0 pyparsing-3.2.5
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[2], line 2 1 get_ipython().system('pip install matplotlib') ----> 2 get_ipython().run_line_magic('matplotlib', 'widget') 3 import matplotlib.pyplot as plt 4 from ipywidgets import Output File D:\anaconda3\envs\jupyter_env\Lib\site-packages\IPython\core\interactiveshell.py:2511, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth) 2509 kwargs['local_ns'] = self.get_local_scope(stack_depth) 2510 with self.builtin_trap: -> 2511 result = fn(*args, **kwargs) 2513 # The code below prevents the output from being displayed 2514 # when using magics with decorator @output_can_be_silenced 2515 # when the last Python token in the expression is a ';'. 2516 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False): File D:\anaconda3\envs\jupyter_env\Lib\site-packages\IPython\core\magics\pylab.py:103, in PylabMagics.matplotlib(self, line) 98 print( 99 "Available matplotlib backends: %s" 100 % _list_matplotlib_backends_and_gui_loops() 101 ) 102 else: --> 103 gui, backend = self.shell.enable_matplotlib(args.gui) 104 self._show_matplotlib_backend(args.gui, backend) File D:\anaconda3\envs\jupyter_env\Lib\site-packages\IPython\core\interactiveshell.py:3801, in InteractiveShell.enable_matplotlib(self, gui) 3797 print('Warning: Cannot change to a different GUI toolkit: %s.' 3798 ' Using %s instead.' % (gui, self.pylab_gui_select)) 3799 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select) -> 3801 pt.activate_matplotlib(backend) 3803 from matplotlib_inline.backend_inline import configure_inline_support 3805 configure_inline_support(self, backend) File D:\anaconda3\envs\jupyter_env\Lib\site-packages\IPython\core\pylabtools.py:402, in activate_matplotlib(backend) 397 matplotlib.interactive(True) 399 # Matplotlib had a bug where even switch_backend could not force 400 # the rcParam to update. This needs to be set *before* the module 401 # magic of switch_backend(). --> 402 matplotlib.rcParams['backend'] = backend 404 # Due to circular imports, pyplot may be only partially initialised 405 # when this function runs. 406 # So avoid needing matplotlib attribute-lookup to access pyplot. 407 from matplotlib import pyplot as plt File D:\anaconda3\envs\jupyter_env\Lib\site-packages\matplotlib\__init__.py:774, in RcParams.__setitem__(self, key, val) 772 cval = self.validate[key](val) 773 except ValueError as ve: --> 774 raise ValueError(f"Key {key}: {ve}") from None 775 self._set(key, cval) 776 except KeyError as err: ValueError: Key backend: 'module://ipympl.backend_nbagg' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template', 'inline']
Overfitting¶
The week's lecture described situations where overfitting can arise. Run the cell below to generate a plot that will allow you to explore overfitting. There are further instructions below the cell.
In [ ]:
plt.close("all")
display(output)
ofit = overfit_example(False)
In the plot above you can:
- switch between Regression and Categorization examples
- add data
- select the degree of the model
- fit the model to the data
Here are some things you should try:
- Fit the data with degree = 1; Note 'underfitting'.
- Fit the data with degree = 6; Note 'overfitting'
- tune degree to get the 'best fit'
- add data:
- extreme examples can increase overfitting (assuming they are outliers).
- nominal examples can reduce overfitting
- switch between
RegressionandCategoricalto try both examples.
To reset the plot, re-run the cell. Click slowly to allow the plot to update before receiving the next click.
Notes on implementations:
- the 'ideal' curves represent the generator model to which noise was added to achieve the data set
- 'fit' does not use pure gradient descent to improve speed. These methods can be used on smaller data sets.
Congratulations!¶
You have developed some intuition about the causes and solutions to overfitting. In the next lab, you will explore a commonly used solution, Regularization.
In [ ]:
In [ ]: