diff --git a/doc/LectureNotes/DataFiles/cancer.dot b/doc/LectureNotes/DataFiles/cancer.dot index 4b5537038..850904527 100644 --- a/doc/LectureNotes/DataFiles/cancer.dot +++ b/doc/LectureNotes/DataFiles/cancer.dot @@ -6,11 +6,11 @@ edge [fontname="helvetica"] ; 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ; 2 [label="worst concave points <= 0.135\ngini = 0.031\nsamples = 253\nvalue = [[249, 4]\n[4, 249]]", fillcolor="#e78946"] ; 1 -> 2 ; -3 [label="area error <= 48.975\ngini = 0.008\nsamples = 242\nvalue = [[241, 1]\n[1, 241]]", fillcolor="#e5833c"] ; +3 [label="radius error <= 0.643\ngini = 0.008\nsamples = 242\nvalue = [[241, 1]\n[1, 241]]", fillcolor="#e5833c"] ; 2 -> 3 ; 4 [label="gini = 0.0\nsamples = 239\nvalue = [[239, 0]\n[0, 239]]", fillcolor="#e58139"] ; 3 -> 4 ; -5 [label="radius error <= 0.688\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#fdf6f0"] ; +5 [label="worst area <= 566.55\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#fdf6f0"] ; 3 -> 5 ; 6 [label="gini = 0.0\nsamples = 1\nvalue = [[0, 1]\n[1, 0]]", fillcolor="#e58139"] ; 5 -> 6 ; @@ -34,7 +34,7 @@ edge [fontname="helvetica"] ; 14 -> 15 ; 16 [label="gini = 0.0\nsamples = 11\nvalue = [[11, 0]\n[0, 11]]", fillcolor="#e58139"] ; 15 -> 16 ; -17 [label="area error <= 23.16\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#f6d5bd"] ; +17 [label="radius error <= 0.251\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#f6d5bd"] ; 15 -> 17 ; 18 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139"] ; 17 -> 18 ; @@ -48,10 +48,10 @@ edge [fontname="helvetica"] ; 21 -> 22 ; 23 [label="gini = 0.0\nsamples = 6\nvalue = [[6, 0]\n[0, 6]]", fillcolor="#e58139"] ; 21 -> 23 ; -24 [label="mean smoothness <= 0.079\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e6853f"] ; +24 [label="fractal dimension error <= 0.013\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e6853f"] ; 20 -> 24 ; -25 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139"] ; +25 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139"] ; 24 -> 25 ; -26 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139"] ; +26 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139"] ; 24 -> 26 ; } \ No newline at end of file diff --git a/doc/LectureNotes/DataFiles/cancer.png b/doc/LectureNotes/DataFiles/cancer.png index fa5789786..cbf1fc251 100644 Binary files a/doc/LectureNotes/DataFiles/cancer.png and b/doc/LectureNotes/DataFiles/cancer.png differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter1.doctree b/doc/LectureNotes/_build/.doctrees/chapter1.doctree index d90b7dccd..3c144649c 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter1.doctree and b/doc/LectureNotes/_build/.doctrees/chapter1.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter10.doctree b/doc/LectureNotes/_build/.doctrees/chapter10.doctree index 58dc88dbd..93a600560 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter10.doctree and b/doc/LectureNotes/_build/.doctrees/chapter10.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter13.doctree b/doc/LectureNotes/_build/.doctrees/chapter13.doctree index 33be68254..06c911ecd 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter13.doctree and b/doc/LectureNotes/_build/.doctrees/chapter13.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter2.doctree b/doc/LectureNotes/_build/.doctrees/chapter2.doctree index 4bbb90a61..2fe5a8a9f 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter2.doctree and b/doc/LectureNotes/_build/.doctrees/chapter2.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter3.doctree b/doc/LectureNotes/_build/.doctrees/chapter3.doctree index d99a40a5b..efad422b5 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter3.doctree and b/doc/LectureNotes/_build/.doctrees/chapter3.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter6.doctree b/doc/LectureNotes/_build/.doctrees/chapter6.doctree index bd57c6ceb..7e667d78d 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter6.doctree and b/doc/LectureNotes/_build/.doctrees/chapter6.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/chapter8.doctree b/doc/LectureNotes/_build/.doctrees/chapter8.doctree index f2a4c91fe..2d0471444 100644 Binary files a/doc/LectureNotes/_build/.doctrees/chapter8.doctree and b/doc/LectureNotes/_build/.doctrees/chapter8.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/environment.pickle b/doc/LectureNotes/_build/.doctrees/environment.pickle index bc59ec815..7892d29a1 100644 Binary files a/doc/LectureNotes/_build/.doctrees/environment.pickle and b/doc/LectureNotes/_build/.doctrees/environment.pickle differ diff --git a/doc/LectureNotes/_build/.doctrees/exercisesweek41.doctree b/doc/LectureNotes/_build/.doctrees/exercisesweek41.doctree index 585532318..575a1bdd6 100644 Binary files a/doc/LectureNotes/_build/.doctrees/exercisesweek41.doctree and b/doc/LectureNotes/_build/.doctrees/exercisesweek41.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/exercisesweek48.doctree b/doc/LectureNotes/_build/.doctrees/exercisesweek48.doctree new file mode 100644 index 000000000..68290fd03 Binary files /dev/null and b/doc/LectureNotes/_build/.doctrees/exercisesweek48.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/intro.doctree b/doc/LectureNotes/_build/.doctrees/intro.doctree index ee7697b6e..1c8570514 100644 Binary files a/doc/LectureNotes/_build/.doctrees/intro.doctree and b/doc/LectureNotes/_build/.doctrees/intro.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/linalg.doctree b/doc/LectureNotes/_build/.doctrees/linalg.doctree index a4392d50e..305295e89 100644 Binary files a/doc/LectureNotes/_build/.doctrees/linalg.doctree and b/doc/LectureNotes/_build/.doctrees/linalg.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/statistics.doctree b/doc/LectureNotes/_build/.doctrees/statistics.doctree index 37627bc3f..3bcbef17b 100644 Binary files a/doc/LectureNotes/_build/.doctrees/statistics.doctree and b/doc/LectureNotes/_build/.doctrees/statistics.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week34.doctree b/doc/LectureNotes/_build/.doctrees/week34.doctree index fb03120b0..6249ae8b7 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week34.doctree and b/doc/LectureNotes/_build/.doctrees/week34.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week35.doctree b/doc/LectureNotes/_build/.doctrees/week35.doctree index e822b152c..957fcfc01 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week35.doctree and b/doc/LectureNotes/_build/.doctrees/week35.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week37.doctree b/doc/LectureNotes/_build/.doctrees/week37.doctree index 80553fbd0..6df8d0e73 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week37.doctree and b/doc/LectureNotes/_build/.doctrees/week37.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week39.doctree b/doc/LectureNotes/_build/.doctrees/week39.doctree index 0d9cf5aa5..81d3022a3 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week39.doctree and b/doc/LectureNotes/_build/.doctrees/week39.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week40.doctree b/doc/LectureNotes/_build/.doctrees/week40.doctree index af1ed3ef7..0b7fc2fc9 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week40.doctree and b/doc/LectureNotes/_build/.doctrees/week40.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week42.doctree b/doc/LectureNotes/_build/.doctrees/week42.doctree index 23d8aa356..90ee6fd12 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week42.doctree and b/doc/LectureNotes/_build/.doctrees/week42.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week43.doctree b/doc/LectureNotes/_build/.doctrees/week43.doctree index c8325c633..25046890d 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week43.doctree and b/doc/LectureNotes/_build/.doctrees/week43.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week44.doctree b/doc/LectureNotes/_build/.doctrees/week44.doctree index 3e22afb1f..aff677bf1 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week44.doctree and b/doc/LectureNotes/_build/.doctrees/week44.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week45.doctree b/doc/LectureNotes/_build/.doctrees/week45.doctree index 4163c17f6..881f73b86 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week45.doctree and b/doc/LectureNotes/_build/.doctrees/week45.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week46.doctree b/doc/LectureNotes/_build/.doctrees/week46.doctree index 878e9bd7f..025425407 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week46.doctree and b/doc/LectureNotes/_build/.doctrees/week46.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week47.doctree b/doc/LectureNotes/_build/.doctrees/week47.doctree index bfd1bc7d6..10c711481 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week47.doctree and b/doc/LectureNotes/_build/.doctrees/week47.doctree differ diff --git a/doc/LectureNotes/_build/.doctrees/week48.doctree b/doc/LectureNotes/_build/.doctrees/week48.doctree new file mode 100644 index 000000000..174aa10f3 Binary files /dev/null and b/doc/LectureNotes/_build/.doctrees/week48.doctree differ diff --git a/doc/LectureNotes/_build/html/_images/01d44d8b3777894a56df96cdebd9411c2a9b9484e40698be0bb84652c7d0f7cf.png b/doc/LectureNotes/_build/html/_images/01d44d8b3777894a56df96cdebd9411c2a9b9484e40698be0bb84652c7d0f7cf.png new file mode 100644 index 000000000..7d19b04dc Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/01d44d8b3777894a56df96cdebd9411c2a9b9484e40698be0bb84652c7d0f7cf.png differ diff --git a/doc/LectureNotes/_build/html/_images/1baae63cbdd15ce7abeb765e3d3adddddca04d8f36b9292d03ad703844b287d4.png b/doc/LectureNotes/_build/html/_images/1baae63cbdd15ce7abeb765e3d3adddddca04d8f36b9292d03ad703844b287d4.png new file mode 100644 index 000000000..a629c931a Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/1baae63cbdd15ce7abeb765e3d3adddddca04d8f36b9292d03ad703844b287d4.png differ diff --git a/doc/LectureNotes/_build/html/_images/1f1e999736d47a2811569158c3eb924dab62b0f520b0f854e48f2e2dbb32e047.png b/doc/LectureNotes/_build/html/_images/1f1e999736d47a2811569158c3eb924dab62b0f520b0f854e48f2e2dbb32e047.png new file mode 100644 index 000000000..6de1285d9 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/1f1e999736d47a2811569158c3eb924dab62b0f520b0f854e48f2e2dbb32e047.png differ diff --git a/doc/LectureNotes/_build/html/_images/326bc2bdd25593d0947bbe11be557f7c976fd425b872153c8c8317ebbb51c5ae.png b/doc/LectureNotes/_build/html/_images/326bc2bdd25593d0947bbe11be557f7c976fd425b872153c8c8317ebbb51c5ae.png new file mode 100644 index 000000000..5fd1cc030 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/326bc2bdd25593d0947bbe11be557f7c976fd425b872153c8c8317ebbb51c5ae.png differ diff --git a/doc/LectureNotes/_build/html/_images/327366ea5051007f61df82fc528a36028c298264f7cb3d1565bb97cd4c20255c.png b/doc/LectureNotes/_build/html/_images/327366ea5051007f61df82fc528a36028c298264f7cb3d1565bb97cd4c20255c.png new file mode 100644 index 000000000..487ca80d3 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/327366ea5051007f61df82fc528a36028c298264f7cb3d1565bb97cd4c20255c.png differ diff --git a/doc/LectureNotes/_build/html/_images/3430c2e5bb18ad9f457af6ed6748c3fa16381ffd0271ca7c0c248e53b04e0fe6.png b/doc/LectureNotes/_build/html/_images/3430c2e5bb18ad9f457af6ed6748c3fa16381ffd0271ca7c0c248e53b04e0fe6.png new file mode 100644 index 000000000..850571d2e Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/3430c2e5bb18ad9f457af6ed6748c3fa16381ffd0271ca7c0c248e53b04e0fe6.png differ diff --git a/doc/LectureNotes/_build/html/_images/3a39cedd7df8be523efd25c1ba51760790f33378dd9e7a9d1eff178bc4b629e1.png b/doc/LectureNotes/_build/html/_images/3a39cedd7df8be523efd25c1ba51760790f33378dd9e7a9d1eff178bc4b629e1.png new file mode 100644 index 000000000..db9988633 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/3a39cedd7df8be523efd25c1ba51760790f33378dd9e7a9d1eff178bc4b629e1.png differ diff --git a/doc/LectureNotes/_build/html/_images/429975495ea036cdaa180dafa8c2225aba5cd58c9c9a67fe5998acd764007772.png b/doc/LectureNotes/_build/html/_images/429975495ea036cdaa180dafa8c2225aba5cd58c9c9a67fe5998acd764007772.png new file mode 100644 index 000000000..4981f1c6b Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/429975495ea036cdaa180dafa8c2225aba5cd58c9c9a67fe5998acd764007772.png differ diff --git a/doc/LectureNotes/_build/html/_images/45972a93ed8e1f6ed66fe9c322a65b549b39dd2c80e16d5081151b2bc713b669.png b/doc/LectureNotes/_build/html/_images/45972a93ed8e1f6ed66fe9c322a65b549b39dd2c80e16d5081151b2bc713b669.png new file mode 100644 index 000000000..9b9116f65 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/45972a93ed8e1f6ed66fe9c322a65b549b39dd2c80e16d5081151b2bc713b669.png differ diff --git a/doc/LectureNotes/_build/html/_images/467927f86cd8a5304cb2f39dbf480015e72d87541abf390f2a0eb8672b465f1e.png b/doc/LectureNotes/_build/html/_images/467927f86cd8a5304cb2f39dbf480015e72d87541abf390f2a0eb8672b465f1e.png new file mode 100644 index 000000000..64fa154a1 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/467927f86cd8a5304cb2f39dbf480015e72d87541abf390f2a0eb8672b465f1e.png differ diff --git a/doc/LectureNotes/_build/html/_images/46a1fad1ccb7c31a75875feb55a5327e9f0ae2b02295543e814d1b2fc23ab459.png b/doc/LectureNotes/_build/html/_images/46a1fad1ccb7c31a75875feb55a5327e9f0ae2b02295543e814d1b2fc23ab459.png new file mode 100644 index 000000000..d40facd6c Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/46a1fad1ccb7c31a75875feb55a5327e9f0ae2b02295543e814d1b2fc23ab459.png differ diff --git a/doc/LectureNotes/_build/html/_images/4b551662b71f36e771bedba88b8176e1bd7b16262de80f1445234d9175a77e42.png b/doc/LectureNotes/_build/html/_images/4b551662b71f36e771bedba88b8176e1bd7b16262de80f1445234d9175a77e42.png new file mode 100644 index 000000000..dd922b591 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/4b551662b71f36e771bedba88b8176e1bd7b16262de80f1445234d9175a77e42.png differ diff --git a/doc/LectureNotes/_build/html/_images/5a1776c87da1ba203336178287b47b42ec33ec260ba18e3e2bb9d9f8ed8c8134.png b/doc/LectureNotes/_build/html/_images/5a1776c87da1ba203336178287b47b42ec33ec260ba18e3e2bb9d9f8ed8c8134.png new file mode 100644 index 000000000..ee6cd5561 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/5a1776c87da1ba203336178287b47b42ec33ec260ba18e3e2bb9d9f8ed8c8134.png differ diff --git a/doc/LectureNotes/_build/html/_images/5cfc76ca7e820abfb8e15070adf2fa59d6dcfb6d702ef48441625e67b326e24c.png b/doc/LectureNotes/_build/html/_images/5cfc76ca7e820abfb8e15070adf2fa59d6dcfb6d702ef48441625e67b326e24c.png new file mode 100644 index 000000000..ff0156015 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/5cfc76ca7e820abfb8e15070adf2fa59d6dcfb6d702ef48441625e67b326e24c.png differ diff --git a/doc/LectureNotes/_build/html/_images/6221ee55bb26dba5cef5540ef9967df02eb119abda11c5c5903f7762c8c9f763.png b/doc/LectureNotes/_build/html/_images/6221ee55bb26dba5cef5540ef9967df02eb119abda11c5c5903f7762c8c9f763.png new file mode 100644 index 000000000..a7415a1c5 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/6221ee55bb26dba5cef5540ef9967df02eb119abda11c5c5903f7762c8c9f763.png differ diff --git a/doc/LectureNotes/_build/html/_images/71a39e681516930bc9bdd50d3be601c8226c85a4b39549563a05614380c05e0c.png b/doc/LectureNotes/_build/html/_images/71a39e681516930bc9bdd50d3be601c8226c85a4b39549563a05614380c05e0c.png new file mode 100644 index 000000000..852da06f0 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/71a39e681516930bc9bdd50d3be601c8226c85a4b39549563a05614380c05e0c.png differ diff --git a/doc/LectureNotes/_build/html/_images/74585d2c5d042ce0364bf21b5a8e9bc5b5504011eaa4a30c445a4415a4c1df98.png b/doc/LectureNotes/_build/html/_images/74585d2c5d042ce0364bf21b5a8e9bc5b5504011eaa4a30c445a4415a4c1df98.png new file mode 100644 index 000000000..a0e4e0fdb Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/74585d2c5d042ce0364bf21b5a8e9bc5b5504011eaa4a30c445a4415a4c1df98.png differ diff --git a/doc/LectureNotes/_build/html/_images/796ded1719cb864b630c37e7692028ee18f0df7fb5a0ed2de15817b0c2f36c0c.png b/doc/LectureNotes/_build/html/_images/796ded1719cb864b630c37e7692028ee18f0df7fb5a0ed2de15817b0c2f36c0c.png new file mode 100644 index 000000000..c657ba3d0 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/796ded1719cb864b630c37e7692028ee18f0df7fb5a0ed2de15817b0c2f36c0c.png differ diff --git a/doc/LectureNotes/_build/html/_images/81f5882581a53e21f2c20be0ef5d63c90956ddfe5d34db4fb8f83012ab7b8c4a.png b/doc/LectureNotes/_build/html/_images/81f5882581a53e21f2c20be0ef5d63c90956ddfe5d34db4fb8f83012ab7b8c4a.png new file mode 100644 index 000000000..a29460226 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/81f5882581a53e21f2c20be0ef5d63c90956ddfe5d34db4fb8f83012ab7b8c4a.png differ diff --git a/doc/LectureNotes/_build/html/_images/82abcfe355d89bb3d7dd4eb6e9ffe48d1f3f3511015d80687fbe0db1b8fd5999.png b/doc/LectureNotes/_build/html/_images/82abcfe355d89bb3d7dd4eb6e9ffe48d1f3f3511015d80687fbe0db1b8fd5999.png new file mode 100644 index 000000000..167354e62 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/82abcfe355d89bb3d7dd4eb6e9ffe48d1f3f3511015d80687fbe0db1b8fd5999.png differ diff --git a/doc/LectureNotes/_build/html/_images/8e8566a48272bbcd741d192ea8f10c53172ad3cba8f805ceb38c6695c7dd5c2d.png b/doc/LectureNotes/_build/html/_images/8e8566a48272bbcd741d192ea8f10c53172ad3cba8f805ceb38c6695c7dd5c2d.png new file mode 100644 index 000000000..bcd92e75f Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/8e8566a48272bbcd741d192ea8f10c53172ad3cba8f805ceb38c6695c7dd5c2d.png differ diff --git a/doc/LectureNotes/_build/html/_images/8f696a60652d0003039dd9a563eb80367f1d574ca15b61c7a3f9757b19083d26.png b/doc/LectureNotes/_build/html/_images/8f696a60652d0003039dd9a563eb80367f1d574ca15b61c7a3f9757b19083d26.png new file mode 100644 index 000000000..f03292924 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/8f696a60652d0003039dd9a563eb80367f1d574ca15b61c7a3f9757b19083d26.png differ diff --git a/doc/LectureNotes/_build/html/_images/936367d3bdcae10aafd2cc903d30ce54287b55ddddaa7af46f455a620a3745cd.png b/doc/LectureNotes/_build/html/_images/936367d3bdcae10aafd2cc903d30ce54287b55ddddaa7af46f455a620a3745cd.png new file mode 100644 index 000000000..fbc35701e Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/936367d3bdcae10aafd2cc903d30ce54287b55ddddaa7af46f455a620a3745cd.png differ diff --git a/doc/LectureNotes/_build/html/_images/9369a99fab3ad63476a60dda7c34258ee45c7d9980558aabda81b593e0a3d307.png b/doc/LectureNotes/_build/html/_images/9369a99fab3ad63476a60dda7c34258ee45c7d9980558aabda81b593e0a3d307.png new file mode 100644 index 000000000..43bfca158 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/9369a99fab3ad63476a60dda7c34258ee45c7d9980558aabda81b593e0a3d307.png differ diff --git a/doc/LectureNotes/_build/html/_images/99bd4e87bbb54a5fb018ef916c872e3158711414d535c467a50d947ace53c954.png b/doc/LectureNotes/_build/html/_images/99bd4e87bbb54a5fb018ef916c872e3158711414d535c467a50d947ace53c954.png new file mode 100644 index 000000000..d975c044d Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/99bd4e87bbb54a5fb018ef916c872e3158711414d535c467a50d947ace53c954.png differ diff --git a/doc/LectureNotes/_build/html/_images/a9306da9994b47ad9b17c6ed3244dbd079e10a74b85153831b07c9570b8677c3.png b/doc/LectureNotes/_build/html/_images/a9306da9994b47ad9b17c6ed3244dbd079e10a74b85153831b07c9570b8677c3.png new file mode 100644 index 000000000..3b40ab770 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/a9306da9994b47ad9b17c6ed3244dbd079e10a74b85153831b07c9570b8677c3.png differ diff --git a/doc/LectureNotes/_build/html/_images/b27afd9b9c2cb0727463c018ad254fd8be50dfbc3e2597029b6cb3b42667fdb5.png b/doc/LectureNotes/_build/html/_images/b27afd9b9c2cb0727463c018ad254fd8be50dfbc3e2597029b6cb3b42667fdb5.png new file mode 100644 index 000000000..da78f7f91 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/b27afd9b9c2cb0727463c018ad254fd8be50dfbc3e2597029b6cb3b42667fdb5.png differ diff --git a/doc/LectureNotes/_build/html/_images/b39b8ed8a4aed5f4a94d2137c267e12d64d23f66d1c50c3e3ad1ae8cd8b9ff5e.png b/doc/LectureNotes/_build/html/_images/b39b8ed8a4aed5f4a94d2137c267e12d64d23f66d1c50c3e3ad1ae8cd8b9ff5e.png new file mode 100644 index 000000000..47d8ddf98 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/b39b8ed8a4aed5f4a94d2137c267e12d64d23f66d1c50c3e3ad1ae8cd8b9ff5e.png differ diff --git a/doc/LectureNotes/_build/html/_images/b4424ef99a3917f39ceb54b5132d60d97fff9ed86b004003694a9733a9d7e3c2.png b/doc/LectureNotes/_build/html/_images/b4424ef99a3917f39ceb54b5132d60d97fff9ed86b004003694a9733a9d7e3c2.png new file mode 100644 index 000000000..c6eefe4af Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/b4424ef99a3917f39ceb54b5132d60d97fff9ed86b004003694a9733a9d7e3c2.png differ diff --git a/doc/LectureNotes/_build/html/_images/bae16b30a452ef5c69ddef05f0de3bbba23676920f8affa40a5a964be4504dd8.png b/doc/LectureNotes/_build/html/_images/bae16b30a452ef5c69ddef05f0de3bbba23676920f8affa40a5a964be4504dd8.png new file mode 100644 index 000000000..52cd1cb73 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/bae16b30a452ef5c69ddef05f0de3bbba23676920f8affa40a5a964be4504dd8.png differ diff --git a/doc/LectureNotes/_build/html/_images/be8d5df8bb940da757ef8fd6eac65ebe0352641500f781f4284c949ce274e1ee.png b/doc/LectureNotes/_build/html/_images/be8d5df8bb940da757ef8fd6eac65ebe0352641500f781f4284c949ce274e1ee.png new file mode 100644 index 000000000..cec8fde9e Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/be8d5df8bb940da757ef8fd6eac65ebe0352641500f781f4284c949ce274e1ee.png differ diff --git a/doc/LectureNotes/_build/html/_images/c61bca31ee6787e0e5d1512e4bf365143d789096f02da0a858ff7e7c3834630c.png b/doc/LectureNotes/_build/html/_images/c61bca31ee6787e0e5d1512e4bf365143d789096f02da0a858ff7e7c3834630c.png new file mode 100644 index 000000000..1da5d62cd Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/c61bca31ee6787e0e5d1512e4bf365143d789096f02da0a858ff7e7c3834630c.png differ diff --git a/doc/LectureNotes/_build/html/_images/d213fd49b73afa7db6fe63b54689d9b6c4aff1adac65c06e412ebb9574c86d39.png b/doc/LectureNotes/_build/html/_images/d213fd49b73afa7db6fe63b54689d9b6c4aff1adac65c06e412ebb9574c86d39.png new file mode 100644 index 000000000..24afd36e2 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/d213fd49b73afa7db6fe63b54689d9b6c4aff1adac65c06e412ebb9574c86d39.png differ diff --git a/doc/LectureNotes/_build/html/_images/e0c9e5cfc32bfe482c04b2091d5d98aa80212c0eef5e22892d16f73e93be8afc.png b/doc/LectureNotes/_build/html/_images/e0c9e5cfc32bfe482c04b2091d5d98aa80212c0eef5e22892d16f73e93be8afc.png new file mode 100644 index 000000000..3f43b901f Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/e0c9e5cfc32bfe482c04b2091d5d98aa80212c0eef5e22892d16f73e93be8afc.png differ diff --git a/doc/LectureNotes/_build/html/_images/eb601133698cb5198be6ed45531c33666c9fa7198b8b8a8e59f3cf4e95ddc8eb.png b/doc/LectureNotes/_build/html/_images/eb601133698cb5198be6ed45531c33666c9fa7198b8b8a8e59f3cf4e95ddc8eb.png new file mode 100644 index 000000000..f3f2dbe7c Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/eb601133698cb5198be6ed45531c33666c9fa7198b8b8a8e59f3cf4e95ddc8eb.png differ diff --git a/doc/LectureNotes/_build/html/_sources/exercisesweek48.ipynb b/doc/LectureNotes/_build/html/_sources/exercisesweek48.ipynb new file mode 100644 index 000000000..96805589d --- /dev/null +++ b/doc/LectureNotes/_build/html/_sources/exercisesweek48.ipynb @@ -0,0 +1,229 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "30071d16", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "268eaea0", + "metadata": { + "editable": true + }, + "source": [ + "# Exercises week 48\n", + "**November 25-29, 2024**\n", + "\n", + "Date: **Deadline is Friday November 29 at midnight**" + ] + }, + { + "cell_type": "markdown", + "id": "1e04cbee", + "metadata": { + "editable": true + }, + "source": [ + "# Overarching aims of the exercises this week\n", + "\n", + "The exercise this week is a simple course survey and feedback. This\n", + "is important for us in order to improve our teaching material, the\n", + "active learning format and anything else related to a succesful\n", + "mastering of central machine learning methods and their applications." + ] + }, + { + "cell_type": "markdown", + "id": "78363328", + "metadata": { + "editable": true + }, + "source": [ + "### Why did you choose this course?" + ] + }, + { + "cell_type": "markdown", + "id": "d4950ede", + "metadata": { + "editable": true + }, + "source": [ + "### What was your programming knowledge before you started?\n", + "\n", + "And do you feel this course added to your programming competences and skills?" + ] + }, + { + "cell_type": "markdown", + "id": "95e23f0c", + "metadata": { + "editable": true + }, + "source": [ + "### How do you judge your own level of knowledge on machine learning before and after this course?\n", + "\n", + "Here you can discuss your level of skill/knowledge at the start of course\n", + "and at the end of the course and how these matched the level of\n", + "skill/knowledge needed to complete the projects." + ] + }, + { + "cell_type": "markdown", + "id": "db819721", + "metadata": { + "editable": true + }, + "source": [ + "### Did the projects and the teaching material allow you to deepen your insights about Machine Learning methods?\n", + "\n", + "Feel free to comment here." + ] + }, + { + "cell_type": "markdown", + "id": "61d153a4", + "metadata": { + "editable": true + }, + "source": [ + "### Project based teaching and active learning\n", + "\n", + "This is a project based course and we as teachers would like to keep\n", + "it as it is since we see very clearly that people who attend this\n", + "course have a very good learning outcome. Project based courses are\n", + "however demanding (and expensive seen from the university admin) when\n", + "it comes to proper feedback and evaluations. Feel free to discuss\n", + "whether you found a project-based useful. Feel also free to comment upon things we can improve upon or\n", + "alternative ways to assess whether the learning outcomes have been\n", + "achieved. Would you for example prefer a standard 4 hours written exam\n", + "be something you would prefer? Or other alternatives to projects? We\n", + "would very much value your thoughts here since projects are an\n", + "essential part of this course." + ] + }, + { + "cell_type": "markdown", + "id": "ee1af3ff", + "metadata": { + "editable": true + }, + "source": [ + "### Usefulness of the weekly exercises\n", + "\n", + "Did the weekly exercises help in getting started with the projects?\n", + "How relevant where they for solving the projects? Feel free to\n", + "elaborate" + ] + }, + { + "cell_type": "markdown", + "id": "46a35899", + "metadata": { + "editable": true + }, + "source": [ + "### Lab sessions and lectures\n", + "\n", + "Was there a good link between lectures and lab sessions?\n", + "Feel\n", + "free to comment." + ] + }, + { + "cell_type": "markdown", + "id": "f6524f03", + "metadata": { + "editable": true + }, + "source": [ + "### How would you improve this course?\n", + "\n", + "Are there topics which are missing, topics which could have been\n", + "omitted and/or discussed in more depth? Feel free to add your comments\n", + "here such as how to improve to teaching material and more." + ] + }, + { + "cell_type": "markdown", + "id": "ab89b772", + "metadata": { + "editable": true + }, + "source": [ + "## Then some basic questions" + ] + }, + { + "cell_type": "markdown", + "id": "9811e1b4", + "metadata": { + "editable": true + }, + "source": [ + "### Which is your preferred information chanel, Canvas, Discord, mail or other?" + ] + }, + { + "cell_type": "markdown", + "id": "6a3741fa", + "metadata": { + "editable": true + }, + "source": [ + "### Was the weekly update with plans etc useful?" + ] + }, + { + "cell_type": "markdown", + "id": "a51df0b9", + "metadata": { + "editable": true + }, + "source": [ + "### Was it easy to access the course material?" + ] + }, + { + "cell_type": "markdown", + "id": "762d5153", + "metadata": { + "editable": true + }, + "source": [ + "### Which resources and tools did you use? Jupyter-notebooks, GitHub, the various textbooks we have recommended, etc etc" + ] + }, + { + "cell_type": "markdown", + "id": "2bf11aae", + "metadata": { + "editable": true + }, + "source": [ + "### If you did not attend the lectures or the lab sessions, which resources did you use?" + ] + }, + { + "cell_type": "markdown", + "id": "3f92f5ff", + "metadata": { + "editable": true + }, + "source": [ + "### Any other topics, impressions, ideas etc you would like to share with us?" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/doc/LectureNotes/_build/html/_sources/week48.ipynb b/doc/LectureNotes/_build/html/_sources/week48.ipynb new file mode 100644 index 000000000..c0298d422 --- /dev/null +++ b/doc/LectureNotes/_build/html/_sources/week48.ipynb @@ -0,0 +1,2818 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d7c532d5", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "d27ab2b4", + "metadata": { + "editable": true + }, + "source": [ + "# Week 48: Gradient boosting and summary of course\n", + "**Morten Hjorth-Jensen**, Department of Physics and Center for Computing in Science Education, University of Oslo, Norway\n", + "\n", + "Date: **Nov 24, 2024**\n", + "\n", + "Copyright 1999-2024, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license" + ] + }, + { + "cell_type": "markdown", + "id": "9f55b05a", + "metadata": { + "editable": true + }, + "source": [ + "## Overview of week 48" + ] + }, + { + "cell_type": "markdown", + "id": "e72578f8", + "metadata": { + "editable": true + }, + "source": [ + "## Lecture Monday, November 25\n", + "**Plans for the lecture Monday 25 November, with video suggestions etc.**\n", + "\n", + "1. Boosting and gradient boosting and ensemble models\n", + "\n", + "2. Summary of course\n", + "\n", + "3. Readings and Videos:\n", + "\n", + "a. These lecture notes at \n", + "\n", + "b. See also lecture notes from week 47 at . The lecture on Monday starts with a repetition on AdaBoost before we move over to gradient boosting with examples\n", + "\n", + "\n", + "\n", + "c. Video on Decision trees \n", + "\n", + "d. Video on boosting methods \n", + "\n", + "e. Video on AdaBoost \n", + "\n", + "f. Video on Gradient boost, part 1, parts 2-4 follow thereafter \n", + "\n", + "g. Decision Trees: Rashcka et al chapter 3 pages 86-98, and chapter 7 on Ensemble methods, Voting and Bagging and Gradient Boosting. See also lecture from STK-IN4300, lecture 7 at ." + ] + }, + { + "cell_type": "markdown", + "id": "51ee8fb3", + "metadata": { + "editable": true + }, + "source": [ + "## Lab sessions\n", + "**Lab sessions on Tuesday and Wednesday.**\n", + "\n", + " * Work and Discussion of project 3\n", + "\n", + " * Last weekly exercise\n", + "\n", + " * Lab sessions at usual times.\n", + "\n", + " * For the week of December 2-6, lab sessions start at 10am and end at 4pm, room FØ434, Tuesday and Wednesday" + ] + }, + { + "cell_type": "markdown", + "id": "5b4ed2be", + "metadata": { + "editable": true + }, + "source": [ + "## Random Forest Algorithm, reminder from last week\n", + "\n", + "The algorithm described here can be applied to both classification and regression problems.\n", + "\n", + "We will grow of forest of say $B$ trees.\n", + "* For $b=1:B$\n", + "\n", + "a. Draw a bootstrap sample from the training data organized in our $\\boldsymbol{X}$ matrix.\n", + "\n", + "b. We grow then a random forest tree $T_b$ based on the bootstrapped data by repeating the steps outlined till we reach the maximum node size is reached\n", + "\n", + "1. we select $m \\le p$ variables at random from the $p$ predictors/features\n", + "\n", + "2. pick the best split point among the $m$ features using for example the CART algorithm and create a new node\n", + "\n", + "3. split the node into daughter nodes\n", + "\n", + "Finally we output then the ensemble of trees $\\{T_b\\}_1^{B}$ and make predictions for either a regression type of problem or a classification type of problem." + ] + }, + { + "cell_type": "markdown", + "id": "3e76e282", + "metadata": { + "editable": true + }, + "source": [ + "## Random Forests Compared with other Methods on the Cancer Data" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "acba62b3", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split \n", + "from sklearn.datasets import load_breast_cancer\n", + "from sklearn.svm import SVC\n", + "from sklearn.linear_model import LogisticRegression\n", + "from sklearn.tree import DecisionTreeClassifier\n", + "from sklearn.ensemble import BaggingClassifier\n", + "\n", + "# Load the data\n", + "cancer = load_breast_cancer()\n", + "\n", + "X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)\n", + "print(X_train.shape)\n", + "print(X_test.shape)\n", + "#define methods\n", + "# Logistic Regression\n", + "logreg = LogisticRegression(solver='lbfgs')\n", + "# Support vector machine\n", + "svm = SVC(gamma='auto', C=100)\n", + "# Decision Trees\n", + "deep_tree_clf = DecisionTreeClassifier(max_depth=None)\n", + "#Scale the data\n", + "from sklearn.preprocessing import StandardScaler\n", + "scaler = StandardScaler()\n", + "scaler.fit(X_train)\n", + "X_train_scaled = scaler.transform(X_train)\n", + "X_test_scaled = scaler.transform(X_test)\n", + "# Logistic Regression\n", + "logreg.fit(X_train_scaled, y_train)\n", + "print(\"Test set accuracy Logistic Regression with scaled data: {:.2f}\".format(logreg.score(X_test_scaled,y_test)))\n", + "# Support Vector Machine\n", + "svm.fit(X_train_scaled, y_train)\n", + "print(\"Test set accuracy SVM with scaled data: {:.2f}\".format(logreg.score(X_test_scaled,y_test)))\n", + "# Decision Trees\n", + "deep_tree_clf.fit(X_train_scaled, y_train)\n", + "print(\"Test set accuracy with Decision Trees and scaled data: {:.2f}\".format(deep_tree_clf.score(X_test_scaled,y_test)))\n", + "\n", + "\n", + "from sklearn.ensemble import RandomForestClassifier\n", + "from sklearn.preprocessing import LabelEncoder\n", + "from sklearn.model_selection import cross_validate\n", + "# Data set not specificied\n", + "#Instantiate the model with 500 trees and entropy as splitting criteria\n", + "Random_Forest_model = RandomForestClassifier(n_estimators=500,criterion=\"entropy\")\n", + "Random_Forest_model.fit(X_train_scaled, y_train)\n", + "#Cross validation\n", + "accuracy = cross_validate(Random_Forest_model,X_test_scaled,y_test,cv=10)['test_score']\n", + "print(accuracy)\n", + "print(\"Test set accuracy with Random Forests and scaled data: {:.2f}\".format(Random_Forest_model.score(X_test_scaled,y_test)))\n", + "\n", + "\n", + "import scikitplot as skplt\n", + "y_pred = Random_Forest_model.predict(X_test_scaled)\n", + "skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n", + "plt.show()\n", + "y_probas = Random_Forest_model.predict_proba(X_test_scaled)\n", + "skplt.metrics.plot_roc(y_test, y_probas)\n", + "plt.show()\n", + "skplt.metrics.plot_cumulative_gain(y_test, y_probas)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "c5cbe0e8", + "metadata": { + "editable": true + }, + "source": [ + "Recall that the cumulative gains curve shows the percentage of the\n", + "overall number of cases in a given category *gained* by targeting a\n", + "percentage of the total number of cases.\n", + "\n", + "Similarly, the receiver operating characteristic curve, or ROC curve,\n", + "displays the diagnostic ability of a binary classifier system as its\n", + "discrimination threshold is varied. It plots the true positive rate against the false positive rate." + ] + }, + { + "cell_type": "markdown", + "id": "19bd77f2", + "metadata": { + "editable": true + }, + "source": [ + "## Compare Bagging on Trees with Random Forests" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "84f1af2e", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "bag_clf = BaggingClassifier(\n", + " DecisionTreeClassifier(splitter=\"random\", max_leaf_nodes=16, random_state=42),\n", + " n_estimators=500, max_samples=1.0, bootstrap=True, n_jobs=-1, random_state=42)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "6c01d900", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "bag_clf.fit(X_train, y_train)\n", + "y_pred = bag_clf.predict(X_test)\n", + "from sklearn.ensemble import RandomForestClassifier\n", + "rnd_clf = RandomForestClassifier(n_estimators=500, max_leaf_nodes=16, n_jobs=-1, random_state=42)\n", + "rnd_clf.fit(X_train, y_train)\n", + "y_pred_rf = rnd_clf.predict(X_test)\n", + "np.sum(y_pred == y_pred_rf) / len(y_pred)" + ] + }, + { + "cell_type": "markdown", + "id": "896072f6", + "metadata": { + "editable": true + }, + "source": [ + "## Boosting, a Bird's Eye View\n", + "\n", + "The basic idea is to combine weak classifiers in order to create a good\n", + "classifier. With a weak classifier we often intend a classifier which\n", + "produces results which are only slightly better than we would get by\n", + "random guesses.\n", + "\n", + "This is done by applying in an iterative way a weak (or a standard\n", + "classifier like decision trees) to modify the data. In each iteration\n", + "we emphasize those observations which are misclassified by weighting\n", + "them with a factor." + ] + }, + { + "cell_type": "markdown", + "id": "babc9c9c", + "metadata": { + "editable": true + }, + "source": [ + "## What is boosting? Additive Modelling/Iterative Fitting\n", + "\n", + "Boosting is a way of fitting an additive expansion in a set of\n", + "elementary basis functions like for example some simple polynomials.\n", + "Assume for example that we have a function" + ] + }, + { + "cell_type": "markdown", + "id": "2ed28584", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f_M(x) = \\sum_{i=1}^M \\beta_m b(x;\\gamma_m),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5b5b9631", + "metadata": { + "editable": true + }, + "source": [ + "where $\\beta_m$ are the expansion parameters to be determined in a\n", + "minimization process and $b(x;\\gamma_m)$ are some simple functions of\n", + "the multivariable parameter $x$ which is characterized by the\n", + "parameters $\\gamma_m$.\n", + "\n", + "As an example, consider the Sigmoid function we used in logistic\n", + "regression. In that case, we can translate the function\n", + "$b(x;\\gamma_m)$ into the Sigmoid function" + ] + }, + { + "cell_type": "markdown", + "id": "7b6c43ec", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\sigma(t) = \\frac{1}{1+\\exp{(-t)}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3962039f", + "metadata": { + "editable": true + }, + "source": [ + "where $t=\\gamma_0+\\gamma_1 x$ and the parameters $\\gamma_0$ and\n", + "$\\gamma_1$ were determined by the Logistic Regression fitting\n", + "algorithm.\n", + "\n", + "As another example, consider the cost function we defined for linear regression" + ] + }, + { + "cell_type": "markdown", + "id": "ee5f259c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(\\boldsymbol{y},\\boldsymbol{f}) = \\frac{1}{n} \\sum_{i=0}^{n-1}(y_i-f(x_i))^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "079d8ee3", + "metadata": { + "editable": true + }, + "source": [ + "In this case the function $f(x)$ was replaced by the design matrix\n", + "$\\boldsymbol{X}$ and the unknown linear regression parameters $\\boldsymbol{\\beta}$,\n", + "that is $\\boldsymbol{f}=\\boldsymbol{X}\\boldsymbol{\\beta}$. In linear regression we can \n", + "simply invert a matrix and obtain the parameters $\\beta$ by" + ] + }, + { + "cell_type": "markdown", + "id": "11f821a2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\beta}=\\left(\\boldsymbol{X}^T\\boldsymbol{X}\\right)^{-1}\\boldsymbol{X}^T\\boldsymbol{y}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "60990073", + "metadata": { + "editable": true + }, + "source": [ + "In iterative fitting or additive modeling, we minimize the cost function with respect to the parameters $\\beta_m$ and $\\gamma_m$." + ] + }, + { + "cell_type": "markdown", + "id": "4d7195ab", + "metadata": { + "editable": true + }, + "source": [ + "## Iterative Fitting, Regression and Squared-error Cost Function\n", + "\n", + "The way we proceed is as follows (here we specialize to the squared-error cost function)\n", + "\n", + "1. Establish a cost function, here ${\\cal C}(\\boldsymbol{y},\\boldsymbol{f}) = \\frac{1}{n} \\sum_{i=0}^{n-1}(y_i-f_M(x_i))^2$ with $f_M(x) = \\sum_{i=1}^M \\beta_m b(x;\\gamma_m)$.\n", + "\n", + "2. Initialize with a guess $f_0(x)$. It could be one or even zero or some random numbers.\n", + "\n", + "3. For $m=1:M$\n", + "\n", + "a. minimize $\\sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\\beta b(x;\\gamma))^2$ wrt $\\gamma$ and $\\beta$\n", + "\n", + "b. This gives the optimal values $\\beta_m$ and $\\gamma_m$\n", + "\n", + "c. Determine then the new values $f_m(x)=f_{m-1}(x) +\\beta_m b(x;\\gamma_m)$\n", + "\n", + "We could use any of the algorithms we have discussed till now. If we\n", + "use trees, $\\gamma$ parameterizes the split variables and split points\n", + "at the internal nodes, and the predictions at the terminal nodes." + ] + }, + { + "cell_type": "markdown", + "id": "4bee726a", + "metadata": { + "editable": true + }, + "source": [ + "## Squared-Error Example and Iterative Fitting\n", + "\n", + "To better understand what happens, let us develop the steps for the iterative fitting using the above squared error function.\n", + "\n", + "For simplicity we assume also that our functions $b(x;\\gamma)=1+\\gamma x$. \n", + "\n", + "This means that for every iteration $m$, we need to optimize" + ] + }, + { + "cell_type": "markdown", + "id": "1190b9a0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "(\\beta_m,\\gamma_m) = \\mathrm{argmin}_{\\beta,\\lambda}\\hspace{0.1cm} \\sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\\beta b(x;\\gamma))^2=\\sum_{i=0}^{n-1}(y_i-f_{m-1}(x_i)-\\beta(1+\\gamma x_i))^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2702211b", + "metadata": { + "editable": true + }, + "source": [ + "We start our iteration by simply setting $f_0(x)=0$. \n", + "Taking the derivatives with respect to $\\beta$ and $\\gamma$ we obtain" + ] + }, + { + "cell_type": "markdown", + "id": "1b1d9984", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial {\\cal C}}{\\partial \\beta} = -2\\sum_{i}(1+\\gamma x_i)(y_i-\\beta(1+\\gamma x_i))=0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cdf7e56a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "ac6f3b86", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial {\\cal C}}{\\partial \\gamma} =-2\\sum_{i}\\beta x_i(y_i-\\beta(1+\\gamma x_i))=0.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "faf6fb5f", + "metadata": { + "editable": true + }, + "source": [ + "We can then rewrite these equations as (defining $\\boldsymbol{w}=\\boldsymbol{e}+\\gamma \\boldsymbol{x})$ with $\\boldsymbol{e}$ being the unit vector)" + ] + }, + { + "cell_type": "markdown", + "id": "969f86ed", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\gamma \\boldsymbol{w}^T(\\boldsymbol{y}-\\beta\\gamma \\boldsymbol{w})=0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a98a541c", + "metadata": { + "editable": true + }, + "source": [ + "which gives us $\\beta = \\boldsymbol{w}^T\\boldsymbol{y}/(\\boldsymbol{w}^T\\boldsymbol{w})$. Similarly we have" + ] + }, + { + "cell_type": "markdown", + "id": "d8be5438", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\beta\\gamma \\boldsymbol{x}^T(\\boldsymbol{y}-\\beta(1+\\gamma \\boldsymbol{x}))=0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "932f43c5", + "metadata": { + "editable": true + }, + "source": [ + "which leads to $\\gamma =(\\boldsymbol{x}^T\\boldsymbol{y}-\\beta\\boldsymbol{x}^T\\boldsymbol{e})/(\\beta\\boldsymbol{x}^T\\boldsymbol{x})$. Inserting\n", + "for $\\beta$ gives us an equation for $\\gamma$. This is a non-linear equation in the unknown $\\gamma$ and has to be solved numerically. \n", + "\n", + "The solution to these two equations gives us in turn $\\beta_1$ and $\\gamma_1$ leading to the new expression for $f_1(x)$ as\n", + "$f_1(x) = \\beta_1(1+\\gamma_1x)$. Doing this $M$ times results in our final estimate for the function $f$." + ] + }, + { + "cell_type": "markdown", + "id": "24630eb9", + "metadata": { + "editable": true + }, + "source": [ + "## Iterative Fitting, Classification and AdaBoost\n", + "\n", + "Let us consider a binary classification problem with two outcomes $y_i \\in \\{-1,1\\}$ and $i=0,1,2,\\dots,n-1$ as our set of\n", + "observations. We define a classification function $G(x)$ which produces a prediction taking one or the other of the two values \n", + "$\\{-1,1\\}$.\n", + "\n", + "The error rate of the training sample is then" + ] + }, + { + "cell_type": "markdown", + "id": "9a7fa4b6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathrm{\\overline{err}}=\\frac{1}{n} \\sum_{i=0}^{n-1} I(y_i\\ne G(x_i)).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7ead62b2", + "metadata": { + "editable": true + }, + "source": [ + "The iterative procedure starts with defining a weak classifier whose\n", + "error rate is barely better than random guessing. The iterative\n", + "procedure in boosting is to sequentially apply a weak\n", + "classification algorithm to repeatedly modified versions of the data\n", + "producing a sequence of weak classifiers $G_m(x)$.\n", + "\n", + "Here we will express our function $f(x)$ in terms of $G(x)$. That is" + ] + }, + { + "cell_type": "markdown", + "id": "91639c49", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f_M(x) = \\sum_{i=1}^M \\beta_m b(x;\\gamma_m),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e43865c2", + "metadata": { + "editable": true + }, + "source": [ + "will be a function of" + ] + }, + { + "cell_type": "markdown", + "id": "1884c219", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "G_M(x) = \\mathrm{sign} \\sum_{i=1}^M \\alpha_m G_m(x).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bbb1cdbb", + "metadata": { + "editable": true + }, + "source": [ + "## Adaptive Boosting, AdaBoost\n", + "\n", + "In our iterative procedure we define thus" + ] + }, + { + "cell_type": "markdown", + "id": "7e3590f6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f_m(x) = f_{m-1}(x)+\\beta_mG_m(x).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2eb8c86b", + "metadata": { + "editable": true + }, + "source": [ + "The simplest possible cost function which leads (also simple from a computational point of view) to the AdaBoost algorithm is the\n", + "exponential cost/loss function defined as" + ] + }, + { + "cell_type": "markdown", + "id": "e477d15a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(\\boldsymbol{y},\\boldsymbol{f}) = \\sum_{i=0}^{n-1}\\exp{(-y_i(f_{m-1}(x_i)+\\beta G(x_i))}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b6f01e59", + "metadata": { + "editable": true + }, + "source": [ + "We optimize $\\beta$ and $G$ for each value of $m=1:M$ as we did in the regression case.\n", + "This is normally done in two steps. Let us however first rewrite the cost function as" + ] + }, + { + "cell_type": "markdown", + "id": "71c85471", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(\\boldsymbol{y},\\boldsymbol{f}) = \\sum_{i=0}^{n-1}w_i^{m}\\exp{(-y_i\\beta G(x_i))},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2d5be340", + "metadata": { + "editable": true + }, + "source": [ + "where we have defined $w_i^m= \\exp{(-y_if_{m-1}(x_i))}$." + ] + }, + { + "cell_type": "markdown", + "id": "e426517c", + "metadata": { + "editable": true + }, + "source": [ + "## Building up AdaBoost\n", + "\n", + "First, for any $\\beta > 0$, we optimize $G$ by setting" + ] + }, + { + "cell_type": "markdown", + "id": "c0c7e993", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "G_m(x) = \\mathrm{sign} \\sum_{i=0}^{n-1} w_i^m I(y_i \\ne G_(x_i)),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7457a096", + "metadata": { + "editable": true + }, + "source": [ + "which is the classifier that minimizes the weighted error rate in predicting $y$.\n", + "\n", + "We can do this by rewriting" + ] + }, + { + "cell_type": "markdown", + "id": "424d5bc9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\exp{-(\\beta)}\\sum_{y_i=G(x_i)}w_i^m+\\exp{(\\beta)}\\sum_{y_i\\ne G(x_i)}w_i^m,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d1fa658b", + "metadata": { + "editable": true + }, + "source": [ + "which can be rewritten as" + ] + }, + { + "cell_type": "markdown", + "id": "f8fc6b15", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "(\\exp{(\\beta)}-\\exp{-(\\beta)})\\sum_{i=0}^{n-1}w_i^mI(y_i\\ne G(x_i))+\\exp{(-\\beta)}\\sum_{i=0}^{n-1}w_i^m=0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "9ca82f54", + "metadata": { + "editable": true + }, + "source": [ + "which leads to" + ] + }, + { + "cell_type": "markdown", + "id": "6c028686", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\beta_m = \\frac{1}{2}\\log{\\frac{1-\\mathrm{\\overline{err}}}{\\mathrm{\\overline{err}}}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4007a0ef", + "metadata": { + "editable": true + }, + "source": [ + "where we have redefined the error as" + ] + }, + { + "cell_type": "markdown", + "id": "ba456347", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathrm{\\overline{err}}_m=\\frac{1}{n}\\frac{\\sum_{i=0}^{n-1}w_i^mI(y_i\\ne G(x_i)}{\\sum_{i=0}^{n-1}w_i^m},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c8df4ef3", + "metadata": { + "editable": true + }, + "source": [ + "which leads to an update of" + ] + }, + { + "cell_type": "markdown", + "id": "da46f9d9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f_m(x) = f_{m-1}(x) +\\beta_m G_m(x).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5c60f30d", + "metadata": { + "editable": true + }, + "source": [ + "This leads to the new weights" + ] + }, + { + "cell_type": "markdown", + "id": "a5bc4dfe", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_i^{m+1} = w_i^m \\exp{(-y_i\\beta_m G_m(x_i))}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3987cc1e", + "metadata": { + "editable": true + }, + "source": [ + "## Adaptive boosting: AdaBoost, Basic Algorithm\n", + "\n", + "The algorithm here is rather straightforward. Assume that our weak\n", + "classifier is a decision tree and we consider a binary set of outputs\n", + "with $y_i \\in \\{-1,1\\}$ and $i=0,1,2,\\dots,n-1$ as our set of\n", + "observations. Our design matrix is given in terms of the\n", + "feature/predictor vectors\n", + "$\\boldsymbol{X}=[\\boldsymbol{x}_0\\boldsymbol{x}_1\\dots\\boldsymbol{x}_{p-1}]$. Finally, we define also a\n", + "classifier determined by our data via a function $G(x)$. This function tells us how well we are able to classify our outputs/targets $\\boldsymbol{y}$. \n", + "\n", + "We have already defined the misclassification error $\\mathrm{err}$ as" + ] + }, + { + "cell_type": "markdown", + "id": "b35df09e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathrm{err}=\\frac{1}{n}\\sum_{i=0}^{n-1}I(y_i\\ne G(x_i)),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5b6a209c", + "metadata": { + "editable": true + }, + "source": [ + "where the function $I()$ is one if we misclassify and zero if we classify correctly." + ] + }, + { + "cell_type": "markdown", + "id": "d619a097", + "metadata": { + "editable": true + }, + "source": [ + "## Basic Steps of AdaBoost\n", + "\n", + "With the above definitions we are now ready to set up the algorithm for AdaBoost.\n", + "The basic idea is to set up weights which will be used to scale the correctly classified and the misclassified cases.\n", + "1. We start by initializing all weights to $w_i = 1/n$, with $i=0,1,2,\\dots n-1$. It is easy to see that we must have $\\sum_{i=0}^{n-1}w_i = 1$.\n", + "\n", + "2. We rewrite the misclassification error as" + ] + }, + { + "cell_type": "markdown", + "id": "b7311abb", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathrm{\\overline{err}}_m=\\frac{\\sum_{i=0}^{n-1}w_i^m I(y_i\\ne G(x_i))}{\\sum_{i=0}^{n-1}w_i},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4bfb4209", + "metadata": { + "editable": true + }, + "source": [ + "1. Then we start looping over all attempts at classifying, namely we start an iterative process for $m=1:M$, where $M$ is the final number of classifications. Our given classifier could for example be a plain decision tree.\n", + "\n", + "a. Fit then a given classifier to the training set using the weights $w_i$.\n", + "\n", + "b. Compute then $\\mathrm{err}$ and figure out which events are classified properly and which are classified wrongly.\n", + "\n", + "c. Define a quantity $\\alpha_{m} = \\log{(1-\\mathrm{\\overline{err}}_m)/\\mathrm{\\overline{err}}_m}$\n", + "\n", + "d. Set the new weights to $w_i = w_i\\times \\exp{(\\alpha_m I(y_i\\ne G(x_i)}$.\n", + "\n", + "5. Compute the new classifier $G(x)= \\sum_{i=0}^{n-1}\\alpha_m I(y_i\\ne G(x_i)$.\n", + "\n", + "For the iterations with $m \\le 2$ the weights are modified\n", + "individually at each steps. The observations which were misclassified\n", + "at iteration $m-1$ have a weight which is larger than those which were\n", + "classified properly. As this proceeds, the observations which were\n", + "difficult to classifiy correctly are given a larger influence. Each\n", + "new classification step $m$ is then forced to concentrate on those\n", + "observations that are missed in the previous iterations." + ] + }, + { + "cell_type": "markdown", + "id": "4cf4c1f4", + "metadata": { + "editable": true + }, + "source": [ + "## AdaBoost Examples\n", + "\n", + "Using **Scikit-Learn** it is easy to apply the adaptive boosting algorithm, as done here." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "453dff54", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "from sklearn.ensemble import AdaBoostClassifier\n", + "\n", + "ada_clf = AdaBoostClassifier(\n", + " DecisionTreeClassifier(max_depth=2), n_estimators=200,\n", + " algorithm=\"SAMME.R\", learning_rate=0.01, random_state=42)\n", + "ada_clf.fit(X_train, y_train)\n", + "y_pred = ada_clf.predict(X_test)\n", + "skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n", + "plt.show()\n", + "y_probas = ada_clf.predict_proba(X_test)\n", + "skplt.metrics.plot_roc(y_test, y_probas)\n", + "plt.show()\n", + "skplt.metrics.plot_cumulative_gain(y_test, y_probas)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "d6470164", + "metadata": { + "editable": true + }, + "source": [ + "## Making an ADAboost code yourself" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b6e01886", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "\n", + "class DecisionStump:\n", + " def fit(self, X, y, weights):\n", + " m, n = X.shape\n", + " self.alpha = 0\n", + " self.threshold = None\n", + " self.polarity = 1\n", + "\n", + " min_error = float('inf')\n", + "\n", + " for feature in range(n):\n", + " feature_values = np.unique(X[:, feature])\n", + "\n", + " for threshold in feature_values:\n", + " for polarity in [1, -1]:\n", + " predictions = np.ones(m)\n", + " predictions[X[:, feature] < threshold] = -1\n", + " predictions *= polarity\n", + "\n", + " error = sum(weights[predictions != y])\n", + "\n", + " if error < min_error:\n", + " min_error = error\n", + " self.alpha = 0.5 * np.log((1 - error) / (error + 1e-10))\n", + " self.threshold = threshold\n", + " self.feature_index = feature\n", + " self.polarity = polarity\n", + "\n", + " def predict(self, X):\n", + " m = X.shape[0]\n", + " predictions = np.ones(m)\n", + " if self.polarity == 1:\n", + " predictions[X[:, self.feature_index] < self.threshold] = -1\n", + " else:\n", + " predictions[X[:, self.feature_index] >= self.threshold] = -1\n", + " return predictions\n", + "\n", + "class AdaBoost:\n", + " def fit(self, X, y, n_estimators):\n", + " m = X.shape[0]\n", + " self.alphas = []\n", + " self.models = []\n", + "\n", + " weights = np.ones(m) / m\n", + "\n", + " for _ in range(n_estimators):\n", + " stump = DecisionStump()\n", + " stump.fit(X, y, weights)\n", + " predictions = stump.predict(X)\n", + "\n", + " error = sum(weights[predictions != y])\n", + " if error == 0:\n", + " break\n", + "\n", + " self.models.append(stump)\n", + " self.alphas.append(stump.alpha)\n", + "\n", + " weights *= np.exp(-stump.alpha * y * predictions)\n", + " weights /= np.sum(weights)\n", + "\n", + " def predict(self, X):\n", + " final_predictions = np.zeros(X.shape[0])\n", + " for alpha, model in zip(self.alphas, self.models):\n", + " final_predictions += alpha * model.predict(X)\n", + " return np.sign(final_predictions)\n", + "\n", + "# Example dataset (X, y)\n", + "X = np.array([[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]])\n", + "y = np.array([-1, -1, -1, -1, 1, 1, 1, 1, 1, 1]) # Labels must be -1 or 1\n", + "\n", + "# Train AdaBoost\n", + "ada = AdaBoost()\n", + "ada.fit(X, y, n_estimators=10)\n", + "\n", + "# Predictions\n", + "predictions = ada.predict(X)\n", + "print(\"Predictions:\", predictions)" + ] + }, + { + "cell_type": "markdown", + "id": "3cede4c9", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient boosting: Basics with Steepest Descent/Functional Gradient Descent\n", + "\n", + "Gradient boosting is again a similar technique to Adaptive boosting,\n", + "it combines so-called weak classifiers or regressors into a strong\n", + "method via a series of iterations.\n", + "\n", + "In order to understand the method, let us illustrate its basics by\n", + "bringing back the essential steps in linear regression, where our cost\n", + "function was the least squares function." + ] + }, + { + "cell_type": "markdown", + "id": "94e3b59f", + "metadata": { + "editable": true + }, + "source": [ + "## The Squared-Error again! Steepest Descent\n", + "\n", + "We start again with our cost function ${\\cal C}(\\boldsymbol{y}m\\boldsymbol{f})=\\sum_{i=0}^{n-1}{\\cal L}(y_i, f(x_i))$ where we want to minimize\n", + "This means that for every iteration, we need to optimize" + ] + }, + { + "cell_type": "markdown", + "id": "2f000f62", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "(\\hat{\\boldsymbol{f}}) = \\mathrm{argmin}_{\\boldsymbol{f}}\\hspace{0.1cm} \\sum_{i=0}^{n-1}(y_i-f(x_i))^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "014da5e9", + "metadata": { + "editable": true + }, + "source": [ + "We define a real function $h_m(x)$ that defines our final function $f_M(x)$ as" + ] + }, + { + "cell_type": "markdown", + "id": "022aee06", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f_M(x) = \\sum_{m=0}^M h_m(x).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d0d3e174", + "metadata": { + "editable": true + }, + "source": [ + "In the steepest decent approach we approximate $h_m(x) = -\\rho_m g_m(x)$, where $\\rho_m$ is a scalar and $g_m(x)$ the gradient defined as" + ] + }, + { + "cell_type": "markdown", + "id": "8af32042", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "g_m(x_i) = \\left[ \\frac{\\partial {\\cal L}(y_i, f(x_i))}{\\partial f(x_i)}\\right]_{f(x_i)=f_{m-1}(x_i)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4a384d95", + "metadata": { + "editable": true + }, + "source": [ + "With the new gradient we can update $f_m(x) = f_{m-1}(x) -\\rho_m g_m(x)$. Using the above squared-error function we see that\n", + "the gradient is $g_m(x_i) = -2(y_i-f(x_i))$.\n", + "\n", + "Choosing $f_0(x)=0$ we obtain $g_m(x) = -2y_i$ and inserting this into the minimization problem for the cost function we have" + ] + }, + { + "cell_type": "markdown", + "id": "bd5b9bb9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "(\\rho_1) = \\mathrm{argmin}_{\\rho}\\hspace{0.1cm} \\sum_{i=0}^{n-1}(y_i+2\\rho y_i)^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "560b3106", + "metadata": { + "editable": true + }, + "source": [ + "## Steepest Descent Example\n", + "\n", + "Optimizing with respect to $\\rho$ we obtain (taking the derivative) that $\\rho_1 = -1/2$. We have then that" + ] + }, + { + "cell_type": "markdown", + "id": "4742d327", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f_1(x) = f_{0}(x) -\\rho_1 g_1(x)=-y_i.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d160a37f", + "metadata": { + "editable": true + }, + "source": [ + "We can then proceed and compute" + ] + }, + { + "cell_type": "markdown", + "id": "f3cde07e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "g_2(x_i) = \\left[ \\frac{\\partial {\\cal L}(y_i, f(x_i))}{\\partial f(x_i)}\\right]_{f(x_i)=f_{1}(x_i)=y_i}=-4y_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cf95ad5e", + "metadata": { + "editable": true + }, + "source": [ + "and find a new value for $\\rho_2=-1/2$ and continue till we have reached $m=M$. We can modify the steepest descent method, or steepest boosting, by introducing what is called **gradient boosting**." + ] + }, + { + "cell_type": "markdown", + "id": "bb614b9d", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient Boosting, algorithm\n", + "\n", + "Steepest descent is however not much used, since it only optimizes $f$ at a fixed set of $n$ points,\n", + "so we do not learn a function that can generalize. However, we can modify the algorithm by\n", + "fitting a weak learner to approximate the negative gradient signal. \n", + "\n", + "Suppose we have a cost function $C(f)=\\sum_{i=0}^{n-1}L(y_i, f(x_i))$ where $y_i$ is our target and $f(x_i)$ the function which is meant to model $y_i$. The above cost function could be our standard squared-error function" + ] + }, + { + "cell_type": "markdown", + "id": "19e3e8fa", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(\\boldsymbol{y},\\boldsymbol{f})=\\sum_{i=0}^{n-1}(y_i-f(x_i))^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "9330b34b", + "metadata": { + "editable": true + }, + "source": [ + "The way we proceed in an iterative fashion is to\n", + "1. Initialize our estimate $f_0(x)$.\n", + "\n", + "2. For $m=1:M$, we\n", + "\n", + "a. compute the negative gradient vector $\\boldsymbol{u}_m = -\\partial C(\\boldsymbol{y},\\boldsymbol{f})/\\partial \\boldsymbol{f}(x)$ at $f(x) = f_{m-1}(x)$;\n", + "\n", + "b. fit the so-called base-learner to the negative gradient $h_m(u_m,x)$;\n", + "\n", + "c. update the estimate $f_m(x) = f_{m-1}(x)+h_m(u_m,x)$;\n", + "\n", + "4. The final estimate is then $f_M(x) = \\sum_{m=1}^M h_m(u_m,x)$." + ] + }, + { + "cell_type": "markdown", + "id": "e648539a", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient Boosting, Examples of Regression" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "d12810d3", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.ensemble import GradientBoostingRegressor\n", + "import scikitplot as skplt\n", + "from sklearn.metrics import mean_squared_error\n", + "\n", + "n = 100\n", + "maxdegree = 6\n", + "\n", + "# Make data set.\n", + "x = np.linspace(-3, 3, n).reshape(-1, 1)\n", + "y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)\n", + "\n", + "error = np.zeros(maxdegree)\n", + "bias = np.zeros(maxdegree)\n", + "variance = np.zeros(maxdegree)\n", + "polydegree = np.zeros(maxdegree)\n", + "X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2)\n", + "\n", + "for degree in range(1,maxdegree):\n", + " model = GradientBoostingRegressor(max_depth=degree, n_estimators=100, learning_rate=1.0) \n", + " model.fit(X_train,y_train)\n", + " y_pred = model.predict(X_test)\n", + " polydegree[degree] = degree\n", + " error[degree] = np.mean( np.mean((y_test - y_pred)**2) )\n", + " bias[degree] = np.mean( (y_test - np.mean(y_pred))**2 )\n", + " variance[degree] = np.mean( np.var(y_pred) )\n", + " print('Max depth:', degree)\n", + " print('Error:', error[degree])\n", + " print('Bias^2:', bias[degree])\n", + " print('Var:', variance[degree])\n", + " print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))\n", + "\n", + "plt.xlim(1,maxdegree-1)\n", + "plt.plot(polydegree, error, label='Error')\n", + "plt.plot(polydegree, bias, label='bias')\n", + "plt.plot(polydegree, variance, label='Variance')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "f3e95eca", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient Boosting, Classification Example" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "d6426469", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split \n", + "from sklearn.datasets import load_breast_cancer\n", + "import scikitplot as skplt\n", + "from sklearn.ensemble import GradientBoostingClassifier\n", + "from sklearn.model_selection import cross_validate\n", + "\n", + "# Load the data\n", + "cancer = load_breast_cancer()\n", + "\n", + "X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)\n", + "print(X_train.shape)\n", + "print(X_test.shape)\n", + "#now scale the data\n", + "from sklearn.preprocessing import StandardScaler\n", + "scaler = StandardScaler()\n", + "scaler.fit(X_train)\n", + "X_train_scaled = scaler.transform(X_train)\n", + "X_test_scaled = scaler.transform(X_test)\n", + "\n", + "gd_clf = GradientBoostingClassifier(max_depth=3, n_estimators=100, learning_rate=1.0) \n", + "gd_clf.fit(X_train_scaled, y_train)\n", + "#Cross validation\n", + "accuracy = cross_validate(gd_clf,X_test_scaled,y_test,cv=10)['test_score']\n", + "print(accuracy)\n", + "print(\"Test set accuracy with Gradient boosting and scaled data: {:.2f}\".format(gd_clf.score(X_test_scaled,y_test)))\n", + "\n", + "import scikitplot as skplt\n", + "y_pred = gd_clf.predict(X_test_scaled)\n", + "skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n", + "plt.show()\n", + "y_probas = gd_clf.predict_proba(X_test_scaled)\n", + "skplt.metrics.plot_roc(y_test, y_probas)\n", + "plt.show()\n", + "skplt.metrics.plot_cumulative_gain(y_test, y_probas)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "8de56415", + "metadata": { + "editable": true + }, + "source": [ + "## XGBoost: Extreme Gradient Boosting\n", + "\n", + "[XGBoost](https://github.com/dmlc/xgboost) or Extreme Gradient\n", + "Boosting, is an optimized distributed gradient boosting library\n", + "designed to be highly efficient, flexible and portable. It implements\n", + "machine learning algorithms under the Gradient Boosting\n", + "framework. XGBoost provides a parallel tree boosting that solve many\n", + "data science problems in a fast and accurate way. See the [article by Chen and Guestrin](https://arxiv.org/abs/1603.02754).\n", + "\n", + "The authors design and build a highly scalable end-to-end tree\n", + "boosting system. It has a theoretically justified weighted quantile\n", + "sketch for efficient proposal calculation. It introduces a novel sparsity-aware algorithm for parallel tree learning and an effective cache-aware block structure for out-of-core tree learning.\n", + "\n", + "It is now the algorithm which wins essentially all ML competitions!!!" + ] + }, + { + "cell_type": "markdown", + "id": "dfc59b18", + "metadata": { + "editable": true + }, + "source": [ + "## Xgboost on the Cancer Data\n", + "\n", + "As you will see from the confusion matrix below, XGBoots does an excellent job on the Wisconsin cancer data and outperforms essentially all agorithms we have discussed till now." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "79e4cc00", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split \n", + "from sklearn.datasets import load_breast_cancer\n", + "from sklearn.preprocessing import LabelEncoder\n", + "from sklearn.model_selection import cross_validate\n", + "import scikitplot as skplt\n", + "import xgboost as xgb\n", + "# Load the data\n", + "cancer = load_breast_cancer()\n", + "\n", + "X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)\n", + "print(X_train.shape)\n", + "print(X_test.shape)\n", + "#now scale the data\n", + "from sklearn.preprocessing import StandardScaler\n", + "scaler = StandardScaler()\n", + "scaler.fit(X_train)\n", + "X_train_scaled = scaler.transform(X_train)\n", + "X_test_scaled = scaler.transform(X_test)\n", + "\n", + "xg_clf = xgb.XGBClassifier()\n", + "xg_clf.fit(X_train_scaled,y_train)\n", + "\n", + "y_test = xg_clf.predict(X_test_scaled)\n", + "\n", + "print(\"Test set accuracy with Gradient Boosting and scaled data: {:.2f}\".format(xg_clf.score(X_test_scaled,y_test)))\n", + "\n", + "import scikitplot as skplt\n", + "y_pred = xg_clf.predict(X_test_scaled)\n", + "skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)\n", + "plt.show()\n", + "y_probas = xg_clf.predict_proba(X_test_scaled)\n", + "skplt.metrics.plot_roc(y_test, y_probas)\n", + "plt.show()\n", + "skplt.metrics.plot_cumulative_gain(y_test, y_probas)\n", + "plt.show()\n", + "\n", + "\n", + "xgb.plot_tree(xg_clf,num_trees=0)\n", + "plt.rcParams['figure.figsize'] = [50, 10]\n", + "plt.show()\n", + "\n", + "xgb.plot_importance(xg_clf)\n", + "plt.rcParams['figure.figsize'] = [5, 5]\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "c4700b19", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient boosting, making our own code for a regression case" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "eb0594c5", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "class DecisionTreeRegressor:\n", + " def __init__(self, max_depth=3):\n", + " self.max_depth = max_depth\n", + " self.tree = None\n", + " def fit(self, X, y):\n", + " self.tree = self._grow_tree(X, y)\n", + " def _grow_tree(self, X, y, depth=0):\n", + " n_samples, n_features = X.shape\n", + " if depth < self.max_depth:\n", + " best_feature, best_threshold = self._best_split(X, y)\n", + " if best_feature is not None:\n", + " left_indices = X[:, best_feature] < best_threshold\n", + " right_indices = X[:, best_feature] >= best_threshold\n", + " left_child = self._grow_tree(X[left_indices], y[left_indices], depth + 1)\n", + " right_child = self._grow_tree(X[right_indices], y[right_indices], depth + 1)\n", + " return (best_feature, best_threshold, left_child, right_child)\n", + " return np.mean(y)\n", + " def _best_split(self, X, y):\n", + " best_mse = float('inf')\n", + " best_feature, best_threshold = None, None\n", + " n_samples, n_features = X.shape\n", + " \n", + " for feature in range(n_features):\n", + " thresholds = np.unique(X[:, feature])\n", + " for threshold in thresholds:\n", + " left_indices = X[:, feature] < threshold\n", + " right_indices = X[:, feature] >= threshold\n", + " if len(y[left_indices]) > 0 and len(y[right_indices]) > 0:\n", + " left_mse = np.mean((y[left_indices] - np.mean(y[left_indices])) ** 2)\n", + " right_mse = np.mean((y[right_indices] - np.mean(y[right_indices])) ** 2)\n", + " mse = (len(y[left_indices]) * left_mse + len(y[right_indices]) * right_mse) / n_samples\n", + " \n", + " if mse < best_mse:\n", + " best_mse = mse\n", + " best_feature = feature\n", + " best_threshold = threshold\n", + " return best_feature, best_threshold\n", + " def predict(self, X):\n", + " return np.array([self._predict_sample(sample, self.tree) for sample in X])\n", + " def _predict_sample(self, sample, node):\n", + " if isinstance(node, tuple):\n", + " feature, threshold, left_child, right_child = node\n", + " if sample[feature] < threshold:\n", + " return self._predict_sample(sample, left_child)\n", + " else:\n", + " return self._predict_sample(sample, right_child)\n", + " return node\n", + "class GradientBoostingRegressor:\n", + " def __init__(self, n_estimators=100, learning_rate=0.1, max_depth=3):\n", + " self.n_estimators = n_estimators\n", + " self.learning_rate = learning_rate\n", + " self.max_depth = max_depth\n", + " self.models = []\n", + " def fit(self, X, y):\n", + " y_pred = np.zeros(y.shape)\n", + " for _ in range(self.n_estimators):\n", + " residuals = y - y_pred\n", + " model = DecisionTreeRegressor(max_depth=self.max_depth)\n", + " model.fit(X, residuals)\n", + " y_pred += self.learning_rate * model.predict(X)\n", + " self.models.append(model)\n", + " def predict(self, X):\n", + " y_pred = np.zeros(X.shape[0])\n", + " for model in self.models:\n", + " y_pred += self.learning_rate * model.predict(X)\n", + " return y_pred\n", + "# Example usage\n", + "if __name__ == \"__main__\":\n", + " # Sample data\n", + " X = np.array([[1], [2], [3], [4], [5]])\n", + " y = np.array([1.5, 1.7, 3.5, 3.7, 5.0])\n", + " model = GradientBoostingRegressor(n_estimators=100, learning_rate=0.1, max_depth=2)\n", + " model.fit(X, y)\n", + " predictions = model.predict(X)\n", + " print(\"Predictions:\", predictions)" + ] + }, + { + "cell_type": "markdown", + "id": "bbf154c4", + "metadata": { + "editable": true + }, + "source": [ + "## Summary of course" + ] + }, + { + "cell_type": "markdown", + "id": "84d512fc", + "metadata": { + "editable": true + }, + "source": [ + "## What? Me worry? No final exam in this course!\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "71b8eb59", + "metadata": { + "editable": true + }, + "source": [ + "## Topics we have covered this year\n", + "\n", + "The course has two central parts\n", + "\n", + "1. Statistical analysis and optimization of data\n", + "\n", + "2. Machine learning" + ] + }, + { + "cell_type": "markdown", + "id": "473329b7", + "metadata": { + "editable": true + }, + "source": [ + "## Statistical analysis and optimization of data\n", + "\n", + "The following topics have been discussed:\n", + "1. Basic concepts, expectation values, variance, covariance, correlation functions and errors;\n", + "\n", + "2. Simpler models, binomial distribution, the Poisson distribution, simple and multivariate normal distributions;\n", + "\n", + "3. Central elements from linear algebra, matrix inversion and SVD\n", + "\n", + "4. Gradient methods for data optimization\n", + "\n", + "5. Estimation of errors using cross-validation, bootstrapping and jackknife methods;\n", + "\n", + "6. Practical optimization using Singular-value decomposition and least squares for parameterizing data.\n", + "\n", + "7. Not discussed: Principal Component Analysis to reduce the number of features." + ] + }, + { + "cell_type": "markdown", + "id": "6c94f44a", + "metadata": { + "editable": true + }, + "source": [ + "## Machine learning\n", + "\n", + "* Linear methods for regression and classification:\n", + "\n", + "a. Ordinary Least Squares\n", + "\n", + "b. Ridge regression\n", + "\n", + "c. Lasso regression\n", + "\n", + "d. Logistic regression\n", + "\n", + "* Neural networks and deep learning:\n", + "\n", + "a. Feed Forward Neural Networks\n", + "\n", + "b. Convolutional Neural Networks\n", + "\n", + "c. Recurrent Neural Networks\n", + "\n", + "* Decisions trees and ensemble methods:\n", + "\n", + "a. Decision trees\n", + "\n", + "b. Bagging and voting\n", + "\n", + "c. Random forests\n", + "\n", + "d. Boosting and gradient boosting\n", + "\n", + "* Not discussed this year: Support vector machines\n", + "\n", + "a. Binary classification and multiclass classification\n", + "\n", + "b. Kernel methods\n", + "\n", + "c. Regression" + ] + }, + { + "cell_type": "markdown", + "id": "d9942ded", + "metadata": { + "editable": true + }, + "source": [ + "## Learning outcomes and overarching aims of this course\n", + "\n", + "The course introduces a variety of central algorithms and methods\n", + "essential for studies of data analysis and machine learning. The\n", + "course is project based and through the various projects, normally\n", + "three, you will be exposed to fundamental research problems\n", + "in these fields, with the aim to reproduce state of the art scientific\n", + "results. The students will learn to develop and structure large codes\n", + "for studying these systems, get acquainted with computing facilities\n", + "and learn to handle large scientific projects. A good scientific and\n", + "ethical conduct is emphasized throughout the course. \n", + "\n", + "* Understand linear methods for regression and classification;\n", + "\n", + "* Learn about neural network;\n", + "\n", + "* Learn about bagging, boosting and trees\n", + "\n", + "\n", + "* Learn about basic data analysis;\n", + "\n", + "* Be capable of extending the acquired knowledge to other systems and cases;\n", + "\n", + "* Have an understanding of central algorithms used in data analysis and machine learning;\n", + "\n", + "* Work on numerical projects to illustrate the theory. The projects play a central role." + ] + }, + { + "cell_type": "markdown", + "id": "7818c700", + "metadata": { + "editable": true + }, + "source": [ + "## Perspective on Machine Learning\n", + "\n", + "1. Rapidly emerging application area\n", + "\n", + "2. Experiment AND theory are evolving in many many fields. \n", + "\n", + "3. Requires education/retraining for more widespread adoption\n", + "\n", + "4. A lot of “word-of-mouth” development methods\n", + "\n", + "Huge amounts of data sets require automation, classical analysis tools often inadequate. \n", + "High energy physics hit this wall in the 90’s.\n", + "In 2009 single top quark production was determined via [Boosted decision trees, Bayesian\n", + "Neural Networks, etc.](https://arxiv.org/pdf/0903.0850.pdf)" + ] + }, + { + "cell_type": "markdown", + "id": "cc946602", + "metadata": { + "editable": true + }, + "source": [ + "## Machine Learning Research\n", + "\n", + "Where to find recent results:\n", + "1. Conference proceedings, arXiv and blog posts!\n", + "\n", + "2. **NIPS**: [Neural Information Processing Systems](https://papers.nips.cc)\n", + "\n", + "3. **ICLR**: [International Conference on Learning Representations](https://openreview.net/group?id=ICLR.cc/2018/Conference#accepted-oral-papers)\n", + "\n", + "4. **ICML**: International Conference on Machine Learning\n", + "\n", + "5. [Journal of Machine Learning Research](http://www.jmlr.org/papers/v19/) \n", + "\n", + "6. [Follow ML on ArXiv](https://arxiv.org/list/cs.LG/recent)" + ] + }, + { + "cell_type": "markdown", + "id": "c2b75185", + "metadata": { + "editable": true + }, + "source": [ + "## Starting your Machine Learning Project\n", + "\n", + "1. Identify problem type: classification, regression\n", + "\n", + "2. Consider your data carefully\n", + "\n", + "3. Choose a simple model that fits 1 and 2\n", + "\n", + "4. Consider your data carefully again! Think of data representation more carefully.\n", + "\n", + "5. Based on your results, feedback loop to earliest possible point" + ] + }, + { + "cell_type": "markdown", + "id": "4600986a", + "metadata": { + "editable": true + }, + "source": [ + "## Choose a Model and Algorithm\n", + "\n", + "* Supervised?\n", + "\n", + "* Start with the simplest model that fits your problem\n", + "\n", + "* Start with minimal processing of data" + ] + }, + { + "cell_type": "markdown", + "id": "cfb572d5", + "metadata": { + "editable": true + }, + "source": [ + "## Preparing Your Data\n", + "\n", + "* Shuffle your data\n", + "\n", + "* Mean center your data\n", + "\n", + " * Why?\n", + "\n", + "* Normalize the variance\n", + "\n", + " * Why?\n", + "\n", + "* **Whitening**\n", + "\n", + " * Decorrelates data\n", + "\n", + " * Can be hit or miss\n", + "\n", + " * When to do train/test split?" + ] + }, + { + "cell_type": "markdown", + "id": "3e38f862", + "metadata": { + "editable": true + }, + "source": [ + "## Which activation and weights to choose in neural networks\n", + "\n", + "* RELU? ELU? GELU? etc\n", + "\n", + "* Sigmoid or Tanh?\n", + "\n", + "* Set all weights to 0? Terrible idea\n", + "\n", + "* Set all weights to random values? Small random values" + ] + }, + { + "cell_type": "markdown", + "id": "76abe122", + "metadata": { + "editable": true + }, + "source": [ + "## Optimization Methods and Hyperparameters\n", + "* Stochastic gradient descent\n", + "\n", + " * Stochastic gradient descent + momentum\n", + "\n", + "* State-of-the-art approaches:\n", + "\n", + "a. RMSProp\n", + "\n", + "b. Adam\n", + "\n", + "c. and more\n", + "\n", + "Which regularization and hyperparameters? $L_1$ or $L_2$, soft\n", + "classifiers, depths of trees and many other. Need to explore a large\n", + "set of hyperparameters and regularization methods." + ] + }, + { + "cell_type": "markdown", + "id": "0b246db8", + "metadata": { + "editable": true + }, + "source": [ + "## Resampling\n", + "\n", + "When do we resample?\n", + "\n", + "1. [Bootstrap](https://www.cambridge.org/core/books/bootstrap-methods-and-their-application/ED2FD043579F27952363566DC09CBD6A)\n", + "\n", + "2. [Cross-validation](https://www.youtube.com/watch?v=fSytzGwwBVw&ab_channel=StatQuestwithJoshStarmer)\n", + "\n", + "3. Jackknife and many other" + ] + }, + { + "cell_type": "markdown", + "id": "9a6555fc", + "metadata": { + "editable": true + }, + "source": [ + "## Other courses on Data science and Machine Learning at UiO\n", + "\n", + "1. [FYS5429 – Advanced machine learning and data analysis for the physical sciences](https://www.uio.no/studier/emner/matnat/fys/FYS5429/index-eng.html)\n", + "\n", + "2. [IN3050/IN4050 Introduction to Artificial Intelligence and Machine Learning](https://www.uio.no/studier/emner/matnat/ifi/IN3050/index-eng.html). Introductory course in machine learning and AI\n", + "\n", + "3. [STK-INF3000/4000 Selected Topics in Data Science](http://www.uio.no/studier/emner/matnat/math/STK-INF3000/index-eng.html). The course provides insight into selected contemporary relevant topics within Data Science. \n", + "\n", + "4. [IN4080 Natural Language Processing](https://www.uio.no/studier/emner/matnat/ifi/IN4080/index.html). Probabilistic and machine learning techniques applied to natural language processing. \n", + "\n", + "5. [STK-IN4300 – Statistical learning methods in Data Science](https://www.uio.no/studier/emner/matnat/math/STK-IN4300/index-eng.html). An advanced introduction to statistical and machine learning. For students with a good mathematics and statistics background.\n", + "\n", + "6. [IN-STK5000 Responsible Data Science](https://www.uio.no/studier/emner/matnat/ifi/IN-STK5000/index-eng.html). Methods for adaptive collection and processing of data based on machine learning techniques. \n", + "\n", + "7. [IN4310 – Machine Learning for Image Analysis](https://www.uio.no/studier/emner/matnat/ifi/IN4310/index.html). An introduction to deep learning with particular emphasis on applications within Image analysis, but useful for other application areas too.\n", + "\n", + "8. [IN5310 – Advanced Deep Learning for Image Analysis](https://www.uio.no/studier/emner/matnat/ifi/IN5310/index.html)\n", + "\n", + "9. [IN5490 – Advanced Topics in Artificial Intelligence for Intelligent Systems](https://www.uio.no/studier/emner/matnat/ifi/IN5490/index.html)\n", + "\n", + "10. [TEK5040 – Deep learning for autonomous systems](https://www.uio.no/studier/emner/matnat/its/TEK5040/). The course addresses advanced algorithms and architectures for deep learning with neural networks. The course provides an introduction to how deep-learning techniques can be used in the construction of key parts of advanced autonomous systems that exist in physical environments and cyber environments." + ] + }, + { + "cell_type": "markdown", + "id": "c2561e72", + "metadata": { + "editable": true + }, + "source": [ + "## Additional courses of interest\n", + "\n", + "1. [STK4051 Computational Statistics](https://www.uio.no/studier/emner/matnat/math/STK4051/index-eng.html)\n", + "\n", + "2. [STK4021 Applied Bayesian Analysis and Numerical Methods](https://www.uio.no/studier/emner/matnat/math/STK4021/index-eng.html)" + ] + }, + { + "cell_type": "markdown", + "id": "796637c8", + "metadata": { + "editable": true + }, + "source": [ + "## What's the future like?\n", + "\n", + "Based on multi-layer nonlinear neural networks, deep learning can\n", + "learn directly from raw data, automatically extract and abstract\n", + "features from layer to layer, and then achieve the goal of regression,\n", + "classification, or ranking. Deep learning has made breakthroughs in\n", + "computer vision, speech processing and natural language, and reached\n", + "or even surpassed human level. The success of deep learning is mainly\n", + "due to the three factors: big data, big model, and big computing.\n", + "\n", + "In the past few decades, many different architectures of deep neural\n", + "networks have been proposed, such as\n", + "1. Convolutional neural networks, which are mostly used in image and video data processing, and have also been applied to sequential data such as text processing;\n", + "\n", + "2. Recurrent neural networks, which can process sequential data of variable length and have been widely used in natural language understanding and speech processing;\n", + "\n", + "3. Encoder-decoder framework, which is mostly used for image or sequence generation, such as machine translation, text summarization, and image captioning." + ] + }, + { + "cell_type": "markdown", + "id": "6afdb59e", + "metadata": { + "editable": true + }, + "source": [ + "## Types of Machine Learning, a repetition\n", + "\n", + "The approaches to machine learning are many, but are often split into two main categories. \n", + "In *supervised learning* we know the answer to a problem,\n", + "and let the computer deduce the logic behind it. On the other hand, *unsupervised learning*\n", + "is a method for finding patterns and relationship in data sets without any prior knowledge of the system.\n", + "Some authours also operate with a third category, namely *reinforcement learning*. This is a paradigm \n", + "of learning inspired by behavioural psychology, where learning is achieved by trial-and-error, \n", + "solely from rewards and punishment.\n", + "\n", + "Another way to categorize machine learning tasks is to consider the desired output of a system.\n", + "Some of the most common tasks are:\n", + "\n", + " * Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.\n", + "\n", + " * Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.\n", + "\n", + " * Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.\n", + "\n", + " * Other unsupervised learning algortihms like **Boltzmann machines**" + ] + }, + { + "cell_type": "markdown", + "id": "95097424", + "metadata": { + "editable": true + }, + "source": [ + "## Why Boltzmann machines?\n", + "\n", + "What is known as restricted Boltzmann Machines (RMB) have received a lot of attention lately. \n", + "One of the major reasons is that they can be stacked layer-wise to build deep neural networks that capture complicated statistics.\n", + "\n", + "The original RBMs had just one visible layer and a hidden layer, but recently so-called Gaussian-binary RBMs have gained quite some popularity in imaging since they are capable of modeling continuous data that are common to natural images. \n", + "\n", + "Furthermore, they have been used to solve complicated [quantum mechanical many-particle problems or classical statistical physics problems like the Ising and Potts classes of models](https://journals.aps.org/rmp/abstract/10.1103/RevModPhys.91.045002)." + ] + }, + { + "cell_type": "markdown", + "id": "31a33cea", + "metadata": { + "editable": true + }, + "source": [ + "## Boltzmann Machines\n", + "\n", + "Why use a generative model rather than the more well known discriminative deep neural networks (DNN)? \n", + "\n", + "* Discriminitave methods have several limitations: They are mainly supervised learning methods, thus requiring labeled data. And there are tasks they cannot accomplish, like drawing new examples from an unknown probability distribution.\n", + "\n", + "* A generative model can learn to represent and sample from a probability distribution. The core idea is to learn a parametric model of the probability distribution from which the training data was drawn. As an example\n", + "\n", + "a. A model for images could learn to draw new examples of cats and dogs, given a training dataset of images of cats and dogs.\n", + "\n", + "b. Generate a sample of an ordered or disordered phase, having been given samples of such phases.\n", + "\n", + "c. Model the trial function for [Monte Carlo calculations](https://journals.aps.org/rmp/abstract/10.1103/RevModPhys.91.045002)." + ] + }, + { + "cell_type": "markdown", + "id": "d6583875", + "metadata": { + "editable": true + }, + "source": [ + "## Some similarities and differences from DNNs\n", + "\n", + "1. Both use gradient-descent based learning procedures for minimizing cost functions\n", + "\n", + "2. Energy based models don't use backpropagation and automatic differentiation for computing gradients, instead turning to Markov Chain Monte Carlo methods.\n", + "\n", + "3. DNNs often have several hidden layers. A restricted Boltzmann machine has only one hidden layer, however several RBMs can be stacked to make up Deep Belief Networks, of which they constitute the building blocks.\n", + "\n", + "History: The RBM was developed by amongst others [Geoffrey Hinton](https://en.wikipedia.org/wiki/Geoffrey_Hinton), called by some the \"Godfather of Deep Learning\", working with the University of Toronto and Google." + ] + }, + { + "cell_type": "markdown", + "id": "285bbf5d", + "metadata": { + "editable": true + }, + "source": [ + "## Boltzmann machines (BM)\n", + "\n", + "A BM is what we would call an undirected probabilistic graphical model\n", + "with stochastic continuous or discrete units.\n", + "\n", + "It is interpreted as a stochastic recurrent neural network where the\n", + "state of each unit(neurons/nodes) depends on the units it is connected\n", + "to. The weights in the network represent thus the strength of the\n", + "interaction between various units/nodes.\n", + "\n", + "It turns into a Hopfield network if we choose deterministic rather\n", + "than stochastic units. In contrast to a Hopfield network, a BM is a\n", + "so-called generative model. It allows us to generate new samples from\n", + "the learned distribution." + ] + }, + { + "cell_type": "markdown", + "id": "5b51dec9", + "metadata": { + "editable": true + }, + "source": [ + "## A standard BM setup\n", + "\n", + "A standard BM network is divided into a set of observable and visible units $\\hat{x}$ and a set of unknown hidden units/nodes $\\hat{h}$.\n", + "\n", + "Additionally there can be bias nodes for the hidden and visible layers. These biases are normally set to $1$.\n", + "\n", + "BMs are stackable, meaning they cwe can train a BM which serves as input to another BM. We can construct deep networks for learning complex PDFs. The layers can be trained one after another, a feature which makes them popular in deep learning\n", + "\n", + "However, they are often hard to train. This leads to the introduction of so-called restricted BMs, or RBMS.\n", + "Here we take away all lateral connections between nodes in the visible layer as well as connections between nodes in the hidden layer. The network is illustrated in the figure below." + ] + }, + { + "cell_type": "markdown", + "id": "4cb37b8f", + "metadata": { + "editable": true + }, + "source": [ + "## The structure of the RBM network\n", + "\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "45fe33d7", + "metadata": { + "editable": true + }, + "source": [ + "## The network\n", + "\n", + "**The network layers**:\n", + "1. A function $\\mathbf{x}$ that represents the visible layer, a vector of $M$ elements (nodes). This layer represents both what the RBM might be given as training input, and what we want it to be able to reconstruct. This might for example be given by the pixels of an image or coefficients representing speech, or the coordinates of a quantum mechanical state function.\n", + "\n", + "2. The function $\\mathbf{h}$ represents the hidden, or latent, layer. A vector of $N$ elements (nodes). Also called \"feature detectors\"." + ] + }, + { + "cell_type": "markdown", + "id": "3bbbaa88", + "metadata": { + "editable": true + }, + "source": [ + "## Goals\n", + "\n", + "The goal of the hidden layer is to increase the model's expressive\n", + "power. We encode complex interactions between visible variables by\n", + "introducing additional, hidden variables that interact with visible\n", + "degrees of freedom in a simple manner, yet still reproduce the complex\n", + "correlations between visible degrees in the data once marginalized\n", + "over (integrated out).\n", + "\n", + "**The network parameters, to be optimized/learned**:\n", + "1. $\\mathbf{a}$ represents the visible bias, a vector of same length as $\\mathbf{x}$.\n", + "\n", + "2. $\\mathbf{b}$ represents the hidden bias, a vector of same lenght as $\\mathbf{h}$.\n", + "\n", + "3. $W$ represents the interaction weights, a matrix of size $M\\times N$." + ] + }, + { + "cell_type": "markdown", + "id": "d6a9f606", + "metadata": { + "editable": true + }, + "source": [ + "## Joint distribution\n", + "\n", + "The restricted Boltzmann machine is described by a Boltzmann distribution" + ] + }, + { + "cell_type": "markdown", + "id": "81aaff6e", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\tP_{rbm}(\\mathbf{x},\\mathbf{h}) = \\frac{1}{Z} e^{-\\frac{1}{T_0}E(\\mathbf{x},\\mathbf{h})},\n", + "\\label{_auto1} \\tag{1}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "9f856eb3", + "metadata": { + "editable": true + }, + "source": [ + "where $Z$ is the normalization constant or partition function, defined as" + ] + }, + { + "cell_type": "markdown", + "id": "f15429d1", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\tZ = \\int \\int e^{-\\frac{1}{T_0}E(\\mathbf{x},\\mathbf{h})} d\\mathbf{x} d\\mathbf{h}.\n", + "\\label{_auto2} \\tag{2}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e8a8f8e7", + "metadata": { + "editable": true + }, + "source": [ + "It is common to ignore $T_0$ by setting it to one." + ] + }, + { + "cell_type": "markdown", + "id": "4fb17989", + "metadata": { + "editable": true + }, + "source": [ + "## Network Elements, the energy function\n", + "\n", + "The function $E(\\mathbf{x},\\mathbf{h})$ gives the **energy** of a\n", + "configuration (pair of vectors) $(\\mathbf{x}, \\mathbf{h})$. The lower\n", + "the energy of a configuration, the higher the probability of it. This\n", + "function also depends on the parameters $\\mathbf{a}$, $\\mathbf{b}$ and\n", + "$W$. Thus, when we adjust them during the learning procedure, we are\n", + "adjusting the energy function to best fit our problem.\n", + "\n", + "An expression for the energy function is" + ] + }, + { + "cell_type": "markdown", + "id": "0bed5ddd", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "E(\\hat{x},\\hat{h}) = -\\sum_{ia}^{NA}b_i^a \\alpha_i^a(x_i)-\\sum_{jd}^{MD}c_j^d \\beta_j^d(h_j)-\\sum_{ijad}^{NAMD}b_i^a \\alpha_i^a(x_i)c_j^d \\beta_j^d(h_j)w_{ij}^{ad}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f8e64229", + "metadata": { + "editable": true + }, + "source": [ + "Here $\\beta_j^d(h_j)$ and $\\alpha_i^a(x_j)$ are so-called transfer functions that map a given input value to a desired feature value. The labels $a$ and $d$ denote that there can be multiple transfer functions per variable. The first sum depends only on the visible units. The second on the hidden ones. **Note** that there is no connection between nodes in a layer.\n", + "\n", + "The quantities $b$ and $c$ can be interpreted as the visible and hidden biases, respectively.\n", + "\n", + "The connection between the nodes in the two layers is given by the weights $w_{ij}$." + ] + }, + { + "cell_type": "markdown", + "id": "f8f02179", + "metadata": { + "editable": true + }, + "source": [ + "## Defining different types of RBMs\n", + "There are different variants of RBMs, and the differences lie in the types of visible and hidden units we choose as well as in the implementation of the energy function $E(\\mathbf{x},\\mathbf{h})$. \n", + "\n", + "**Binary-Binary RBM:**\n", + "\n", + "RBMs were first developed using binary units in both the visible and hidden layer. The corresponding energy function is defined as follows:" + ] + }, + { + "cell_type": "markdown", + "id": "19008689", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\tE(\\mathbf{x}, \\mathbf{h}) = - \\sum_i^M x_i a_i- \\sum_j^N b_j h_j - \\sum_{i,j}^{M,N} x_i w_{ij} h_j,\n", + "\\label{_auto3} \\tag{3}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a3d31b3a", + "metadata": { + "editable": true + }, + "source": [ + "where the binary values taken on by the nodes are most commonly 0 and 1.\n", + "\n", + "**Gaussian-Binary RBM:**\n", + "\n", + "Another varient is the RBM where the visible units are Gaussian while the hidden units remain binary:" + ] + }, + { + "cell_type": "markdown", + "id": "79d29641", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "
\n", + "\n", + "$$\n", + "\\begin{equation}\n", + "\tE(\\mathbf{x}, \\mathbf{h}) = \\sum_i^M \\frac{(x_i - a_i)^2}{2\\sigma_i^2} - \\sum_j^N b_j h_j - \\sum_{i,j}^{M,N} \\frac{x_i w_{ij} h_j}{\\sigma_i^2}. \n", + "\\label{_auto4} \\tag{4}\n", + "\\end{equation}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4d19d779", + "metadata": { + "editable": true + }, + "source": [ + "## More about RBMs\n", + "1. Useful when we model continuous data (i.e., we wish $\\mathbf{x}$ to be continuous)\n", + "\n", + "2. Requires a smaller learning rate, since there's no upper bound to the value a component might take in the reconstruction\n", + "\n", + "Other types of units include:\n", + "1. Softmax and multinomial units\n", + "\n", + "2. Gaussian visible and hidden units\n", + "\n", + "3. Binomial units\n", + "\n", + "4. Rectified linear units\n", + "\n", + "To read more, see [Lectures on Boltzmann machines in Physics](https://github.com/CompPhysics/ComputationalPhysics2/blob/gh-pages/doc/pub/notebook2/ipynb/notebook2.ipynb)." + ] + }, + { + "cell_type": "markdown", + "id": "b8fa06ec", + "metadata": { + "editable": true + }, + "source": [ + "## Autoencoders: Overarching view\n", + "\n", + "Autoencoders are artificial neural networks capable of learning\n", + "efficient representations of the input data (these representations are called codings) without\n", + "any supervision (i.e., the training set is unlabeled). These codings\n", + "typically have a much lower dimensionality than the input data, making\n", + "autoencoders useful for dimensionality reduction. \n", + "\n", + "More importantly, autoencoders act as powerful feature detectors, and\n", + "they can be used for unsupervised pretraining of deep neural networks.\n", + "\n", + "Lastly, they are capable of randomly generating new data that looks\n", + "very similar to the training data; this is called a generative\n", + "model. For example, you could train an autoencoder on pictures of\n", + "faces, and it would then be able to generate new faces. Surprisingly,\n", + "autoencoders work by simply learning to copy their inputs to their\n", + "outputs. This may sound like a trivial task, but we will see that\n", + "constraining the network in various ways can make it rather\n", + "difficult. For example, you can limit the size of the internal\n", + "representation, or you can add noise to the inputs and train the\n", + "network to recover the original inputs. These constraints prevent the\n", + "autoencoder from trivially copying the inputs directly to the outputs,\n", + "which forces it to learn efficient ways of representing the data. In\n", + "short, the codings are byproducts of the autoencoder’s attempt to\n", + "learn the identity function under some constraints.\n", + "\n", + "[Video on autoencoders](https://www.coursera.org/lecture/building-deep-learning-models-with-tensorflow/autoencoders-1U4L3)\n", + "\n", + "See also A. Geron's textbook, chapter 15." + ] + }, + { + "cell_type": "markdown", + "id": "262fc510", + "metadata": { + "editable": true + }, + "source": [ + "## Bayesian Machine Learning\n", + "\n", + "This is an important topic if we aim at extracting a probability\n", + "distribution. This gives us also a confidence interval and error\n", + "estimates.\n", + "\n", + "Bayesian machine learning allows us to encode our prior beliefs about\n", + "what those models should look like, independent of what the data tells\n", + "us. This is especially useful when we don’t have a ton of data to\n", + "confidently learn our model.\n", + "\n", + "[Video on Bayesian deep learning](https://www.youtube.com/watch?v=E1qhGw8QxqY&ab_channel=AndrewGordonWilson)\n", + "\n", + "See also the [slides here](https://github.com/CompPhysics/MachineLearning/blob/master/doc/Articles/lec03.pdf)." + ] + }, + { + "cell_type": "markdown", + "id": "36608f14", + "metadata": { + "editable": true + }, + "source": [ + "## Reinforcement Learning\n", + "\n", + "Reinforcement Learning (RL) is one of the most exciting fields of\n", + "Machine Learning today, and also one of the oldest. It has been around\n", + "since the 1950s, producing many interesting applications over the\n", + "years.\n", + "\n", + "It studies\n", + "how agents take actions based on trial and error, so as to maximize\n", + "some notion of cumulative reward in a dynamic system or\n", + "environment. Due to its generality, the problem has also been studied\n", + "in many other disciplines, such as game theory, control theory,\n", + "operations research, information theory, multi-agent systems, swarm\n", + "intelligence, statistics, and genetic algorithms.\n", + "\n", + "In March 2016, AlphaGo, a computer program that plays the board game\n", + "Go, beat Lee Sedol in a five-game match. This was the first time a\n", + "computer Go program had beaten a 9-dan (highest rank) professional\n", + "without handicaps. AlphaGo is based on deep convolutional neural\n", + "networks and reinforcement learning. AlphaGo’s victory was a major\n", + "milestone in artificial intelligence and it has also made\n", + "reinforcement learning a hot research area in the field of machine\n", + "learning.\n", + "\n", + "[Lecture on Reinforcement Learning](https://www.youtube.com/watch?v=FgzM3zpZ55o&ab_channel=stanfordonline).\n", + "\n", + "See also A. Geron's textbook, chapter 16." + ] + }, + { + "cell_type": "markdown", + "id": "a2b4652f", + "metadata": { + "editable": true + }, + "source": [ + "## Transfer learning\n", + "\n", + "The goal of transfer learning is to transfer the model or knowledge\n", + "obtained from a source task to the target task, in order to resolve\n", + "the issues of insufficient training data in the target task. The\n", + "rationality of doing so lies in that usually the source and target\n", + "tasks have inter-correlations, and therefore either the features,\n", + "samples, or models in the source task might provide useful information\n", + "for us to better solve the target task. Transfer learning is a hot\n", + "research topic in recent years, with many problems still waiting to be studied.\n", + "\n", + "[Lecture on transfer learning](https://www.ias.edu/video/machinelearning/2020/0331-SamoryKpotufe)." + ] + }, + { + "cell_type": "markdown", + "id": "8cef8c03", + "metadata": { + "editable": true + }, + "source": [ + "## Adversarial learning\n", + "\n", + "The conventional deep generative model has a potential problem: the\n", + "model tends to generate extreme instances to maximize the\n", + "probabilistic likelihood, which will hurt its performance. Adversarial\n", + "learning utilizes the adversarial behaviors (e.g., generating\n", + "adversarial instances or training an adversarial model) to enhance the\n", + "robustness of the model and improve the quality of the generated\n", + "data. In recent years, one of the most promising unsupervised learning\n", + "technologies, generative adversarial networks (GAN), has already been\n", + "successfully applied to image, speech, and text.\n", + "\n", + "[Lecture on adversial learning](https://www.youtube.com/watch?v=CIfsB_EYsVI&ab_channel=StanfordUniversitySchoolofEngineering)." + ] + }, + { + "cell_type": "markdown", + "id": "df85a3e6", + "metadata": { + "editable": true + }, + "source": [ + "## Dual learning\n", + "\n", + "Dual learning is a new learning paradigm, the basic idea of which is\n", + "to use the primal-dual structure between machine learning tasks to\n", + "obtain effective feedback/regularization, and guide and strengthen the\n", + "learning process, thus reducing the requirement of large-scale labeled\n", + "data for deep learning. The idea of dual learning has been applied to\n", + "many problems in machine learning, including machine translation,\n", + "image style conversion, question answering and generation, image\n", + "classification and generation, text classification and generation,\n", + "image-to-text, and text-to-image." + ] + }, + { + "cell_type": "markdown", + "id": "f01aaa3c", + "metadata": { + "editable": true + }, + "source": [ + "## Distributed machine learning\n", + "\n", + "Distributed computation will speed up machine learning algorithms,\n", + "significantly improve their efficiency, and thus enlarge their\n", + "application. When distributed meets machine learning, more than just\n", + "implementing the machine learning algorithms in parallel is required." + ] + }, + { + "cell_type": "markdown", + "id": "0005330c", + "metadata": { + "editable": true + }, + "source": [ + "## Meta learning\n", + "\n", + "Meta learning is an emerging research direction in machine\n", + "learning. Roughly speaking, meta learning concerns learning how to\n", + "learn, and focuses on the understanding and adaptation of the learning\n", + "itself, instead of just completing a specific learning task. That is,\n", + "a meta learner needs to be able to evaluate its own learning methods\n", + "and adjust its own learning methods according to specific learning\n", + "tasks." + ] + }, + { + "cell_type": "markdown", + "id": "efcfaccf", + "metadata": { + "editable": true + }, + "source": [ + "## The Challenges Facing Machine Learning\n", + "\n", + "While there has been much progress in machine learning, there are also challenges.\n", + "\n", + "For example, the mainstream machine learning technologies are\n", + "black-box approaches, making us concerned about their potential\n", + "risks. To tackle this challenge, we may want to make machine learning\n", + "more explainable and controllable. As another example, the\n", + "computational complexity of machine learning algorithms is usually\n", + "very high and we may want to invent lightweight algorithms or\n", + "implementations. Furthermore, in many domains such as physics,\n", + "chemistry, biology, and social sciences, people usually seek elegantly\n", + "simple equations (e.g., the Schrödinger equation) to uncover the\n", + "underlying laws behind various phenomena. In the field of machine\n", + "learning, can we reveal simple laws instead of designing more complex\n", + "models for data fitting? Although there are many challenges, we are\n", + "still very optimistic about the future of machine learning. As we look\n", + "forward to the future, here are what we think the research hotspots in\n", + "the next ten years will be.\n", + "\n", + "See the article on [Discovery of Physics From Data: Universal Laws and Discrepancies](https://www.frontiersin.org/articles/10.3389/frai.2020.00025/full)" + ] + }, + { + "cell_type": "markdown", + "id": "f7b109c9", + "metadata": { + "editable": true + }, + "source": [ + "## Explainable machine learning\n", + "\n", + "Machine learning, especially deep learning, evolves rapidly. The\n", + "ability gap between machine and human on many complex cognitive tasks\n", + "becomes narrower and narrower. However, we are still in the very early\n", + "stage in terms of explaining why those effective models work and how\n", + "they work.\n", + "\n", + "**What is missing: the gap between correlation and causation**. Standard Machine Learning is based on what e have called a frequentist approach. \n", + "\n", + "Most\n", + "machine learning techniques, especially the statistical ones, depend\n", + "highly on correlations in data sets to make predictions and analyses. In\n", + "contrast, rational humans tend to reply on clear and trustworthy\n", + "causality relations obtained via logical reasoning on real and clear\n", + "facts. It is one of the core goals of explainable machine learning to\n", + "transition from solving problems by data correlation to solving\n", + "problems by logical reasoning.\n", + "\n", + "**Bayesian Machine Learning is one of the exciting research directions in this field**." + ] + }, + { + "cell_type": "markdown", + "id": "e9142380", + "metadata": { + "editable": true + }, + "source": [ + "## Quantum machine learning\n", + "\n", + "Quantum machine learning is an emerging interdisciplinary research\n", + "area at the intersection of quantum computing and machine learning.\n", + "\n", + "Quantum computers use effects such as quantum coherence and quantum\n", + "entanglement to process information, which is fundamentally different\n", + "from classical computers. Quantum algorithms have surpassed the best\n", + "classical algorithms in several problems (e.g., searching for an\n", + "unsorted database, inverting a sparse matrix), which we call quantum\n", + "acceleration.\n", + "\n", + "When quantum computing meets machine learning, it can be a mutually\n", + "beneficial and reinforcing process, as it allows us to take advantage\n", + "of quantum computing to improve the performance of classical machine\n", + "learning algorithms. In addition, we can also use the machine learning\n", + "algorithms (on classic computers) to analyze and improve quantum\n", + "computing systems.\n", + "\n", + "[Lecture on Quantum ML](https://www.youtube.com/watch?v=Xh9pUu3-WxM&ab_channel=InstituteforPure%26AppliedMathematics%28IPAM%29).\n", + "\n", + "[Read interview with Maria Schuld on her work on Quantum Machine Learning](https://physics.aps.org/articles/v13/179?utm_campaign=weekly&utm_medium=email&utm_source=emailalert). See also [her recent textbook](https://www.springer.com/gp/book/9783319964232)." + ] + }, + { + "cell_type": "markdown", + "id": "cb638c92", + "metadata": { + "editable": true + }, + "source": [ + "## Quantum machine learning algorithms based on linear algebra\n", + "\n", + "Many quantum machine learning algorithms are based on variants of\n", + "quantum algorithms for solving linear equations, which can efficiently\n", + "solve N-variable linear equations with complexity of O(log2 N) under\n", + "certain conditions. The quantum matrix inversion algorithm can\n", + "accelerate many machine learning methods, such as least square linear\n", + "regression, least square version of support vector machine, Gaussian\n", + "process, and more. The training of these algorithms can be simplified\n", + "to solve linear equations. The key bottleneck of this type of quantum\n", + "machine learning algorithms is data input—that is, how to initialize\n", + "the quantum system with the entire data set. Although efficient\n", + "data-input algorithms exist for certain situations, how to efficiently\n", + "input data into a quantum system is as yet unknown for most cases." + ] + }, + { + "cell_type": "markdown", + "id": "676fd56e", + "metadata": { + "editable": true + }, + "source": [ + "## Quantum reinforcement learning\n", + "\n", + "In quantum reinforcement learning, a quantum agent interacts with the\n", + "classical environment to obtain rewards from the environment, so as to\n", + "adjust and improve its behavioral strategies. In some cases, it\n", + "achieves quantum acceleration by the quantum processing capabilities\n", + "of the agent or the possibility of exploring the environment through\n", + "quantum superposition. Such algorithms have been proposed in\n", + "superconducting circuits and systems of trapped ions." + ] + }, + { + "cell_type": "markdown", + "id": "ac1d93d3", + "metadata": { + "editable": true + }, + "source": [ + "## Quantum deep learning\n", + "\n", + "Dedicated quantum information processors, such as quantum annealers\n", + "and programmable photonic circuits, are well suited for building deep\n", + "quantum networks. The simplest deep quantum network is the Boltzmann\n", + "machine. The classical Boltzmann machine consists of bits with tunable\n", + "interactions and is trained by adjusting the interaction of these bits\n", + "so that the distribution of its expression conforms to the statistics\n", + "of the data. To quantize the Boltzmann machine, the neural network can\n", + "simply be represented as a set of interacting quantum spins that\n", + "correspond to an adjustable Ising model. Then, by initializing the\n", + "input neurons in the Boltzmann machine to a fixed state and allowing\n", + "the system to heat up, we can read out the output qubits to get the\n", + "result." + ] + }, + { + "cell_type": "markdown", + "id": "c5047fcb", + "metadata": { + "editable": true + }, + "source": [ + "## Social machine learning\n", + "\n", + "Machine learning aims to imitate how humans\n", + "learn. While we have developed successful machine learning algorithms,\n", + "until now we have ignored one important fact: humans are social. Each\n", + "of us is one part of the total society and it is difficult for us to\n", + "live, learn, and improve ourselves, alone and isolated. Therefore, we\n", + "should design machines with social properties. Can we let machines\n", + "evolve by imitating human society so as to achieve more effective,\n", + "intelligent, interpretable “social machine learning”?\n", + "\n", + "And much more." + ] + }, + { + "cell_type": "markdown", + "id": "bdd66000", + "metadata": { + "editable": true + }, + "source": [ + "## The last words?\n", + "\n", + "Early computer scientist Alan Kay said, **The best way to predict the\n", + "future is to create it**. Therefore, all machine learning\n", + "practitioners, whether scholars or engineers, professors or students,\n", + "need to work together to advance these important research\n", + "topics. Together, we will not just predict the future, but create it." + ] + }, + { + "cell_type": "markdown", + "id": "7fb56aeb", + "metadata": { + "editable": true + }, + "source": [ + "## Best wishes to you all and thanks so much for your heroic efforts this semester\n", + "\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/doc/LectureNotes/_build/html/additionweek42.html b/doc/LectureNotes/_build/html/additionweek42.html index e81a40a00..8b6416a7b 100644 --- a/doc/LectureNotes/_build/html/additionweek42.html +++ b/doc/LectureNotes/_build/html/additionweek42.html @@ -257,6 +257,9 @@
  • Week 47: From Decision Trees to Ensemble Methods, Random Forests and Boosting Methods
  • Exercise week 47
  • +
  • Week 48: Gradient boosting and summary of course
  • +
  • Exercises week 48
  • +

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects

    Projects