This commit is contained in:
Morten Hjorth-Jensen
2024-09-10 12:06:15 +02:00
parent 4a3985783f
commit 4e5c11dfa3
143 changed files with 2073 additions and 6207 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "6c8c59f8",
"id": "34471c23",
"metadata": {
"editable": true
},
@@ -14,7 +14,7 @@
},
{
"cell_type": "markdown",
"id": "24af4cf5",
"id": "947e566c",
"metadata": {
"editable": true
},
@@ -27,7 +27,7 @@
},
{
"cell_type": "markdown",
"id": "2971d68f",
"id": "91b68c62",
"metadata": {
"editable": true
},
@@ -60,7 +60,7 @@
},
{
"cell_type": "markdown",
"id": "eba3be6a",
"id": "6161e2ec",
"metadata": {
"editable": true
},
@@ -89,7 +89,7 @@
},
{
"cell_type": "markdown",
"id": "50da25e5",
"id": "d598eabc",
"metadata": {
"editable": true
},
@@ -111,7 +111,7 @@
},
{
"cell_type": "markdown",
"id": "7757fb0c",
"id": "6f94bf24",
"metadata": {
"editable": true
},
@@ -126,7 +126,7 @@
},
{
"cell_type": "markdown",
"id": "83fbdb79",
"id": "2d87bd3d",
"metadata": {
"editable": true
},
@@ -159,7 +159,7 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "39b900ad",
"id": "3ea47a48",
"metadata": {
"collapsed": false,
"editable": true
@@ -176,8 +176,7 @@
"from random import random, seed\n",
"\n",
"fig = plt.figure()\n",
"ax = fig.gca(projection='3d')\n",
"\n",
"ax = fig.add_subplot(projection = '3d')\n",
"# Make data.\n",
"x = np.arange(0, 1, 0.05)\n",
"y = np.arange(0, 1, 0.05)\n",
@@ -211,7 +210,7 @@
},
{
"cell_type": "markdown",
"id": "ef99fea4",
"id": "681ae810",
"metadata": {
"editable": true
},
@@ -221,7 +220,7 @@
},
{
"cell_type": "markdown",
"id": "b1a7f51d",
"id": "0bf63b42",
"metadata": {
"editable": true
},
@@ -243,7 +242,7 @@
},
{
"cell_type": "markdown",
"id": "d4bd58e3",
"id": "bda22453",
"metadata": {
"editable": true
},
@@ -256,7 +255,7 @@
},
{
"cell_type": "markdown",
"id": "32f767b4",
"id": "7cc65393",
"metadata": {
"editable": true
},
@@ -268,7 +267,7 @@
},
{
"cell_type": "markdown",
"id": "bae0d9d6",
"id": "0e5859cb",
"metadata": {
"editable": true
},
@@ -280,7 +279,7 @@
},
{
"cell_type": "markdown",
"id": "8f0b2ec9",
"id": "5969702e",
"metadata": {
"editable": true
},
@@ -290,7 +289,7 @@
},
{
"cell_type": "markdown",
"id": "8a455920",
"id": "6fc7cf78",
"metadata": {
"editable": true
},
@@ -302,7 +301,7 @@
},
{
"cell_type": "markdown",
"id": "3f7ffe3e",
"id": "fad83915",
"metadata": {
"editable": true
},
@@ -333,7 +332,7 @@
},
{
"cell_type": "markdown",
"id": "cf4d70a4",
"id": "5ca41535",
"metadata": {
"editable": true
},
@@ -351,7 +350,7 @@
},
{
"cell_type": "markdown",
"id": "8cc60702",
"id": "eafba188",
"metadata": {
"editable": true
},
@@ -368,7 +367,7 @@
},
{
"cell_type": "markdown",
"id": "bd9d1dd3",
"id": "ca22f9c3",
"metadata": {
"editable": true
},
@@ -384,7 +383,7 @@
},
{
"cell_type": "markdown",
"id": "03fab7b5",
"id": "62e8987d",
"metadata": {
"editable": true
},
@@ -396,7 +395,7 @@
},
{
"cell_type": "markdown",
"id": "009b7fb9",
"id": "3a837289",
"metadata": {
"editable": true
},
@@ -407,7 +406,7 @@
},
{
"cell_type": "markdown",
"id": "5bf0a0d5",
"id": "c4103004",
"metadata": {
"editable": true
},
@@ -419,7 +418,7 @@
},
{
"cell_type": "markdown",
"id": "52c48acb",
"id": "8802447b",
"metadata": {
"editable": true
},
@@ -431,7 +430,7 @@
},
{
"cell_type": "markdown",
"id": "3158357a",
"id": "b129e460",
"metadata": {
"editable": true
},
@@ -443,7 +442,7 @@
},
{
"cell_type": "markdown",
"id": "021253bc",
"id": "91bb15a6",
"metadata": {
"editable": true
},
@@ -454,7 +453,7 @@
},
{
"cell_type": "markdown",
"id": "9e89d5fe",
"id": "d6ac051f",
"metadata": {
"editable": true
},
@@ -466,7 +465,7 @@
},
{
"cell_type": "markdown",
"id": "5f79916c",
"id": "6d2b1477",
"metadata": {
"editable": true
},
@@ -479,7 +478,7 @@
},
{
"cell_type": "markdown",
"id": "a6e62eff",
"id": "ffb13255",
"metadata": {
"editable": true
},
@@ -491,7 +490,7 @@
},
{
"cell_type": "markdown",
"id": "7e833f14",
"id": "031020e1",
"metadata": {
"editable": true
},
@@ -501,7 +500,7 @@
},
{
"cell_type": "markdown",
"id": "14ef5a97",
"id": "ba8af75f",
"metadata": {
"editable": true
},
@@ -513,7 +512,7 @@
},
{
"cell_type": "markdown",
"id": "a9443b1d",
"id": "c5c4d7e6",
"metadata": {
"editable": true
},
@@ -524,7 +523,7 @@
},
{
"cell_type": "markdown",
"id": "ff0c2a46",
"id": "62633d34",
"metadata": {
"editable": true
},
@@ -557,7 +556,7 @@
},
{
"cell_type": "markdown",
"id": "4c8ea78a",
"id": "18f1b5b0",
"metadata": {
"editable": true
},
@@ -569,7 +568,7 @@
},
{
"cell_type": "markdown",
"id": "1d119b3e",
"id": "76dc98a9",
"metadata": {
"editable": true
},
@@ -588,7 +587,7 @@
},
{
"cell_type": "markdown",
"id": "b9782b21",
"id": "ea4f7a95",
"metadata": {
"editable": true
},
@@ -600,7 +599,7 @@
},
{
"cell_type": "markdown",
"id": "457bd0ae",
"id": "21225b69",
"metadata": {
"editable": true
},
@@ -614,7 +613,7 @@
},
{
"cell_type": "markdown",
"id": "fbc011e0",
"id": "c259efb1",
"metadata": {
"editable": true
},
@@ -626,7 +625,7 @@
},
{
"cell_type": "markdown",
"id": "5bb40600",
"id": "2bf21344",
"metadata": {
"editable": true
},
@@ -636,7 +635,7 @@
},
{
"cell_type": "markdown",
"id": "e5aebe0a",
"id": "2b5dd2b9",
"metadata": {
"editable": true
},
@@ -648,7 +647,7 @@
},
{
"cell_type": "markdown",
"id": "6f243211",
"id": "90c065aa",
"metadata": {
"editable": true
},
@@ -658,7 +657,7 @@
},
{
"cell_type": "markdown",
"id": "850e1403",
"id": "c29e34b2",
"metadata": {
"editable": true
},
@@ -670,7 +669,7 @@
},
{
"cell_type": "markdown",
"id": "86066fab",
"id": "f928062b",
"metadata": {
"editable": true
},
@@ -689,7 +688,7 @@
},
{
"cell_type": "markdown",
"id": "aedb0de8",
"id": "ba0fe639",
"metadata": {
"editable": true
},
@@ -712,7 +711,7 @@
},
{
"cell_type": "markdown",
"id": "09e42708",
"id": "82f076b3",
"metadata": {
"editable": true
},
@@ -740,7 +739,7 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "a7412176",
"id": "b5f7adac",
"metadata": {
"collapsed": false,
"editable": true
@@ -752,7 +751,7 @@
},
{
"cell_type": "markdown",
"id": "2462a733",
"id": "5e55285e",
"metadata": {
"editable": true
},
@@ -764,7 +763,7 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "e299ff99",
"id": "a66f3a48",
"metadata": {
"collapsed": false,
"editable": true
@@ -790,7 +789,7 @@
},
{
"cell_type": "markdown",
"id": "58bfbdc9",
"id": "1015d4e5",
"metadata": {
"editable": true
},
@@ -815,7 +814,7 @@
},
{
"cell_type": "markdown",
"id": "5c69b9d7",
"id": "23b093c7",
"metadata": {
"editable": true
},
@@ -829,7 +828,7 @@
},
{
"cell_type": "markdown",
"id": "a92b1a41",
"id": "fe5834fa",
"metadata": {
"editable": true
},
@@ -859,7 +858,7 @@
},
{
"cell_type": "markdown",
"id": "3da35987",
"id": "a238d8fe",
"metadata": {
"editable": true
},
@@ -881,7 +880,7 @@
},
{
"cell_type": "markdown",
"id": "c03bf204",
"id": "e2cae8ee",
"metadata": {
"editable": true
},
@@ -1,348 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "515c9474",
"metadata": {
"editable": true
},
"source": [
"<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)\n",
"doconce format html Project2.do.txt -->\n",
"<!-- dom:TITLE: Project 2 on Machine Learning, deadline November 17 (Midnight) -->"
]
},
{
"cell_type": "markdown",
"id": "890dcb04",
"metadata": {
"editable": true
},
"source": [
"# Project 2 on Machine Learning, deadline November 17 (Midnight)\n",
"**[Data Analysis and Machine Learning FYS-STK3155/FYS4155](http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html)**, Department of Physics, University of Oslo, Norway\n",
"\n",
"Date: **Nov 13, 2023**\n",
"\n",
"Copyright 1999-2023, [Data Analysis and Machine Learning FYS-STK3155/FYS4155](http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html). Released under CC Attribution-NonCommercial 4.0 license"
]
},
{
"cell_type": "markdown",
"id": "8cbf512f",
"metadata": {
"editable": true
},
"source": [
"## Classification and Regression, from linear and logistic regression to neural networks\n",
"\n",
"The main aim of this project is to study both classification and\n",
"regression problems by developing our own feed-forward neural network\n",
"(FFNN) code. We can reuse the regression algorithms studied in project\n",
"1. We will also include logistic regression for classification\n",
"problems and write our own FFNN code for studying both regression and\n",
"classification problems. The codes developed in project 1, including\n",
"bootstrap **and/or** cross-validation as well as the computation of the\n",
"mean-squared error and/or the $R2$ or the accuracy score\n",
"(classification problems) functions can also be utilized in the\n",
"present analysis.\n",
"\n",
"The data sets that we propose here are (the default sets)\n",
"\n",
"* Regression (fitting a continuous function). In this part you will need to bring back your results from project 1 and compare these with what you get from your Neural Network code to be developed here. The data sets could be\n",
"\n",
"a. A simple one-dimensional function or the Franke function or the terrain data from project 1, or data sets your propose. It could be a simpler function than the Franke function. We recommend testing a simpler function (see below). But if you wish to try more complex function, feel free to do so.\n",
"\n",
"* Classification. Here you will also need to develop a Logistic regression code that you will use to compare with the Neural Network code. The data set we propose are the so-called [Wisconsin Breat Cancer Data](https://www.kaggle.com/uciml/breast-cancer-wisconsin-data) data set of images representing various features of tumors. These are discussed intensively in the lecture notes, see for example the slides from [week 41](https://compphysics.github.io/MachineLearning/doc/pub/week41/html/week41.html). A longer explanation with links to the scientific literature can be found at the [Machine Learning repository of the University of California at Irvine](https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29). Feel free to consult this site and the pertinent literature.\n",
"\n",
"You can find more information about this at the [Scikit-Learn site](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html) or at the [University of California at Irvine](https://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+(original)). \n",
"\n",
"However, if you would like to study other data sets, feel free to\n",
"propose other sets. What we list here are mere suggestions from our\n",
"side. If you opt for another data set, consider using a set which has\n",
"been studied in the scientific literature. This makes it easier for\n",
"you to compare and analyze your results. Comparing with existing\n",
"results from the scientific literature is also an essential element of\n",
"the scientific discussion. The University of California at Irvine\n",
"with its Machine Learning repository at\n",
"<https://archive.ics.uci.edu/ml/index.php> is an excellent site to\n",
"look up for examples and\n",
"inspiration. [Kaggle.com](https://www.kaggle.com/) is an equally\n",
"interesting site. Feel free to explore these sites.\n",
"\n",
"We will start with a regression problem and we will reuse our codes from project 1 starting with writing our own Stochastic Gradient Descent (SGD) code."
]
},
{
"cell_type": "markdown",
"id": "696379a0",
"metadata": {
"editable": true
},
"source": [
"### Part a): Write your own Stochastic Gradient Descent code, first step\n",
"\n",
"In order to get started, we will now replace in our standard ordinary\n",
"least squares (OLS) and Ridge regression codes (from project 1) the\n",
"matrix inversion algorithm with our own gradient descent (GD) and SGD\n",
"codes. You can use the Franke function or the terrain data from\n",
"project 1. **However, we recommend using a simpler function like**\n",
"$f(x)=a_0+a_1x+a_2x^2$ or higher-order one-dimensional polynomials.\n",
"You can obviously test your final codes against for example the Franke\n",
"function.\n",
"\n",
"You should include in your analysis of the GD and SGD codes the following elements\n",
"1. A plain gradient descent with a fixed learning rate (you will need to tune it) using the analytical expression for the gradient.\n",
"\n",
"2. Add momentum to the plain GD code and compare convergence with a fixed learning rate (you may need to tune the learning rate). Keep using the analytical expression for the gradient.\n",
"\n",
"3. Repeat these steps for stochastic gradient descent with mini batches and a given number of epochs. Use a tunable learning rate as discussed in the lectures from weeks 39 and 40. Discuss the results as functions of the various parameters (size of batches, number of epochs etc). Use the analytical gradient.\n",
"\n",
"4. Implement the Adagrad method in order to tune the learning rate. Do this with and without momentum for plain gradient descent and SGD.\n",
"\n",
"5. Add RMSprop and Adam to your library of methods for tuning the learning rate.\n",
"\n",
"The lecture notes from [weeks 39 and 40contain more\n",
"details](https://compphysics.github.io/MachineLearning/doc/pub/week39/html/week39.html) and code examples. Feel free to use these examples.\n",
"1. Replace thereafter your analytical gradient with either **Autograd** or **JAX**\n",
"\n",
"In summary, you should \n",
"perform an analysis of the results for OLS and Ridge regression as\n",
"function of the chosen learning rates, the number of mini-batches and\n",
"epochs as well as algorithm for scaling the learning rate. You can\n",
"also compare your own results with those that can be obtained using\n",
"for example **Scikit-Learn**'s various SGD options. Discuss your\n",
"results. For Ridge regression you need now to study the results as functions of the hyper-parameter $\\lambda$ and \n",
"the learning rate $\\eta$. Discuss your results.\n",
"\n",
"You will need your SGD code for the setup of the Neural Network and\n",
"Logistic Regression codes. You will find the Python [Seaborn\n",
"package](https://seaborn.pydata.org/generated/seaborn.heatmap.html)\n",
"useful when plotting the results as function of the learning rate\n",
"$\\eta$ and the hyper-parameter $\\lambda$ when you use Ridge\n",
"regression.\n",
"\n",
"We recommend reading chapter 8 on optimization from the textbook of [Goodfellow, Bengio and Courville](https://www.deeplearningbook.org/). This chapter contains many useful insights and discussions on the optimization part of machine learning."
]
},
{
"cell_type": "markdown",
"id": "81d48303",
"metadata": {
"editable": true
},
"source": [
"### Part b): Writing your own Neural Network code\n",
"\n",
"Your aim now, and this is the central part of this project, is to\n",
"write your own Feed Forward Neural Network code implementing the back\n",
"propagation algorithm discussed in the lecture slides from [week 40](https://compphysics.github.io/MachineLearning/doc/pub/week41/html/week40.html) and\n",
"[week 41](https://compphysics.github.io/MachineLearning/doc/pub/week41/html/week41.html).\n",
"\n",
"We will focus on a regression problem first and study either the simple second-order polynomial from part a) or the \n",
"Franke function or terrain data (or both or other data sets) from\n",
"project 1.\n",
"\n",
"Discuss again your choice of cost function.\n",
"\n",
"Write an FFNN code for regression with a flexible number of hidden\n",
"layers and nodes using the Sigmoid function as activation function for\n",
"the hidden layers. Initialize the weights using a normal\n",
"distribution. How would you initialize the biases? And which\n",
"activation function would you select for the final output layer?\n",
"\n",
"Train your network and compare the results with those from your OLS and Ridge Regression codes from project 1 if you use the Franke function or the terrain data.\n",
"You should test your results against a similar code using **Scikit-Learn** (see the examples in the above lecture notes from week 41) or **tensorflow/keras**. \n",
"\n",
"Comment your results and give a critical discussion of the results\n",
"obtained with the Linear Regression code and your own Neural Network\n",
"code. \n",
"Make an analysis of the regularization parameters and the learning rates employed to find the optimal MSE and $R2$ scores.\n",
"\n",
"A useful reference on the back progagation algorithm is [Nielsen's\n",
"book](http://neuralnetworksanddeeplearning.com/). It is an excellent\n",
"read."
]
},
{
"cell_type": "markdown",
"id": "db6aebb0",
"metadata": {
"editable": true
},
"source": [
"### Part c): Testing different activation functions\n",
"\n",
"You should now also test different activation functions for the hidden layers. Try out the Sigmoid, the RELU and the Leaky RELU functions and discuss your results. You may also study the way you initialize your weights and biases."
]
},
{
"cell_type": "markdown",
"id": "18314d90",
"metadata": {
"editable": true
},
"source": [
"### Part d): Classification analysis using neural networks\n",
"\n",
"With a well-written code it should now be easy to change the\n",
"activation function for the output layer.\n",
"\n",
"Here we will change the cost function for our neural network code\n",
"developed in parts b) and c) in order to perform a classification analysis. \n",
"\n",
"We will here study the Wisconsin Breast Cancer data set. This is a typical binary classification problem with just one single output, either True or Fale, $0$ or $1$ etc.\n",
"You find more information about this at the [Scikit-Learn\n",
"site](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html) or at the [University of California\n",
"at Irvine](https://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+(original)). \n",
"\n",
"To measure the performance of our classification problem we use the\n",
"so-called *accuracy* score. The accuracy is as you would expect just\n",
"the number of correctly guessed targets $t_i$ divided by the total\n",
"number of targets, that is"
]
},
{
"cell_type": "markdown",
"id": "dc3021aa",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"\\text{Accuracy} = \\frac{\\sum_{i=1}^n I(t_i = y_i)}{n} ,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "3c3c5b42",
"metadata": {
"editable": true
},
"source": [
"where $I$ is the indicator function, $1$ if $t_i = y_i$ and $0$\n",
"otherwise if we have a binary classification problem. Here $t_i$\n",
"represents the target and $y_i$ the outputs of your FFNN code and $n$ is simply the number of targets $t_i$.\n",
"\n",
"Discuss your results and give a critical analysis of the various parameters, including hyper-parameters like the learning rates and the regularization parameter $\\lambda$ (as you did in Ridge Regression), various activation functions, number of hidden layers and nodes and activation functions. \n",
"\n",
"As stated in the introduction, it can also be useful to study other\n",
"datasets. \n",
"\n",
"Again, we strongly recommend that you compare your own neural Network\n",
"code for classification and pertinent results against a similar code using **Scikit-Learn** or **tensorflow/keras** or **pytorch**."
]
},
{
"cell_type": "markdown",
"id": "1a493d07",
"metadata": {
"editable": true
},
"source": [
"### Part e): Write your Logistic Regression code, final step\n",
"\n",
"Finally, we want to compare the FFNN code we have developed with\n",
"Logistic regression, that is we wish to compare our neural network\n",
"classification results with the results we can obtain with another\n",
"method.\n",
"\n",
"Define your cost function and the design matrix before you start writing your code.\n",
"Write thereafter a Logistic regression code using your SGD algorithm. You can also use standard gradient descent in this case, with a learning rate as hyper-parameter.\n",
"Study the results as functions of the chosen learning rates.\n",
"Add also an $l_2$ regularization parameter $\\lambda$. Compare your results with those from your FFNN code as well as those obtained using **Scikit-Learn**'s logistic regression functionality.\n",
"\n",
"The weblink here <https://medium.com/ai-in-plain-english/comparison-between-logistic-regression-and-neural-networks-in-classifying-digits-dc5e85cd93c3>compares logistic regression and FFNN using the so-called MNIST data set. You may find several useful hints and ideas from this article."
]
},
{
"cell_type": "markdown",
"id": "649a5380",
"metadata": {
"editable": true
},
"source": [
"### Part f) Critical evaluation of the various algorithms\n",
"\n",
"After all these glorious calculations, you should now summarize the\n",
"various algorithms and come with a critical evaluation of their pros\n",
"and cons. Which algorithm works best for the regression case and which\n",
"is best for the classification case. These codes can also be part of\n",
"your final project 3, but now applied to other data sets."
]
},
{
"cell_type": "markdown",
"id": "804df082",
"metadata": {
"editable": true
},
"source": [
"## Background literature\n",
"\n",
"1. The text of Michael Nielsen is highly recommended, see [Nielsen's book](http://neuralnetworksanddeeplearning.com/). It is an excellent read.\n",
"\n",
"2. [Mehta et al, arXiv 1803.08823](https://arxiv.org/abs/1803.08823), *A high-bias, low-variance introduction to Machine Learning for physicists*, ArXiv:1803.08823.\n",
"\n",
"c. [Goodfellow, Bengio and Courville](https://www.deeplearningbook.org/), *Deep Learning*."
]
},
{
"cell_type": "markdown",
"id": "2661bc83",
"metadata": {
"editable": true
},
"source": [
"## Introduction to numerical projects\n",
"\n",
"Here follows a brief recipe and recommendation on how to write a report for each\n",
"project.\n",
"\n",
" * Give a short description of the nature of the problem and the eventual numerical methods you have used.\n",
"\n",
" * Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.\n",
"\n",
" * Include the source code of your program. Comment your program properly.\n",
"\n",
" * If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.\n",
"\n",
" * Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.\n",
"\n",
" * Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.\n",
"\n",
" * Try to give an interpretation of you results in your answers to the problems.\n",
"\n",
" * Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.\n",
"\n",
" * Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning."
]
},
{
"cell_type": "markdown",
"id": "e651a157",
"metadata": {
"editable": true
},
"source": [
"## Format for electronic delivery of report and programs\n",
"\n",
"The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:\n",
"\n",
" * Use Canvas to hand in your projects, log in at <https://www.uio.no/english/services/it/education/canvas/> with your normal UiO username and password.\n",
"\n",
" * Upload **only** the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.\n",
"\n",
" * In your GitHub/GitLab or similar repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.\n",
"\n",
"Finally, \n",
"we encourage you to collaborate. Optimal working groups consist of \n",
"2-3 students. You can then hand in a common report."
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
@@ -1,546 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "32bbc99a",
"metadata": {
"editable": true
},
"source": [
"<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)\n",
"doconce format html Project3.do.txt -->\n",
"<!-- dom:TITLE: Project 3 on Machine Learning, deadline December 18 (midnight), 2023 -->"
]
},
{
"cell_type": "markdown",
"id": "21397747",
"metadata": {
"editable": true
},
"source": [
"# Project 3 on Machine Learning, deadline December 18 (midnight), 2023\n",
"**[Data Analysis and Machine Learning FYS-STK3155/FYS4155](http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html)**, Department of Physics, University of Oslo, Norway\n",
"\n",
"Date: **Nov 13, 2023**\n",
"\n",
"Copyright 1999-2023, [Data Analysis and Machine Learning FYS-STK3155/FYS4155](http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html). Released under CC Attribution-NonCommercial 4.0 license"
]
},
{
"cell_type": "markdown",
"id": "a13debcc",
"metadata": {
"editable": true
},
"source": [
"# Paths for project 3"
]
},
{
"cell_type": "markdown",
"id": "9d1f1220",
"metadata": {
"editable": true
},
"source": [
"## Defining the data sets to analyze yourself\n",
"\n",
"For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say\n",
"1. [Kaggle](https://www.kaggle.com/datasets) \n",
"\n",
"2. The [University of California at Irvine (UCI) with its machine learning repository](https://archive.ics.uci.edu/ml/index.php).\n",
"\n",
"3. Or other sources.\n",
"\n",
"The approach to the analysis of these new data sets should follow to a large extent what you did in projects 1 and 2. That is:\n",
"1. Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among **linear regression (including Ridge and Lasso)**, **Logistic Regression**, **Neural Networks**, **Convolution Neural Networks**, **Recurrent Neural Networks**, and **Decision Trees, Random Forests, Bagging and Boosting**.\n",
"\n",
"Feel also free to use support vector machines, $k$-means and principal components analysis, although the latter have not been covered during the lectures. This material can be found in the lecture notes.\n",
"\n",
"You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into **convolutional neural networks** or **recurrent neural networks**, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attention to supervised learning. \n",
"\n",
"For Boosting, feel also free to write your own codes.\n",
"\n",
"1. For project 3, you should feel free to use your own codes from projects 1 and 2, eventually write your own for Decision trees/random forests/bagging/boosting' or use the available functionality of **Scikit-Learn**, **Tensorflow**, PyTorch etc. \n",
"\n",
"2. The estimates you used and tested in projects 1 and 2 should also be included, that is the $R2$-score, **MSE**, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.\n",
"\n",
"3. Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.\n",
"\n",
"4. If possible, you should link the data sets with exisiting research and analyses thereof. Scientific articles which have used Machine Learning algorithms to analyze the data are highly welcome. Perhaps you can improve previous analyses and even publish a new article? \n",
"\n",
"5. A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.\n",
"\n",
"All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..\n",
"\n",
"We propose also an alternative to the above. This is a project on using machine learning methods (neural networks mainly) to the solution of ordinary differential equations and partial differential equations, with a final twist on how to diagonalize a symmetric matrix with neural networks.\n",
"\n",
"This is a field with large scientific interest, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides [from week 43](https://compphysics.github.io/MachineLearning/doc/pub/week43/html/week42.html) and/or the textbook by [Yadav et al](https://www.springer.com/gp/book/9789401798150)."
]
},
{
"cell_type": "markdown",
"id": "6416060c",
"metadata": {
"editable": true
},
"source": [
"## The basic structure of your project\n",
"\n",
"Here follows a set up on how to structure your report and analyze the data you have opted for."
]
},
{
"cell_type": "markdown",
"id": "18827262",
"metadata": {
"editable": true
},
"source": [
"### Part a)\n",
"\n",
"The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context."
]
},
{
"cell_type": "markdown",
"id": "bcee53f4",
"metadata": {
"editable": true
},
"source": [
"### Part b)\n",
"\n",
"You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part."
]
},
{
"cell_type": "markdown",
"id": "83ec8275",
"metadata": {
"editable": true
},
"source": [
"### Part c)\n",
"\n",
"Then describe your algorithm and its implementation and tests you have performed."
]
},
{
"cell_type": "markdown",
"id": "2be62c8e",
"metadata": {
"editable": true
},
"source": [
"### Part d)\n",
"\n",
"Then presents your results and findings, link with existing literature and more."
]
},
{
"cell_type": "markdown",
"id": "385e0b16",
"metadata": {
"editable": true
},
"source": [
"### Part e)\n",
"\n",
"Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature."
]
},
{
"cell_type": "markdown",
"id": "fbf49165",
"metadata": {
"editable": true
},
"source": [
"## Solving partial differential equations with neural networks\n",
"\n",
"For this variant of project 3, we will assume that you have some\n",
"background in the solution of partial differential equations using\n",
"finite difference schemes. We will study the solution of the diffusion\n",
"equation in one dimension using a standard explicit scheme and neural\n",
"networks to solve the same equations.\n",
"\n",
"For the explicit scheme, you can study for example chapter 10 of the lecture notes in [Computational Physics, FYS3150/4150](https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf) or alternative sources from courses like [MAT-MEK4270](https://www.uio.no/studier/emner/matnat/math/MAT-MEK4270/index.html). For the solution of ordinary and partial differential equations using neural networks, the lectures by [included in the lectures of week 43](https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week43.html) at this course are highly recommended.\n",
"\n",
"For the machine learning part you can use your own code from project 2 or the functionality of for example **Tensorflow/Keras**, **PyTorch** or other libraries such [Physics informed machine learning](https://maziarraissi.github.io/PINNs/)."
]
},
{
"cell_type": "markdown",
"id": "c97df4f9",
"metadata": {
"editable": true
},
"source": [
"### Alternative differential equations\n",
"\n",
"Note that you can replace the one-dimensional diffusion equation discussed below with other sets of either ordinary differential equations or partial differential equations.\n",
"Please discuss such a change with us at the lab."
]
},
{
"cell_type": "markdown",
"id": "ecde0a0e",
"metadata": {
"editable": true
},
"source": [
"### Part a), setting up the problem\n",
"\n",
"The physical problem can be that of the temperature gradient in a rod of length $L=1$ at $x=0$ and $x=1$.\n",
"We are looking at a one-dimensional\n",
"problem"
]
},
{
"cell_type": "markdown",
"id": "56429d7e",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"\\frac{\\partial^2 u(x,t)}{\\partial x^2} =\\frac{\\partial u(x,t)}{\\partial t}, t> 0, x\\in [0,L]\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "c2e49662",
"metadata": {
"editable": true
},
"source": [
"or"
]
},
{
"cell_type": "markdown",
"id": "fd661d63",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u_{xx} = u_t,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "a1d77183",
"metadata": {
"editable": true
},
"source": [
"with initial conditions, i.e., the conditions at $t=0$,"
]
},
{
"cell_type": "markdown",
"id": "73d187ef",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u(x,0)= \\sin{(\\pi x)} \\hspace{0.5cm} 0 < x < L,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "b9b49da0",
"metadata": {
"editable": true
},
"source": [
"with $L=1$ the length of the $x$-region of interest. The \n",
"boundary conditions are"
]
},
{
"cell_type": "markdown",
"id": "aee685e3",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u(0,t)= 0 \\hspace{0.5cm} t \\ge 0,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "96ec18ae",
"metadata": {
"editable": true
},
"source": [
"and"
]
},
{
"cell_type": "markdown",
"id": "57c542b7",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u(L,t)= 0 \\hspace{0.5cm} t \\ge 0.\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "b6e8e863",
"metadata": {
"editable": true
},
"source": [
"The function $u(x,t)$ can be the temperature gradient of a rod.\n",
"As time increases, the velocity approaches a linear variation with $x$. \n",
"\n",
"We will limit ourselves to the so-called explicit forward Euler algorithm with discretized versions of time given by a forward formula and a centered difference in space resulting in"
]
},
{
"cell_type": "markdown",
"id": "76ae9476",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u_t\\approx \\frac{u(x,t+\\Delta t)-u(x,t)}{\\Delta t}=\\frac{u(x_i,t_j+\\Delta t)-u(x_i,t_j)}{\\Delta t}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "95e239a3",
"metadata": {
"editable": true
},
"source": [
"and"
]
},
{
"cell_type": "markdown",
"id": "63fb1417",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u_{xx}\\approx \\frac{u(x+\\Delta x,t)-2u(x,t)+u(x-\\Delta x,t)}{\\Delta x^2},\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "e1c77709",
"metadata": {
"editable": true
},
"source": [
"or"
]
},
{
"cell_type": "markdown",
"id": "2631e4bd",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u_{xx}\\approx \\frac{u(x_i+\\Delta x,t_j)-2u(x_i,t_j)+u(x_i-\\Delta x,t_j)}{\\Delta x^2}.\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "0fa54ca3",
"metadata": {
"editable": true
},
"source": [
"Write down the algorithm and the equations you need to implement.\n",
"Find also the analytical solution to the problem."
]
},
{
"cell_type": "markdown",
"id": "7579152d",
"metadata": {
"editable": true
},
"source": [
"### Part b)\n",
"\n",
"Implement the explicit scheme algorithm and perform tests of the solution \n",
"for $\\Delta x=1/10$, $\\Delta x=1/100$ using $\\Delta t$ as dictated by the stability limit of the explicit scheme. The stability criterion for the explicit scheme requires that $\\Delta t/\\Delta x^2 \\leq 1/2$. \n",
"\n",
"Study the solutions at two time points $t_1$ and $t_2$ where $u(x,t_1)$ is smooth but still significantly curved\n",
"and $u(x,t_2)$ is almost linear, close to the stationary state."
]
},
{
"cell_type": "markdown",
"id": "e8ceb962",
"metadata": {
"editable": true
},
"source": [
"### Part c) Neural networks\n",
"\n",
"Study now the lecture notes on solving ODEs and PDEs with neural\n",
"network and use either your own code from project 2 or the\n",
"functionality of tensorflow/keras to solve the same equation as in\n",
"part b). Discuss your results and compare them with the standard\n",
"explicit scheme. Include also the analytical solution and compare with\n",
"that."
]
},
{
"cell_type": "markdown",
"id": "fe5c3f2f",
"metadata": {
"editable": true
},
"source": [
"### Part d) Neural network complexity\n",
"\n",
"Here we study the stability of the results of the results as functions of the number of hidden nodes, layers and activation functions for the hidden layers.\n",
"Increase the number of hidden nodes and layers in order to see if this improves your results. Try also different activation functions for the hidden layers, such as the **tanh**, **ReLU**, and other activation functions. \n",
"Discuss your results."
]
},
{
"cell_type": "markdown",
"id": "3b2adf3a",
"metadata": {
"editable": true
},
"source": [
"### Part e)\n",
"\n",
"Finally, present a critical assessment of the methods you have studied\n",
"and discuss the potential for the solving differential equations with machine learning methods."
]
},
{
"cell_type": "markdown",
"id": "c2ed7243",
"metadata": {
"editable": true
},
"source": [
"## Introduction to numerical projects\n",
"\n",
"Here follows a brief recipe and recommendation on how to write a report for each\n",
"project.\n",
"\n",
" * Give a short description of the nature of the problem and the eventual numerical methods you have used.\n",
"\n",
" * Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.\n",
"\n",
" * Include the source code of your program. Comment your program properly.\n",
"\n",
" * If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.\n",
"\n",
" * Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.\n",
"\n",
" * Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.\n",
"\n",
" * Try to give an interpretation of you results in your answers to the problems.\n",
"\n",
" * Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.\n",
"\n",
" * Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning."
]
},
{
"cell_type": "markdown",
"id": "e9f450e7",
"metadata": {
"editable": true
},
"source": [
"## Format for electronic delivery of report and programs\n",
"\n",
"The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:\n",
"\n",
" * Use Canvas to hand in your projects, log in at <https://www.uio.no/english/services/it/education/canvas/> with your normal UiO username and password.\n",
"\n",
" * Upload **only** the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.\n",
"\n",
" * In your GitHub/GitLab or similar repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.\n",
"\n",
"Finally, \n",
"we encourage you to collaborate. Optimal working groups consist of \n",
"2-3 students. You can then hand in a common report."
]
},
{
"cell_type": "markdown",
"id": "4ec24e55",
"metadata": {
"editable": true
},
"source": [
"## Software and needed installations\n",
"\n",
"If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages, \n",
"we recommend that you install the following Python packages via **pip** as\n",
"1. pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow\n",
"\n",
"For Python3, replace **pip** with **pip3**.\n",
"\n",
"See below for a discussion of **tensorflow** and **scikit-learn**. \n",
"\n",
"For OSX users we recommend also, after having installed Xcode, to install **brew**. Brew allows \n",
"for a seamless installation of additional software via for example\n",
"1. brew install python3\n",
"\n",
"For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution\n",
"you can use **pip** as well and simply install Python as \n",
"1. sudo apt-get install python3 (or python for python2.7)\n",
"\n",
"etc etc. \n",
"\n",
"If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely\n",
"1. [Anaconda](https://docs.anaconda.com/) Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system **conda**\n",
"\n",
"2. [Enthought canopy](https://www.enthought.com/product/canopy/) is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.\n",
"\n",
"Popular software packages written in Python for ML are\n",
"\n",
"* [Scikit-learn](http://scikit-learn.org/stable/), \n",
"\n",
"* [Tensorflow](https://www.tensorflow.org/),\n",
"\n",
"* [PyTorch](http://pytorch.org/) and \n",
"\n",
"* [Keras](https://keras.io/).\n",
"\n",
"These are all freely available at their respective GitHub sites. They \n",
"encompass communities of developers in the thousands or more. And the number\n",
"of code developers and contributors keeps increasing."
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
+34 -7
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -994,13 +1021,13 @@ example of the functionality of <strong>Scikit-Learn</strong>.</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>The intercept alpha:
[2.01173838]
[2.00955125]
Coefficient beta :
[[4.76160572]]
Mean squared error: 0.33
Variance score: 0.86
[[4.94419718]]
Mean squared error: 0.31
Variance score: 0.87
Mean squared log error: 0.01
Mean absolute error: 0.45
Mean absolute error: 0.43
</pre></div>
</div>
<img alt="_images/chapter1_19_1.png" src="_images/chapter1_19_1.png" />
@@ -1100,7 +1127,7 @@ a linear <span class="math notranslate nohighlight">\(x\)</span>-dependence we s
</div>
<div class="cell_output docutils container">
<img alt="_images/chapter1_33_0.png" src="_images/chapter1_33_0.png" />
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.004999999999999991
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.005000000000000001
</pre></div>
</div>
</div>
+84 -453
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -1311,7 +1338,7 @@ the <em>Hadamard product</em>, meaning element-wise multiplication.</p>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Old accuracy on training data: 0.1440501043841336
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1645,7 +1672,7 @@ Lambda = 10.0
Accuracy score on test set: 0.19166666666666668
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1654,7 +1681,7 @@ Lambda = 1e-05
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1663,7 +1690,7 @@ Lambda = 0.0001
Accuracy score on test set: 0.08611111111111111
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1672,7 +1699,7 @@ Lambda = 0.001
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1681,7 +1708,7 @@ Lambda = 0.01
Accuracy score on test set: 0.08888888888888889
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1690,7 +1717,7 @@ Lambda = 0.1
Accuracy score on test set: 0.08611111111111111
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1699,7 +1726,7 @@ Lambda = 1.0
Accuracy score on test set: 0.08888888888888889
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1708,11 +1735,11 @@ Lambda = 10.0
Accuracy score on test set: 0.09166666666666666
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1721,11 +1748,11 @@ Lambda = 1e-05
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1734,11 +1761,11 @@ Lambda = 0.0001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1747,11 +1774,11 @@ Lambda = 0.001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1760,11 +1787,11 @@ Lambda = 0.01
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1773,7 +1800,7 @@ Lambda = 0.1
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1782,11 +1809,11 @@ Lambda = 1.0
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1795,11 +1822,11 @@ Lambda = 10.0
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1808,82 +1835,37 @@ Lambda = 1e-05
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1323/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.0001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.01
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.1
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 1.0
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 10.0
Accuracy score on test set: 0.07777777777777778
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">KeyboardInterrupt</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="n">Cell</span> <span class="n">In</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span> <span class="n">line</span> <span class="mi">11</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">for</span> <span class="n">j</span><span class="p">,</span> <span class="n">lmbd</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lmbd_vals</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">dnn</span> <span class="o">=</span> <span class="n">NeuralNetwork</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">Y_train_onehot</span><span class="p">,</span> <span class="n">eta</span><span class="o">=</span><span class="n">eta</span><span class="p">,</span> <span class="n">lmbd</span><span class="o">=</span><span class="n">lmbd</span><span class="p">,</span> <span class="n">epochs</span><span class="o">=</span><span class="n">epochs</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span>
<span class="g g-Whitespace"> </span><span class="mi">10</span> <span class="n">n_hidden_neurons</span><span class="o">=</span><span class="n">n_hidden_neurons</span><span class="p">,</span> <span class="n">n_categories</span><span class="o">=</span><span class="n">n_categories</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">11</span> <span class="n">dnn</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="n">DNN_numpy</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">dnn</span>
<span class="g g-Whitespace"> </span><span class="mi">15</span> <span class="n">test_predict</span> <span class="o">=</span> <span class="n">dnn</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X_test</span><span class="p">)</span>
<span class="nn">Cell In[6], line 99,</span> in <span class="ni">NeuralNetwork.train</span><span class="nt">(self)</span>
<span class="g g-Whitespace"> </span><span class="mi">96</span> <span class="bp">self</span><span class="o">.</span><span class="n">Y_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Y_data_full</span><span class="p">[</span><span class="n">chosen_datapoints</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">98</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed_forward</span><span class="p">()</span>
<span class="ne">---&gt; </span><span class="mi">99</span> <span class="bp">self</span><span class="o">.</span><span class="n">backpropagation</span><span class="p">()</span>
<span class="nn">Cell In[6], line 64,</span> in <span class="ni">NeuralNetwork.backpropagation</span><span class="nt">(self)</span>
<span class="g g-Whitespace"> </span><span class="mi">61</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_weights_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a_h</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">error_output</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">62</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_bias_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">error_output</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">64</span> <span class="bp">self</span><span class="o">.</span><span class="n">hidden_weights_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">X_data</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">error_hidden</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">65</span> <span class="bp">self</span><span class="o">.</span><span class="n">hidden_bias_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">error_hidden</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">67</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lmbd</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
<span class="ne">KeyboardInterrupt</span>:
</pre></div>
</div>
</div>
@@ -1929,22 +1911,6 @@ Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_48918/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
<img alt="_images/chapter10_59_1.png" src="_images/chapter10_59_1.png" />
<img alt="_images/chapter10_59_2.png" src="_images/chapter10_59_2.png" />
</div>
</div>
</div>
<div class="section" id="scikit-learn-implementation">
@@ -1980,329 +1946,6 @@ performance overall.</p>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 1e-05
Accuracy score on test set: 0.18333333333333332
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.0001
Accuracy score on test set: 0.18611111111111112
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.001
Accuracy score on test set: 0.13055555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.01
Accuracy score on test set: 0.24444444444444444
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.1
Accuracy score on test set: 0.23333333333333334
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 1.0
Accuracy score on test set: 0.12777777777777777
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 10.0
Accuracy score on test set: 0.1527777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 1e-05
Accuracy score on test set: 0.9111111111111111
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.0001
Accuracy score on test set: 0.8888888888888888
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.001
Accuracy score on test set: 0.8722222222222222
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.01
Accuracy score on test set: 0.8305555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.1
Accuracy score on test set: 0.8888888888888888
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 1.0
Accuracy score on test set: 0.8805555555555555
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 10.0
Accuracy score on test set: 0.8944444444444445
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 1e-05
Accuracy score on test set: 0.975
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.0001
Accuracy score on test set: 0.9777777777777777
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.001
Accuracy score on test set: 0.9805555555555555
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.01
Accuracy score on test set: 0.9861111111111112
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.1
Accuracy score on test set: 0.9805555555555555
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 1.0
Accuracy score on test set: 0.9777777777777777
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 10.0
Accuracy score on test set: 0.9444444444444444
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 1e-05
Accuracy score on test set: 0.9861111111111112
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.0001
Accuracy score on test set: 0.9888888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.001
Accuracy score on test set: 0.9888888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.01
Accuracy score on test set: 0.9861111111111112
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.1
Accuracy score on test set: 0.9888888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 1.0
Accuracy score on test set: 0.9722222222222222
Learning rate = 0.01
Lambda = 10.0
Accuracy score on test set: 0.9527777777777777
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 1e-05
Accuracy score on test set: 0.9027777777777778
Learning rate = 0.1
Lambda = 0.0001
Accuracy score on test set: 0.8583333333333333
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 0.001
Accuracy score on test set: 0.8722222222222222
Learning rate = 0.1
Lambda = 0.01
Accuracy score on test set: 0.9055555555555556
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 0.1
Accuracy score on test set: 0.8805555555555555
Learning rate = 0.1
Lambda = 1.0
Accuracy score on test set: 0.8722222222222222
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 10.0
Accuracy score on test set: 0.8666666666666667
Learning rate = 1.0
Lambda = 1e-05
Accuracy score on test set: 0.08611111111111111
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 0.0001
Accuracy score on test set: 0.10555555555555556
Learning rate = 1.0
Lambda = 0.001
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 0.01
Accuracy score on test set: 0.17777777777777778
Learning rate = 1.0
Lambda = 0.1
Accuracy score on test set: 0.08333333333333333
Learning rate = 1.0
Lambda = 1.0
Accuracy score on test set: 0.08888888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 10.0
Accuracy score on test set: 0.09444444444444444
Learning rate = 10.0
Lambda = 1e-05
Accuracy score on test set: 0.17222222222222222
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.0001
Accuracy score on test set: 0.11666666666666667
Learning rate = 10.0
Lambda = 0.001
Accuracy score on test set: 0.10555555555555556
Learning rate = 10.0
Lambda = 0.01
Accuracy score on test set: 0.1388888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.1
Accuracy score on test set: 0.11388888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 1.0
Accuracy score on test set: 0.10555555555555556
Learning rate = 10.0
Lambda = 10.0
Accuracy score on test set: 0.09444444444444444
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="id1">
@@ -2346,10 +1989,6 @@ Accuracy score on test set: 0.09444444444444444
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/chapter10_63_0.png" src="_images/chapter10_63_0.png" />
<img alt="_images/chapter10_63_1.png" src="_images/chapter10_63_1.png" />
</div>
</div>
</div>
<div class="section" id="building-neural-networks-in-tensorflow-and-keras">
@@ -2388,14 +2027,6 @@ and/or if you use <strong>anaconda</strong>, just write (or install from the gra
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span> <span class="n">Cell</span> <span class="n">In</span><span class="p">[</span><span class="mi">12</span><span class="p">],</span> <span class="n">line</span> <span class="mi">1</span>
<span class="n">conda</span> <span class="n">create</span> <span class="o">-</span><span class="n">n</span> <span class="n">tf</span> <span class="n">tensorflow</span>
<span class="o">^</span>
<span class="ne">SyntaxError</span>: invalid syntax
</pre></div>
</div>
</div>
</div>
<p>To install the current release of GPU TensorFlow</p>
<div class="cell docutils container">
+147 -57
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -2577,70 +2604,122 @@ Using TensorFlow results in a much better execution time. Try it!</p>
<span class="g g-Whitespace"> </span><span class="mi">14</span> <span class="n">subargs</span> <span class="o">=</span> <span class="n">subvals</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="nb">zip</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="ne">---&gt; </span><span class="mi">15</span> <span class="k">return</span> <span class="n">fun</span><span class="p">(</span><span class="o">*</span><span class="n">subargs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nn">Cell In[9], line 79,</span> in <span class="ni">cost_function</span><span class="nt">(P, x, t)</span>
<span class="g g-Whitespace"> </span><span class="mi">76</span> <span class="n">point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">x_</span><span class="p">,</span><span class="n">t_</span><span class="p">])</span>
<span class="nn">Cell In[9], line 80,</span> in <span class="ni">cost_function</span><span class="nt">(P, x, t)</span>
<span class="g g-Whitespace"> </span><span class="mi">78</span> <span class="n">g_t</span> <span class="o">=</span> <span class="n">g_trial</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">79</span> <span class="n">g_t_jacobian</span> <span class="o">=</span> <span class="n">g_t_jacobian_func</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">80</span> <span class="n">g_t_hessian</span> <span class="o">=</span> <span class="n">g_t_hessian_func</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">79</span> <span class="n">g_t_jacobian</span> <span class="o">=</span> <span class="n">g_t_jacobian_func</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">80</span> <span class="n">g_t_hessian</span> <span class="o">=</span> <span class="n">g_t_hessian_func</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">82</span> <span class="n">g_t_dt</span> <span class="o">=</span> <span class="n">g_t_jacobian</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="n">g_t_d2x</span> <span class="o">=</span> <span class="n">g_t_hessian</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">18</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">argnum</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">20</span> <span class="k">return</span> <span class="n">unary_operator</span><span class="p">(</span><span class="n">unary_f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="o">*</span><span class="n">nary_op_args</span><span class="p">,</span> <span class="o">**</span><span class="n">nary_op_kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:64,</span> in <span class="ni">jacobian</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">62</span> <span class="n">jacobian_shape</span> <span class="o">=</span> <span class="n">ans_vspace</span><span class="o">.</span><span class="n">shape</span> <span class="o">+</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="g g-Whitespace"> </span><span class="mi">63</span> <span class="n">grads</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">vjp</span><span class="p">,</span> <span class="n">ans_vspace</span><span class="o">.</span><span class="n">standard_basis</span><span class="p">())</span>
<span class="ne">---&gt; </span><span class="mi">64</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">stack</span><span class="p">(</span><span class="n">grads</span><span class="p">),</span> <span class="n">jacobian_shape</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:81,</span> in <span class="ni">hessian</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">78</span> <span class="nd">@unary_to_nary</span>
<span class="g g-Whitespace"> </span><span class="mi">79</span> <span class="k">def</span> <span class="nf">hessian</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">80</span> <span class="s2">&quot;Returns a function that computes the exact Hessian.&quot;</span>
<span class="ne">---&gt; </span><span class="mi">81</span> <span class="k">return</span> <span class="n">jacobian</span><span class="p">(</span><span class="n">jacobian</span><span class="p">(</span><span class="n">fun</span><span class="p">))(</span><span class="n">x</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:88,</span> in <span class="ni">stack</span><span class="nt">(arrays, axis)</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="k">def</span> <span class="nf">stack</span><span class="p">(</span><span class="n">arrays</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">84</span> <span class="c1"># this code is basically copied from numpy/core/shape_base.py&#39;s stack</span>
<span class="g g-Whitespace"> </span><span class="mi">85</span> <span class="c1"># we need it here because we want to re-implement stack in terms of the</span>
<span class="g g-Whitespace"> </span><span class="mi">86</span> <span class="c1"># primitives defined in this file</span>
<span class="ne">---&gt; </span><span class="mi">88</span> <span class="n">arrays</span> <span class="o">=</span> <span class="p">[</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span> <span class="k">for</span> <span class="n">arr</span> <span class="ow">in</span> <span class="n">arrays</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">89</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">arrays</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">90</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;need at least one array to stack&#39;</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">18</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">argnum</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">20</span> <span class="k">return</span> <span class="n">unary_operator</span><span class="p">(</span><span class="n">unary_f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="o">*</span><span class="n">nary_op_args</span><span class="p">,</span> <span class="o">**</span><span class="n">nary_op_kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:88,</span> in <span class="ni">&lt;listcomp&gt;</span><span class="nt">(.0)</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="k">def</span> <span class="nf">stack</span><span class="p">(</span><span class="n">arrays</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">84</span> <span class="c1"># this code is basically copied from numpy/core/shape_base.py&#39;s stack</span>
<span class="g g-Whitespace"> </span><span class="mi">85</span> <span class="c1"># we need it here because we want to re-implement stack in terms of the</span>
<span class="g g-Whitespace"> </span><span class="mi">86</span> <span class="c1"># primitives defined in this file</span>
<span class="ne">---&gt; </span><span class="mi">88</span> <span class="n">arrays</span> <span class="o">=</span> <span class="p">[</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span> <span class="k">for</span> <span class="n">arr</span> <span class="ow">in</span> <span class="n">arrays</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">89</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">arrays</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">90</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;need at least one array to stack&#39;</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:60,</span> in <span class="ni">jacobian</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">50</span> <span class="nd">@unary_to_nary</span>
<span class="g g-Whitespace"> </span><span class="mi">51</span> <span class="k">def</span> <span class="nf">jacobian</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">52</span><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="g g-Whitespace"> </span><span class="mi">53</span><span class="sd"> Returns a function which computes the Jacobian of `fun` with respect to</span>
<span class="g g-Whitespace"> </span><span class="mi">54</span><span class="sd"> positional argument number `argnum`, which must be a scalar or array. Unlike</span>
<span class="sd"> (...)</span>
<span class="g g-Whitespace"> </span><span class="mi">58</span><span class="sd"> (out1, out2, ...) then the Jacobian has shape (out1, out2, ..., in1, in2, ...).</span>
<span class="g g-Whitespace"> </span><span class="mi">59</span><span class="sd"> &quot;&quot;&quot;</span>
<span class="ne">---&gt; </span><span class="mi">60</span> <span class="n">vjp</span><span class="p">,</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">_make_vjp</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">61</span> <span class="n">ans_vspace</span> <span class="o">=</span> <span class="n">vspace</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">62</span> <span class="n">jacobian_shape</span> <span class="o">=</span> <span class="n">ans_vspace</span><span class="o">.</span><span class="n">shape</span> <span class="o">+</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:14,</span> in <span class="ni">make_vjp.&lt;locals&gt;.vjp</span><span class="nt">(g)</span>
<span class="ne">---&gt; </span><span class="mi">14</span> <span class="k">def</span> <span class="nf">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">):</span> <span class="k">return</span> <span class="n">backward_pass</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">end_node</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:10,</span> in <span class="ni">make_vjp</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">def</span> <span class="nf">make_vjp</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">start_node</span> <span class="o">=</span> <span class="n">VJPNode</span><span class="o">.</span><span class="n">new_root</span><span class="p">()</span>
<span class="ne">---&gt; </span><span class="mi">10</span> <span class="n">end_value</span><span class="p">,</span> <span class="n">end_node</span> <span class="o">=</span> <span class="n">trace</span><span class="p">(</span><span class="n">start_node</span><span class="p">,</span> <span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">11</span> <span class="k">if</span> <span class="n">end_node</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">12</span> <span class="k">def</span> <span class="nf">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">):</span> <span class="k">return</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">zeros</span><span class="p">()</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:21,</span> in <span class="ni">backward_pass</span><span class="nt">(g, end_node)</span>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">toposort</span><span class="p">(</span><span class="n">end_node</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">20</span> <span class="n">outgrad</span> <span class="o">=</span> <span class="n">outgrads</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">21</span> <span class="n">ingrads</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">vjp</span><span class="p">(</span><span class="n">outgrad</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="g g-Whitespace"> </span><span class="mi">22</span> <span class="k">for</span> <span class="n">parent</span><span class="p">,</span> <span class="n">ingrad</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">,</span> <span class="n">ingrads</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">23</span> <span class="n">outgrads</span><span class="p">[</span><span class="n">parent</span><span class="p">]</span> <span class="o">=</span> <span class="n">add_outgrads</span><span class="p">(</span><span class="n">outgrads</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">parent</span><span class="p">),</span> <span class="n">ingrad</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:10,</span> in <span class="ni">trace</span><span class="nt">(start_node, fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">with</span> <span class="n">trace_stack</span><span class="o">.</span><span class="n">new_trace</span><span class="p">()</span> <span class="k">as</span> <span class="n">t</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">start_box</span> <span class="o">=</span> <span class="n">new_box</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">start_node</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">10</span> <span class="n">end_box</span> <span class="o">=</span> <span class="n">fun</span><span class="p">(</span><span class="n">start_box</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">11</span> <span class="k">if</span> <span class="n">isbox</span><span class="p">(</span><span class="n">end_box</span><span class="p">)</span> <span class="ow">and</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_trace</span> <span class="o">==</span> <span class="n">start_box</span><span class="o">.</span><span class="n">_trace</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">12</span> <span class="k">return</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_value</span><span class="p">,</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_node</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:67,</span> in <span class="ni">defvjp.&lt;locals&gt;.vjp_argnums.&lt;locals&gt;.&lt;lambda&gt;</span><span class="nt">(g)</span>
<span class="g g-Whitespace"> </span><span class="mi">64</span> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span>
<span class="g g-Whitespace"> </span><span class="mi">65</span> <span class="s2">&quot;VJP of </span><span class="si">{}</span><span class="s2"> wrt argnum 0 not defined&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fun</span><span class="o">.</span><span class="vm">__name__</span><span class="p">))</span>
<span class="g g-Whitespace"> </span><span class="mi">66</span> <span class="n">vjp</span> <span class="o">=</span> <span class="n">vjpfun</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">67</span> <span class="k">return</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="p">(</span><span class="n">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">),)</span>
<span class="g g-Whitespace"> </span><span class="mi">68</span> <span class="k">elif</span> <span class="n">L</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">69</span> <span class="n">argnum_0</span><span class="p">,</span> <span class="n">argnum_1</span> <span class="o">=</span> <span class="n">argnums</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:15,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f.&lt;locals&gt;.unary_f</span><span class="nt">(x)</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">14</span> <span class="n">subargs</span> <span class="o">=</span> <span class="n">subvals</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="nb">zip</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="ne">---&gt; </span><span class="mi">15</span> <span class="k">return</span> <span class="n">fun</span><span class="p">(</span><span class="o">*</span><span class="n">subargs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:660,</span> in <span class="ni">unbroadcast_f.&lt;locals&gt;.&lt;lambda&gt;</span><span class="nt">(g)</span>
<span class="g g-Whitespace"> </span><span class="mi">658</span> <span class="k">def</span> <span class="nf">unbroadcast_f</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">659</span> <span class="n">target_meta</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">metadata</span><span class="p">(</span><span class="n">target</span><span class="p">)</span>
<span class="ne">--&gt; </span><span class="mi">660</span> <span class="k">return</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="n">unbroadcast</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">g</span><span class="p">),</span> <span class="n">target_meta</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">18</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">argnum</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">20</span> <span class="k">return</span> <span class="n">unary_operator</span><span class="p">(</span><span class="n">unary_f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="o">*</span><span class="n">nary_op_args</span><span class="p">,</span> <span class="o">**</span><span class="n">nary_op_kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:653,</span> in <span class="ni">unbroadcast</span><span class="nt">(x, target_meta, broadcast_idx)</span>
<span class="g g-Whitespace"> </span><span class="mi">651</span> <span class="k">for</span> <span class="n">axis</span><span class="p">,</span> <span class="n">size</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">target_shape</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">652</span> <span class="k">if</span> <span class="n">size</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="ne">--&gt; </span><span class="mi">653</span> <span class="n">x</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">654</span> <span class="k">if</span> <span class="n">anp</span><span class="o">.</span><span class="n">iscomplexobj</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">target_iscomplex</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">655</span> <span class="n">x</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">real</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:60,</span> in <span class="ni">jacobian</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">50</span> <span class="nd">@unary_to_nary</span>
<span class="g g-Whitespace"> </span><span class="mi">51</span> <span class="k">def</span> <span class="nf">jacobian</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">52</span><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="g g-Whitespace"> </span><span class="mi">53</span><span class="sd"> Returns a function which computes the Jacobian of `fun` with respect to</span>
<span class="g g-Whitespace"> </span><span class="mi">54</span><span class="sd"> positional argument number `argnum`, which must be a scalar or array. Unlike</span>
<span class="sd"> (...)</span>
<span class="g g-Whitespace"> </span><span class="mi">58</span><span class="sd"> (out1, out2, ...) then the Jacobian has shape (out1, out2, ..., in1, in2, ...).</span>
<span class="g g-Whitespace"> </span><span class="mi">59</span><span class="sd"> &quot;&quot;&quot;</span>
<span class="ne">---&gt; </span><span class="mi">60</span> <span class="n">vjp</span><span class="p">,</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">_make_vjp</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">61</span> <span class="n">ans_vspace</span> <span class="o">=</span> <span class="n">vspace</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">62</span> <span class="n">jacobian_shape</span> <span class="o">=</span> <span class="n">ans_vspace</span><span class="o">.</span><span class="n">shape</span> <span class="o">+</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:10,</span> in <span class="ni">make_vjp</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">def</span> <span class="nf">make_vjp</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">start_node</span> <span class="o">=</span> <span class="n">VJPNode</span><span class="o">.</span><span class="n">new_root</span><span class="p">()</span>
<span class="ne">---&gt; </span><span class="mi">10</span> <span class="n">end_value</span><span class="p">,</span> <span class="n">end_node</span> <span class="o">=</span> <span class="n">trace</span><span class="p">(</span><span class="n">start_node</span><span class="p">,</span> <span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">11</span> <span class="k">if</span> <span class="n">end_node</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">12</span> <span class="k">def</span> <span class="nf">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">):</span> <span class="k">return</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">zeros</span><span class="p">()</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:10,</span> in <span class="ni">trace</span><span class="nt">(start_node, fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">with</span> <span class="n">trace_stack</span><span class="o">.</span><span class="n">new_trace</span><span class="p">()</span> <span class="k">as</span> <span class="n">t</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">start_box</span> <span class="o">=</span> <span class="n">new_box</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">start_node</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">10</span> <span class="n">end_box</span> <span class="o">=</span> <span class="n">fun</span><span class="p">(</span><span class="n">start_box</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">11</span> <span class="k">if</span> <span class="n">isbox</span><span class="p">(</span><span class="n">end_box</span><span class="p">)</span> <span class="ow">and</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_trace</span> <span class="o">==</span> <span class="n">start_box</span><span class="o">.</span><span class="n">_trace</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">12</span> <span class="k">return</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_value</span><span class="p">,</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_node</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:15,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f.&lt;locals&gt;.unary_f</span><span class="nt">(x)</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">14</span> <span class="n">subargs</span> <span class="o">=</span> <span class="n">subvals</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="nb">zip</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="ne">---&gt; </span><span class="mi">15</span> <span class="k">return</span> <span class="n">fun</span><span class="p">(</span><span class="o">*</span><span class="n">subargs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:15,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f.&lt;locals&gt;.unary_f</span><span class="nt">(x)</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">14</span> <span class="n">subargs</span> <span class="o">=</span> <span class="n">subvals</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="nb">zip</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="ne">---&gt; </span><span class="mi">15</span> <span class="k">return</span> <span class="n">fun</span><span class="p">(</span><span class="o">*</span><span class="n">subargs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nn">Cell In[9], line 61,</span> in <span class="ni">g_trial</span><span class="nt">(point, P)</span>
<span class="g g-Whitespace"> </span><span class="mi">59</span> <span class="k">def</span> <span class="nf">g_trial</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">60</span> <span class="n">x</span><span class="p">,</span><span class="n">t</span> <span class="o">=</span> <span class="n">point</span>
<span class="ne">---&gt; </span><span class="mi">61</span> <span class="k">return</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">t</span><span class="p">)</span><span class="o">*</span><span class="n">u</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">t</span><span class="o">*</span><span class="n">deep_neural_network</span><span class="p">(</span><span class="n">P</span><span class="p">,</span><span class="n">point</span><span class="p">)</span>
<span class="nn">Cell In[9], line 48,</span> in <span class="ni">deep_neural_network</span><span class="nt">(deep_params, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">45</span> <span class="n">w_output</span> <span class="o">=</span> <span class="n">deep_params</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">47</span> <span class="c1"># Include bias:</span>
<span class="ne">---&gt; </span><span class="mi">48</span> <span class="n">x_prev</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span><span class="n">num_points</span><span class="p">)),</span> <span class="n">x_prev</span><span class="p">),</span> <span class="n">axis</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">50</span> <span class="n">z_output</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">w_output</span><span class="p">,</span> <span class="n">x_prev</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">51</span> <span class="n">x_output</span> <span class="o">=</span> <span class="n">z_output</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:38,</span> in <span class="ni">&lt;lambda&gt;</span><span class="nt">(arr_list, axis)</span>
<span class="g g-Whitespace"> </span><span class="mi">35</span> <span class="nd">@primitive</span>
<span class="g g-Whitespace"> </span><span class="mi">36</span> <span class="k">def</span> <span class="nf">concatenate_args</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">37</span> <span class="k">return</span> <span class="n">_np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">axis</span><span class="p">)</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">ndarray</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">38</span> <span class="n">concatenate</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">arr_list</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span> <span class="p">:</span> <span class="n">concatenate_args</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="o">*</span><span class="n">arr_list</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">39</span> <span class="n">vstack</span> <span class="o">=</span> <span class="n">row_stack</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">tup</span><span class="p">:</span> <span class="n">concatenate</span><span class="p">([</span><span class="n">atleast_2d</span><span class="p">(</span><span class="n">_m</span><span class="p">)</span> <span class="k">for</span> <span class="n">_m</span> <span class="ow">in</span> <span class="n">tup</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">40</span> <span class="k">def</span> <span class="nf">hstack</span><span class="p">(</span><span class="n">tup</span><span class="p">):</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:45,</span> in <span class="ni">primitive.&lt;locals&gt;.f_wrapped</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">43</span> <span class="n">argnums</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">argnum</span> <span class="k">for</span> <span class="n">argnum</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="n">boxed_args</span><span class="p">)</span>
@@ -2655,13 +2734,24 @@ Using TensorFlow results in a much better execution time. Try it!</p>
<span class="g g-Whitespace"> </span><span class="mi">35</span> <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fun_name</span><span class="p">,</span> <span class="n">parent_argnums</span><span class="p">))</span>
<span class="ne">---&gt; </span><span class="mi">36</span> <span class="bp">self</span><span class="o">.</span><span class="n">vjp</span> <span class="o">=</span> <span class="n">vjpmaker</span><span class="p">(</span><span class="n">parent_argnums</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:56,</span> in <span class="ni">defvjp.&lt;locals&gt;.vjp_argnums</span><span class="nt">(argnums, ans, args, kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">53</span> <span class="n">argnums</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;argnums&#39;</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span>
<span class="g g-Whitespace"> </span><span class="mi">54</span> <span class="n">vjps_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">argnum</span> <span class="p">:</span> <span class="n">translate_vjp</span><span class="p">(</span><span class="n">vjpmaker</span><span class="p">,</span> <span class="n">fun</span><span class="p">,</span> <span class="n">argnum</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">55</span> <span class="k">for</span> <span class="n">argnum</span><span class="p">,</span> <span class="n">vjpmaker</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">argnums</span><span class="p">,</span> <span class="n">vjpmakers</span><span class="p">)}</span>
<span class="ne">---&gt; </span><span class="mi">56</span> <span class="k">def</span> <span class="nf">vjp_argnums</span><span class="p">(</span><span class="n">argnums</span><span class="p">,</span> <span class="n">ans</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">57</span> <span class="n">L</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">argnums</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">58</span> <span class="c1"># These first two cases are just optimizations</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:48,</span> in <span class="ni">defvjp_argnum.&lt;locals&gt;.vjp_argnums</span><span class="nt">(argnums, *args)</span>
<span class="g g-Whitespace"> </span><span class="mi">47</span> <span class="k">def</span> <span class="nf">vjp_argnums</span><span class="p">(</span><span class="n">argnums</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="ne">---&gt; </span><span class="mi">48</span> <span class="n">vjps</span> <span class="o">=</span> <span class="p">[</span><span class="n">vjpmaker</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span> <span class="k">for</span> <span class="n">argnum</span> <span class="ow">in</span> <span class="n">argnums</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">49</span> <span class="k">return</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="p">(</span><span class="n">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> <span class="k">for</span> <span class="n">vjp</span> <span class="ow">in</span> <span class="n">vjps</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:48,</span> in <span class="ni">&lt;listcomp&gt;</span><span class="nt">(.0)</span>
<span class="g g-Whitespace"> </span><span class="mi">47</span> <span class="k">def</span> <span class="nf">vjp_argnums</span><span class="p">(</span><span class="n">argnums</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="ne">---&gt; </span><span class="mi">48</span> <span class="n">vjps</span> <span class="o">=</span> <span class="p">[</span><span class="n">vjpmaker</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span> <span class="k">for</span> <span class="n">argnum</span> <span class="ow">in</span> <span class="n">argnums</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">49</span> <span class="k">return</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="p">(</span><span class="n">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> <span class="k">for</span> <span class="n">vjp</span> <span class="ow">in</span> <span class="n">vjps</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:537,</span> in <span class="ni">grad_concatenate_args</span><span class="nt">(argnum, ans, axis_args, kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">532</span> <span class="n">defvjp</span><span class="p">(</span><span class="n">tensordot_adjoint_1</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">ans</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">G</span><span class="p">,</span> <span class="n">axes</span><span class="p">,</span> <span class="n">An</span><span class="p">,</span> <span class="n">Bn</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">B</span><span class="p">:</span> <span class="n">match_complex</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">tensordot_adjoint_0</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">G</span><span class="p">,</span> <span class="n">axes</span><span class="p">,</span> <span class="n">An</span><span class="p">,</span> <span class="n">Bn</span><span class="p">)),</span>
<span class="g g-Whitespace"> </span><span class="mi">533</span> <span class="k">lambda</span> <span class="n">ans</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">G</span><span class="p">,</span> <span class="n">axes</span><span class="p">,</span> <span class="n">An</span><span class="p">,</span> <span class="n">Bn</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">B</span><span class="p">:</span> <span class="n">match_complex</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">anp</span><span class="o">.</span><span class="n">tensordot</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">axes</span><span class="p">)))</span>
<span class="g g-Whitespace"> </span><span class="mi">534</span> <span class="n">defvjp</span><span class="p">(</span><span class="n">anp</span><span class="o">.</span><span class="n">outer</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">ans</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="p">:</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="n">match_complex</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">anp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">T</span><span class="p">)),</span>
<span class="g g-Whitespace"> </span><span class="mi">535</span> <span class="k">lambda</span> <span class="n">ans</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="p">:</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="n">match_complex</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">anp</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">g</span><span class="p">)))</span>
<span class="ne">--&gt; </span><span class="mi">537</span> <span class="k">def</span> <span class="nf">grad_concatenate_args</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="n">ans</span><span class="p">,</span> <span class="n">axis_args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">538</span> <span class="n">axis</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">axis_args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">axis_args</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
<span class="g g-Whitespace"> </span><span class="mi">539</span> <span class="n">sizes</span> <span class="o">=</span> <span class="p">[</span><span class="n">anp</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">a</span><span class="p">)[</span><span class="n">axis</span><span class="p">]</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[:</span><span class="n">argnum</span><span class="p">]]</span>
<span class="ne">KeyboardInterrupt</span>:
</pre></div>
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+86 -59
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -1243,10 +1270,10 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.15792278643800434
3.469596964296967
[[0.82924408 2.51097872]
[2.51097872 8.91660026]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.05005634426334421
4.366375489616074
[[ 0.93787605 2.95563211]
[ 2.95563211 10.33025801]]
</pre></div>
</div>
</div>
@@ -1283,10 +1310,10 @@ a more brute force way. Here we scale the mean values for each column of the des
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08557805981945521
1.6515332649941654
[[1. 0.67509467]
[0.67509467 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.07808426989543932
1.4121966338442804
[[1. 0.70362677]
[0.70362677 1. ]]
</pre></div>
</div>
</div>
@@ -1316,30 +1343,30 @@ this matrix we easily see that it is a positive definite matrix.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[-1.2222736 -2.47780495]
[-0.84963695 -3.33047051]
[ 1.52869849 3.46922796]
[-0.31385129 -1.2500845 ]
[-0.02761005 0.80816668]
[-0.79036971 -1.8310483 ]
[ 0.22681817 -0.28207517]
[-0.69475072 -1.99810021]
[-0.17979265 -0.38267862]
[ 2.3227683 7.27486761]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[-0.34661376 -1.6809195 ]
[ 0.05792927 0.30915293]
[ 0.65183066 3.00564344]
[ 1.75018686 4.35667342]
[-0.75682834 -1.67875366]
[ 1.16654048 3.9065894 ]
[-1.86267497 -5.53585173]
[ 0.29803738 2.45731144]
[-0.63031478 -2.76157429]
[-0.3280928 -2.37827145]]
0 1
0 -1.222274 -2.477805
1 -0.849637 -3.330471
2 1.528698 3.469228
3 -0.313851 -1.250084
4 -0.027610 0.808167
5 -0.790370 -1.831048
6 0.226818 -0.282075
7 -0.694751 -1.998100
8 -0.179793 -0.382679
9 2.322768 7.274868
0 -0.346614 -1.680920
1 0.057929 0.309153
2 0.651831 3.005643
3 1.750187 4.356673
4 -0.756828 -1.678754
5 1.166540 3.906589
6 -1.862675 -5.535852
7 0.298037 2.457311
8 -0.630315 -2.761574
9 -0.328093 -2.378271
0 1
0 1.000000 0.972591
1 0.972591 1.000000
0 1.000000 0.959076
1 0.959076 1.000000
</pre></div>
</div>
</div>
@@ -1396,37 +1423,37 @@ this matrix we easily see that it is a positive definite matrix.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1 2 3 4 5 6 7 \
0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.0 0.078704 0.076964 0.076716 0.075698 0.074706 0.067097 0.066458
2 0.0 0.076964 0.076620 0.076716 0.076383 0.075972 0.068301 0.068022
3 0.0 0.076716 0.076716 0.079642 0.079578 0.079412 0.072860 0.072759
4 0.0 0.075698 0.076383 0.079578 0.079873 0.080016 0.073481 0.073581
5 0.0 0.074706 0.075972 0.079412 0.080016 0.080425 0.073934 0.074208
6 0.0 0.067097 0.068301 0.072860 0.073481 0.073934 0.068963 0.069275
7 0.0 0.066458 0.068022 0.072759 0.073581 0.074208 0.069275 0.069704
8 0.0 0.065860 0.067729 0.072633 0.073627 0.074407 0.069521 0.070054
9 0.0 0.065299 0.067429 0.072489 0.073634 0.074548 0.069717 0.070342
10 0.0 0.058190 0.060003 0.065359 0.066349 0.067149 0.063511 0.064061
11 0.0 0.057786 0.059797 0.065273 0.066380 0.067284 0.063684 0.064307
12 0.0 0.057415 0.059597 0.065186 0.066395 0.067392 0.063832 0.064521
13 0.0 0.057076 0.059406 0.065101 0.066402 0.067482 0.063965 0.064713
14 0.0 0.056767 0.059226 0.065024 0.066406 0.067560 0.064087 0.064889
1 0.0 0.084996 0.084434 0.084712 0.085455 0.086212 0.075771 0.076638
2 0.0 0.084434 0.084514 0.084042 0.085120 0.086230 0.075176 0.076259
3 0.0 0.084712 0.084042 0.089718 0.090439 0.091159 0.083479 0.084358
4 0.0 0.085455 0.085120 0.090439 0.091388 0.092347 0.084091 0.085139
5 0.0 0.086212 0.086230 0.091159 0.092347 0.093554 0.084695 0.085918
6 0.0 0.075771 0.075176 0.083479 0.084091 0.084695 0.079903 0.080657
7 0.0 0.076638 0.076259 0.084358 0.085139 0.085918 0.080657 0.081544
8 0.0 0.077567 0.077411 0.085294 0.086250 0.087210 0.081457 0.082482
9 0.0 0.078557 0.078636 0.086286 0.087424 0.088574 0.082303 0.083471
10 0.0 0.066997 0.066458 0.075909 0.076389 0.076857 0.074221 0.074824
11 0.0 0.067764 0.067380 0.076693 0.077304 0.077906 0.074892 0.075602
12 0.0 0.068592 0.068369 0.077539 0.078284 0.079027 0.075615 0.076436
13 0.0 0.069484 0.069427 0.078447 0.079334 0.080222 0.076393 0.077329
14 0.0 0.070441 0.070558 0.079420 0.080453 0.081494 0.077226 0.078282
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.065860 0.065299 0.058190 0.057786 0.057415 0.057076 0.056767
2 0.067729 0.067429 0.060003 0.059797 0.059597 0.059406 0.059226
3 0.072633 0.072489 0.065359 0.065273 0.065186 0.065101 0.065024
4 0.073627 0.073634 0.066349 0.066380 0.066395 0.066402 0.066406
5 0.074407 0.074548 0.067149 0.067284 0.067392 0.067482 0.067560
6 0.069521 0.069717 0.063511 0.063684 0.063832 0.063965 0.064087
7 0.070054 0.070342 0.064061 0.064307 0.064521 0.064713 0.064889
8 0.070496 0.070868 0.064530 0.064841 0.065115 0.065361 0.065588
9 0.070868 0.071315 0.064933 0.065304 0.065633 0.065930 0.066204
10 0.064530 0.064933 0.059711 0.060043 0.060340 0.060612 0.060864
11 0.064841 0.065304 0.060043 0.060422 0.060764 0.061076 0.061367
12 0.065115 0.065633 0.060340 0.060764 0.061146 0.061496 0.061822
13 0.065361 0.065930 0.060612 0.061076 0.061496 0.061882 0.062242
14 0.065588 0.066204 0.060864 0.061367 0.061822 0.062242 0.062634
1 0.077567 0.078557 0.066997 0.067764 0.068592 0.069484 0.070441
2 0.077411 0.078636 0.066458 0.067380 0.068369 0.069427 0.070558
3 0.085294 0.086286 0.075909 0.076693 0.077539 0.078447 0.079420
4 0.086250 0.087424 0.076389 0.077304 0.078284 0.079334 0.080453
5 0.087210 0.088574 0.076857 0.077906 0.079027 0.080222 0.081494
6 0.081457 0.082303 0.074221 0.074892 0.075615 0.076393 0.077226
7 0.082482 0.083471 0.074824 0.075602 0.076436 0.077329 0.078282
8 0.083564 0.084702 0.075463 0.076351 0.077301 0.078313 0.079391
9 0.084702 0.085996 0.076138 0.077141 0.078210 0.079347 0.080555
10 0.075463 0.076138 0.070095 0.070630 0.071208 0.071831 0.072500
11 0.076351 0.077141 0.070630 0.071252 0.071921 0.072638 0.073405
12 0.077301 0.078210 0.071208 0.071921 0.072684 0.073499 0.074368
13 0.078313 0.079347 0.071831 0.072638 0.073499 0.074417 0.075392
14 0.079391 0.080555 0.072500 0.073405 0.074368 0.075392 0.076479
</pre></div>
</div>
</div>
+56 -31
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -797,10 +824,10 @@ number <span class="math notranslate nohighlight">\(i\)</span> is left out. Usin
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 0.148282 sec
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 0.14708 sec
Jackknife Statistics :
original bias std. error
99.9492 99.9392 0.150707
100.034 100.024 0.147836
</pre></div>
</div>
</div>
@@ -1019,7 +1046,7 @@ theorem.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Bootstrap Statistics :
original bias std. error
100.154 14.9603 100.154 0.149425
100.179 15.0422 100.179 0.151522
</pre></div>
</div>
</div>
@@ -1236,9 +1263,7 @@ Error: 0.06547790180152355
Bias^2: 0.06208238634231949
Var: 0.0033955154592040936
0.06547790180152355 &gt;= 0.06208238634231949 + 0.0033955154592040936 = 0.06547790180152359
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 4
Polynomial degree: 4
Error: 0.06844519414009445
Bias^2: 0.06453579006728324
Var: 0.003909404072811226
@@ -1265,14 +1290,14 @@ Error: 0.017355848195593347
Bias^2: 0.010331721306655127
Var: 0.007024126888938232
0.017355848195593347 &gt;= 0.010331721306655127 + 0.007024126888938232 = 0.01735584819559336
Polynomial degree: 9
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 9
Error: 0.02660572763718093
Bias^2: 0.010018312644137363
Var: 0.016587414993043573
0.02660572763718093 &gt;= 0.010018312644137363 + 0.016587414993043573 = 0.026605727637180936
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 10
Polynomial degree: 10
Error: 0.021592704588025025
Bias^2: 0.010516485576645508
Var: 0.011076219011379514
@@ -1294,7 +1319,7 @@ Var: 0.20867052175034223
0.22842468702219465 &gt;= 0.01975416527185249 + 0.20867052175034223 = 0.2284246870221947
</pre></div>
</div>
<img alt="_images/chapter3_66_4.png" src="_images/chapter3_66_4.png" />
<img alt="_images/chapter3_66_3.png" src="_images/chapter3_66_3.png" />
</div>
</div>
<p>The bias-variance tradeoff summarizes the fundamental tension in
@@ -1609,9 +1634,9 @@ Mean squared error on training data: 0.00060704
Mean squared error on test data: 3262.26814548
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(trainingerror), label=&#39;Training Error&#39;)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(testerror), label=&#39;Test Error&#39;)
</pre></div>
</div>
@@ -1845,7 +1870,7 @@ cross-validation (LOOCV).</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(estimated_mse_sklearn), label=&#39;Test Error&#39;)
</pre></div>
</div>
@@ -2734,7 +2759,7 @@ linear system as an equation would reduce this down to
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/4162706317.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/4162706317.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -2878,7 +2903,7 @@ with the form utilized in linear regression, viz.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/3777801602.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/3777801602.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -2918,7 +2943,7 @@ cost function is given by</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/438060758.py:10: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/438060758.py:10: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -2953,7 +2978,7 @@ cost function is given by</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49101/3544313922.py:9: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1390/3544313922.py:9: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -3006,43 +3031,43 @@ constant as opposed to ridge and OLS. We get a sparse solution with
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0%| | 0/10 [00:00&lt;?, ?it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0%| | 0/10 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/linear_model/_coordinate_descent.py:628: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 3.924e+00, tolerance: 1.797e+00
model = cd_fast.enet_coordinate_descent(
10%|██████████ | 1/10 [00:01&lt;00:11, 1.25s/it]
10%|███████████████████▏ | 1/10 [00:00&lt;00:07, 1.14it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 20%|████████████████████ | 2/10 [00:02&lt;00:09, 1.24s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 20%|██████████████████████████████████████▍ | 2/10 [00:01&lt;00:07, 1.13it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 30%|██████████████████████████████ | 3/10 [00:03&lt;00:07, 1.14s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 30%|█████████████████████████████████████████████████████████▌ | 3/10 [00:02&lt;00:05, 1.24it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 40%|████████████████████████████████████████ | 4/10 [00:04&lt;00:06, 1.01s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 40%|████████████████████████████████████████████████████████████████████████████▊ | 4/10 [00:03&lt;00:04, 1.31it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 50%|██████████████████████████████████████████████████ | 5/10 [00:05&lt;00:04, 1.01it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 50%|████████████████████████████████████████████████████████████████████████████████████████████████ | 5/10 [00:03&lt;00:03, 1.33it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 60%|████████████████████████████████████████████████████████████ | 6/10 [00:06&lt;00:03, 1.00it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 60%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 6/10 [00:04&lt;00:03, 1.30it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 70%|██████████████████████████████████████████████████████████████████████ | 7/10 [00:07&lt;00:03, 1.02s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 70%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 7/10 [00:05&lt;00:02, 1.28it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 80%|████████████████████████████████████████████████████████████████████████████████ | 8/10 [00:08&lt;00:01, 1.02it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 80%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 8/10 [00:06&lt;00:01, 1.33it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 90%|██████████████████████████████████████████████████████████████████████████████████████████ | 9/10 [00:09&lt;00:01, 1.01s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 90%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊ | 9/10 [00:07&lt;00:00, 1.30it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:10&lt;00:00, 1.00s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:07&lt;00:00, 1.35it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:10&lt;00:00, 1.03s/it]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:07&lt;00:00, 1.30it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+37 -10
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -725,9 +752,9 @@ predicting the target features of query instances is as follows:</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>2nd degree coefficients:
zero power: 7.373465215701515
first power: -0.037299816041296285
second power: 0.00019961646575285301
zero power: 2.1810415856976313
first power: -0.2546817701709956
second power: 0.0008297120772365539
</pre></div>
</div>
<img alt="_images/chapter6_1_1.png" src="_images/chapter6_1_1.png" />
@@ -1590,16 +1617,16 @@ attributes at each step while growing the tree.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>(426, 30)
(143, 30)
Test set accuracy with Logistic Regression: 0.94
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Test set accuracy with Logistic Regression: 0.94
Test set accuracy with SVM: 0.63
Test set accuracy with Decision Trees: 0.90
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Test set accuracy with SVM: 0.63
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Test set accuracy with Decision Trees: 0.90
Test set accuracy Logistic Regression with scaled data: 0.96
Test set accuracy SVM with scaled data: 0.96
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Test set accuracy with Decision Trees and scaled data: 0.89
Test set accuracy with Decision Trees and scaled data: 0.89
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/linear_model/_logistic.py:460: ConvergenceWarning: lbfgs failed to converge (status=1):
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+99 -74
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -679,10 +706,10 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.046842629321028326
3.909446359461397
[[0.76681867 2.32238906]
[2.32238906 8.10983159]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.1477190177681485
3.5426270409877345
[[1.01393496 3.02432309]
[3.02432309 9.86643649]]
</pre></div>
</div>
</div>
@@ -722,10 +749,10 @@ a more brute force way. Here we scale the mean values for each column of the des
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.0798590438380667
1.270350130579073
[[1. 0.58734026]
[0.58734026 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08793554992813543
1.9271707090281667
[[1. 0.6690108]
[0.6690108 1. ]]
</pre></div>
</div>
</div>
@@ -754,30 +781,30 @@ this matrix we easily see that it is a positive definite matrix.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[-0.34565973 -1.4704785 ]
[-0.29669702 -0.75437273]
[ 1.05100602 2.13022421]
[ 0.40103689 3.11022072]
[ 0.01591047 -0.05087888]
[-0.89261577 -1.74947597]
[-0.21796226 -0.62901905]
[-0.5961905 -2.9242511 ]
[ 0.39428522 1.65208925]
[ 0.48688666 0.68594205]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[-0.95395895 -3.11535632]
[ 1.05641352 3.6533977 ]
[ 0.801356 4.56475921]
[-0.69136414 -1.7642448 ]
[ 0.68822559 0.63896182]
[ 0.30916988 1.25233253]
[ 0.10008326 0.10539984]
[-0.52155823 -1.85777073]
[ 0.24377554 0.94616709]
[-1.03214247 -4.42364634]]
0 1
0 -0.345660 -1.470478
1 -0.296697 -0.754373
2 1.051006 2.130224
3 0.401037 3.110221
4 0.015910 -0.050879
5 -0.892616 -1.749476
6 -0.217962 -0.629019
7 -0.596190 -2.924251
8 0.394285 1.652089
9 0.486887 0.685942
0 1
0 1.00000 0.87078
1 0.87078 1.00000
0 -0.953959 -3.115356
1 1.056414 3.653398
2 0.801356 4.564759
3 -0.691364 -1.764245
4 0.688226 0.638962
5 0.309170 1.252333
6 0.100083 0.105400
7 -0.521558 -1.857771
8 0.243776 0.946167
9 -1.032142 -4.423646
0 1
0 1.000000 0.947607
1 0.947607 1.000000
</pre></div>
</div>
</div>
@@ -834,37 +861,37 @@ this matrix we easily see that it is a positive definite matrix.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1 2 3 4 5 6 7 \
0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.0 0.078785 0.081798 0.081422 0.083540 0.085693 0.075398 0.077082
2 0.0 0.081798 0.085346 0.084157 0.086550 0.088986 0.077522 0.079381
3 0.0 0.081422 0.084157 0.090290 0.092347 0.094426 0.087176 0.088908
4 0.0 0.083540 0.086550 0.092347 0.094577 0.096837 0.088893 0.090751
5 0.0 0.085693 0.088986 0.094426 0.096837 0.099287 0.090623 0.092613
6 0.0 0.075398 0.077522 0.087176 0.088893 0.090623 0.086538 0.088061
7 0.0 0.077082 0.079381 0.088908 0.090751 0.092613 0.088061 0.089682
8 0.0 0.078824 0.081308 0.090696 0.092672 0.094671 0.089629 0.091353
9 0.0 0.080630 0.083309 0.092544 0.094659 0.096803 0.091246 0.093078
10 0.0 0.068605 0.070202 0.081597 0.082978 0.084362 0.082661 0.083943
11 0.0 0.070006 0.071729 0.083096 0.084574 0.086059 0.084022 0.085383
12 0.0 0.071462 0.073318 0.084650 0.086230 0.087822 0.085431 0.086875
13 0.0 0.072976 0.074973 0.086263 0.087951 0.089654 0.086890 0.088422
14 0.0 0.074552 0.076697 0.087938 0.089739 0.091561 0.088402 0.090025
1 0.0 0.079977 0.079947 0.079510 0.081431 0.083259 0.070891 0.072689
2 0.0 0.079947 0.081195 0.081235 0.083734 0.086125 0.073415 0.075557
3 0.0 0.079510 0.081235 0.084255 0.086970 0.089578 0.078324 0.080630
4 0.0 0.081431 0.083734 0.086970 0.090033 0.092982 0.081221 0.083765
5 0.0 0.083259 0.086125 0.089578 0.092982 0.096270 0.084018 0.086799
6 0.0 0.070891 0.073415 0.078324 0.081221 0.084018 0.074971 0.077341
7 0.0 0.072689 0.075557 0.080630 0.083765 0.086799 0.077341 0.079887
8 0.0 0.074531 0.077736 0.082971 0.086346 0.089619 0.079739 0.082464
9 0.0 0.076418 0.079959 0.085353 0.088970 0.092486 0.082173 0.085079
10 0.0 0.062300 0.065028 0.070886 0.073685 0.076396 0.069322 0.071578
11 0.0 0.063862 0.066824 0.072817 0.075794 0.078684 0.071279 0.073672
12 0.0 0.065482 0.068680 0.074807 0.077965 0.081038 0.073288 0.075822
13 0.0 0.067164 0.070600 0.076859 0.080205 0.083465 0.075356 0.078035
14 0.0 0.068912 0.072590 0.078981 0.082519 0.085973 0.077486 0.080316
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.078824 0.080630 0.068605 0.070006 0.071462 0.072976 0.074552
2 0.081308 0.083309 0.070202 0.071729 0.073318 0.074973 0.076697
3 0.090696 0.092544 0.081597 0.083096 0.084650 0.086263 0.087938
4 0.092672 0.094659 0.082978 0.084574 0.086230 0.087951 0.089739
5 0.094671 0.096803 0.084362 0.086059 0.087822 0.089654 0.091561
6 0.089629 0.091246 0.082661 0.084022 0.085431 0.086890 0.088402
7 0.091353 0.093078 0.083943 0.085383 0.086875 0.088422 0.090025
8 0.093132 0.094970 0.085259 0.086782 0.088361 0.090000 0.091700
9 0.094970 0.096928 0.086611 0.088222 0.089892 0.091627 0.093429
10 0.085259 0.086611 0.080195 0.081374 0.082592 0.083851 0.085152
11 0.086782 0.088222 0.081374 0.082619 0.083906 0.085237 0.086615
12 0.088361 0.089892 0.082592 0.083906 0.085265 0.086673 0.088130
13 0.090000 0.091627 0.083851 0.085237 0.086673 0.088160 0.089702
14 0.091700 0.093429 0.085152 0.086615 0.088130 0.089702 0.091331
1 0.074531 0.076418 0.062300 0.063862 0.065482 0.067164 0.068912
2 0.077736 0.079959 0.065028 0.066824 0.068680 0.070600 0.072590
3 0.082971 0.085353 0.070886 0.072817 0.074807 0.076859 0.078981
4 0.086346 0.088970 0.073685 0.075794 0.077965 0.080205 0.082519
5 0.089619 0.092486 0.076396 0.078684 0.081038 0.083465 0.085973
6 0.079739 0.082173 0.069322 0.071279 0.073288 0.075356 0.077486
7 0.082464 0.085079 0.071578 0.073672 0.075822 0.078035 0.080316
8 0.085222 0.088023 0.073858 0.076091 0.078386 0.080747 0.083182
9 0.088023 0.091015 0.076167 0.078544 0.080987 0.083501 0.086095
10 0.073858 0.076167 0.065149 0.067003 0.068903 0.070855 0.072863
11 0.076091 0.078544 0.067003 0.068967 0.070980 0.073048 0.075177
12 0.078386 0.080987 0.068903 0.070980 0.073109 0.075298 0.077553
13 0.080747 0.083501 0.070855 0.073048 0.075298 0.077613 0.079998
14 0.083182 0.086095 0.072863 0.075177 0.077553 0.079998 0.082518
</pre></div>
</div>
</div>
@@ -1053,10 +1080,10 @@ We can write our own code or simply use either the functionaly of <strong>numpy<
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1
0 4.034057 2.045548
1 2.045548 2.024217
[[4.03405654 2.04554803]
[2.04554803 2.02421742]]
0 3.970827 1.972533
1 1.972533 1.968650
[[3.97082748 1.97253307]
[1.97253307 1.96865004]]
</pre></div>
</div>
</div>
@@ -1083,8 +1110,8 @@ Our own code here is not very elegant and asks for obvious improvements. It is t
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Centered covariance using own code
[[4.03405654 2.04554803]
[2.04554803 2.02421742]]
[[3.97082748 1.97253307]
[1.97253307 1.96865004]]
</pre></div>
</div>
<img alt="_images/chapter8_65_1.png" src="_images/chapter8_65_1.png" />
@@ -1144,16 +1171,16 @@ questions.</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvalues of Covariance matrix
5.30820040103372
0.7500735612987705
5.181766185664273
0.7577113351177733
First eigenvector
[0.84880366 0.52870818]
[0.85222243 0.52317963]
Second eigenvector
[-0.52870818 0.84880366]
[-0.52317963 0.85222243]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvector of largest eigenvalue
[-0.84880366 -0.52870818]
[0.85222243 0.52317963]
</pre></div>
</div>
</div>
@@ -1494,9 +1521,7 @@ Here we compute performance scores on the training data using logistic regressio
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Train set accuracy from Logistic Regression: 0.95
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Train set accuracy scaled data: 0.99
Train set accuracy scaled data: 0.99
Train set accuracy scaled and PCA data: 0.96
</pre></div>
</div>
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+28 -1
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -55,7 +55,7 @@ const thebe_selector_output = ".output, .cell_output"
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Week 36: Linear Rgeression and Statistical interpretations" href="week36.html" />
<link rel="next" title="Week 36: Linear Regression and Statistical interpretations" href="week36.html" />
<link rel="prev" title="Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression" href="week35.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -590,7 +617,7 @@ Ridge regression and ordinary least squares.</p>
<a class='right-next' id="next-link" href="week36.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Week 36: Linear Rgeression and Statistical interpretations</p>
<p class="prev-next-title">Week 36: Linear Regression and Statistical interpretations</p>
</div>
<i class="fas fa-angle-right"></i>
</a>
@@ -288,6 +288,11 @@ const thebe_selector_output = ".output, .cell_output"
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+57 -30
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -581,8 +608,8 @@ matrices and vectors.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 1.24155894 0.62765236 -0.87599676 -0.45422069 1.14966323 -0.13318759
-0.4768597 0.11400097 0.43442461 0.37504943]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 1.02808229 1.3194467 -1.8476874 -0.00537955 -0.47991892 -1.54490887
-0.04110474 0.70857635 -1.39855569 -0.11081083]
</pre></div>
</div>
</div>
@@ -803,26 +830,26 @@ as (recall that we user lowercase letters for vectors and uppercase letters for
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.55796518 0.07643382 0.06644775 0.56823411 0.638618 0.06696769
0.89442642 0.33435469 0.24604925 0.88347937]
[0.28238649 0.00890669 0.61124231 0.21888121 0.05965043 0.30481195
0.09917303 0.29313228 0.26093249 0.72048339]
[0.43295279 0.60393882 0.85533937 0.75199355 0.02629596 0.13929376
0.14092044 0.86260426 0.10694828 0.48593774]
[0.26792572 0.40420245 0.15431202 0.51084243 0.74720185 0.60518617
0.64286758 0.63811548 0.24975055 0.2211108 ]
[0.83460016 0.95274315 0.63619296 0.59831212 0.40030144 0.9149137
0.61542957 0.30132427 0.26773827 0.59161025]
[0.17561484 0.22019267 0.12700133 0.49775827 0.13614217 0.6473418
0.88422263 0.32399798 0.77921992 0.55119373]
[0.16526258 0.11500354 0.3952007 0.88354703 0.13156239 0.51569907
0.48898864 0.53607935 0.41691626 0.05210975]
[0.41858649 0.64403731 0.08939489 0.33540382 0.08860792 0.91561163
0.06719214 0.17485935 0.16638104 0.73184876]
[0.09953815 0.79704553 0.41988809 0.7345483 0.75309603 0.3480159
0.58886887 0.76471048 0.60236121 0.49510364]
[0.9090666 0.24502113 0.52511377 0.97056672 0.95154558 0.3823545
0.48447474 0.53603254 0.91358186 0.8840785 ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.04413243 0.8917148 0.26113912 0.87399194 0.30400113 0.35432563
0.05060379 0.65641173 0.77507653 0.83369175]
[0.71261809 0.93968601 0.91961463 0.79866484 0.81919129 0.73062648
0.1488598 0.24254071 0.39922082 0.24398826]
[0.09171886 0.59348521 0.078588 0.74613334 0.18094575 0.61883807
0.89408972 0.86978877 0.82802004 0.75433448]
[0.26715191 0.8905826 0.19852045 0.06432267 0.72771857 0.63030526
0.97272223 0.66289235 0.41744203 0.6663569 ]
[0.91114704 0.01530321 0.55020649 0.40140374 0.67100236 0.5847256
0.80410179 0.37055062 0.4729218 0.26775644]
[0.34271514 0.45193407 0.55542568 0.82242798 0.40266454 0.64713979
0.03873507 0.81506255 0.72848736 0.16118615]
[0.72602818 0.13825388 0.03701105 0.76807288 0.58493493 0.1441031
0.72744372 0.20755569 0.0317606 0.67313212]
[0.85005989 0.9485531 0.81622636 0.32003025 0.57914918 0.36482524
0.17934801 0.84726382 0.52397611 0.14829228]
[0.18510775 0.22528536 0.56977352 0.53105728 0.43962226 0.06444224
0.01772779 0.20912557 0.08839544 0.06984502]
[0.71469351 0.70474145 0.97836358 0.65475653 0.14213876 0.6816947
0.65082441 0.01573768 0.06410638 0.64425744]]
</pre></div>
</div>
</div>
@@ -882,13 +909,13 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.0694169556368514
4.182925111119767
0.519327774467847
[[ 0.92674248 2.77519276 2.60482174]
[ 2.77519276 9.52018478 7.80919738]
[ 2.60482174 7.80919738 15.48655388]]
[21.53541027 0.0988662 4.29920468]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.030645975175292262
4.057913350391706
0.6380763200092493
[[ 0.87584434 2.75131415 3.30124108]
[ 2.75131415 9.73994248 10.78758569]
[ 3.30124108 10.78758569 24.86174943]]
[31.05888195 0.08758013 4.33107417]
</pre></div>
</div>
</div>
+31 -21
View File
@@ -55,7 +55,7 @@ const thebe_selector_output = ".output, .cell_output"
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Week 36: Linear Rgeression and Statistical interpretations" href="week36.html" />
<link rel="prev" title="Exercises week 38" href="exercisesweek38.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
@@ -274,7 +274,22 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
@@ -629,8 +644,7 @@ which polynomial fits the data best.</p>
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">random</span><span class="p">,</span> <span class="n">seed</span>
<span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">gca</span><span class="p">(</span><span class="n">projection</span><span class="o">=</span><span class="s1">&#39;3d&#39;</span><span class="p">)</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="n">projection</span> <span class="o">=</span> <span class="s1">&#39;3d&#39;</span><span class="p">)</span>
<span class="c1"># Make data.</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
@@ -664,21 +678,7 @@ which polynomial fits the data best.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">TypeError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="n">Cell</span> <span class="n">In</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">line</span> <span class="mi">11</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">random</span><span class="p">,</span> <span class="n">seed</span>
<span class="g g-Whitespace"> </span><span class="mi">10</span> <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="ne">---&gt; </span><span class="mi">11</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">gca</span><span class="p">(</span><span class="n">projection</span><span class="o">=</span><span class="s1">&#39;3d&#39;</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="c1"># Make data.</span>
<span class="g g-Whitespace"> </span><span class="mi">14</span> <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.05</span><span class="p">)</span>
<span class="ne">TypeError</span>: gca() got an unexpected keyword argument &#39;projection&#39;
</pre></div>
</div>
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>&lt;Figure size 640x480 with 0 Axes&gt;
</pre></div>
</div>
<img alt="_images/project1_7_0.png" src="_images/project1_7_0.png" />
</div>
</div>
<p>If you wish to compare your results with other on the Franke function or other popular functions tested with linear regression, see the list in Figure 1 of the article by Cook et al at <a class="reference external" href="https://arxiv.org/abs/2401.11694">https://arxiv.org/abs/2401.11694</a>.</p>
@@ -887,6 +887,16 @@ Python program using</p>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">NameError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="n">Cell</span> <span class="n">In</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">line</span> <span class="mi">1</span>
<span class="ne">----&gt; </span><span class="mi">1</span> <span class="n">scipy</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">imread</span>
<span class="ne">NameError</span>: name &#39;scipy&#39; is not defined
</pre></div>
</div>
</div>
</div>
<p>Here is a simple part of a Python code which reads and plots the data
from such files</p>
@@ -1023,11 +1033,11 @@ of code developers and contributors keeps increasing.</p>
<!-- Previous / next buttons -->
<div class='prev-next-area'>
<a class='left-prev' id="prev-link" href="week36.html" title="previous page">
<a class='left-prev' id="prev-link" href="exercisesweek38.html" title="previous page">
<i class="fas fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Week 36: Linear Rgeression and Statistical interpretations</p>
<p class="prev-next-title">Exercises week 38</p>
</div>
</a>
</div>
-726
View File
@@ -1,726 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Project 2 on Machine Learning, deadline November 17 (Midnight) &#8212; Applied Data Analysis and Machine Learning</title>
<link href="_static/css/theme.css" rel="stylesheet">
<link href="_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-book-theme.css?digest=c3fdc42140077d1ad13ad2f1588a4309" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="preload" as="script" href="_static/js/index.be7d3bbb2ef33a8344ce.js">
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script>let toggleHintShow = 'Click to show';</script>
<script>let toggleHintHide = 'Click to hide';</script>
<script>let toggleOpenOnPrint = 'true';</script>
<script src="_static/togglebutton.js"></script>
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="_static/sphinx-book-theme.d59cb220de22ca1c485ebbdc042f0030.js"></script>
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
const thebe_selector = ".thebe,.cell"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output, .cell_output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
<!-- Google Analytics -->
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-fluid" id="banner"></div>
<div class="container-xl">
<div class="row">
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
<div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="index.html">
<!-- `logo` is deprecated in Sphinx 4.0, so remove this when we stop supporting 3 -->
<img src="_static/logo.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">Applied Data Analysis and Machine Learning</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
<div class="bd-toc-item active">
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="intro.html">
Applied Data Analysis and Machine Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
About the course
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="schedule.html">
Teaching schedule with links to material
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="teachers.html">
Teachers and Grading
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="textbooks.html">
Textbooks
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Review of Statistics with Resampling Techniques and Linear Algebra
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="statistics.html">
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
From Regression to Support Vector Machines
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter1.html">
3. Linear Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter2.html">
4. Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter3.html">
5. Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter4.html">
6. Logistic Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapteroptimization.html">
7. Optimization, the central part of any Machine Learning algortithm
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter5.html">
8. Support Vector Machines, overarching aims
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Decision Trees, Ensemble Methods and Boosting
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter6.html">
9. Decision trees, overarching aims
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter7.html">
10. Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Dimensionality Reduction
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter8.html">
11. Basic ideas of the Principal Component Analysis (PCA)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="clustering.html">
12. Clustering and Unsupervised Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Deep Learning Methods
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter9.html">
13. Neural networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter10.html">
14. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
15. Solving Differential Equations with Deep Learning
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter12.html">
16. Convolutional Neural Networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter13.html">
17. Recurrent neural networks: Overarching view
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Weekly material, notes and exercises
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek34.html">
Exercises week 34
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week34.html">
Week 34: Introduction to the course, Logistics and Practicalities
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek35.html">
Exercises week 35
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week35.html">
Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek36.html">
Exercises week 36
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
</a>
</li>
</ul>
</div>
</nav> <!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
</div>
</div>
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
<div class="topbar container-xl fixed-top">
<div class="topbar-contents row">
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
<div class="col pl-md-4 topbar-main">
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
<i class="fas fa-bars"></i>
<i class="fas fa-arrow-left"></i>
<i class="fas fa-arrow-up"></i>
</button>
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
class="fas fa-download"></i></button>
<div class="dropdown-buttons">
<!-- ipynb file if we had a myst markdown file -->
<!-- Download raw file -->
<a class="dropdown-buttons" href="_sources/project2.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
data-placement="left">.ipynb</button></a>
<!-- Download PDF via print -->
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
</div>
</div>
<!-- Source interaction buttons -->
<!-- Full screen (wrap in <a> to have style consistency -->
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
title="Fullscreen mode"><i
class="fas fa-expand"></i></button></a>
<!-- Launch buttons -->
</div>
<!-- Table of contents -->
<div class="d-none d-md-block col-md-2 bd-toc show noprint">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> Contents
</div>
<nav id="bd-toc-nav" aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#classification-and-regression-from-linear-and-logistic-regression-to-neural-networks">
Classification and Regression, from linear and logistic regression to neural networks
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a-write-your-own-stochastic-gradient-descent-code-first-step">
Part a): Write your own Stochastic Gradient Descent code, first step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-b-writing-your-own-neural-network-code">
Part b): Writing your own Neural Network code
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c-testing-different-activation-functions">
Part c): Testing different activation functions
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d-classification-analysis-using-neural-networks">
Part d): Classification analysis using neural networks
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-e-write-your-logistic-regression-code-final-step">
Part e): Write your Logistic Regression code, final step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-f-critical-evaluation-of-the-various-algorithms">
Part f) Critical evaluation of the various algorithms
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#background-literature">
Background literature
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction-to-numerical-projects">
Introduction to numerical projects
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#format-for-electronic-delivery-of-report-and-programs">
Format for electronic delivery of report and programs
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="main-content" class="row">
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<!-- Table of contents that is only displayed when printing the page -->
<div id="jb-print-docs-body" class="onlyprint">
<h1>Project 2 on Machine Learning, deadline November 17 (Midnight)</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
<div>
<h2> Contents </h2>
</div>
<nav aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#classification-and-regression-from-linear-and-logistic-regression-to-neural-networks">
Classification and Regression, from linear and logistic regression to neural networks
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a-write-your-own-stochastic-gradient-descent-code-first-step">
Part a): Write your own Stochastic Gradient Descent code, first step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-b-writing-your-own-neural-network-code">
Part b): Writing your own Neural Network code
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c-testing-different-activation-functions">
Part c): Testing different activation functions
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d-classification-analysis-using-neural-networks">
Part d): Classification analysis using neural networks
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-e-write-your-logistic-regression-code-final-step">
Part e): Write your Logistic Regression code, final step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-f-critical-evaluation-of-the-various-algorithms">
Part f) Critical evaluation of the various algorithms
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#background-literature">
Background literature
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction-to-numerical-projects">
Introduction to numerical projects
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#format-for-electronic-delivery-of-report-and-programs">
Format for electronic delivery of report and programs
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div>
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
doconce format html Project2.do.txt -->
<!-- dom:TITLE: Project 2 on Machine Learning, deadline November 17 (Midnight) --><div class="tex2jax_ignore mathjax_ignore section" id="project-2-on-machine-learning-deadline-november-17-midnight">
<h1>Project 2 on Machine Learning, deadline November 17 (Midnight)<a class="headerlink" href="#project-2-on-machine-learning-deadline-november-17-midnight" title="Permalink to this headline"></a></h1>
<p><strong><a class="reference external" href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a></strong>, Department of Physics, University of Oslo, Norway</p>
<p>Date: <strong>Nov 13, 2023</strong></p>
<p>Copyright 1999-2023, <a class="reference external" href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a>. Released under CC Attribution-NonCommercial 4.0 license</p>
<div class="section" id="classification-and-regression-from-linear-and-logistic-regression-to-neural-networks">
<h2>Classification and Regression, from linear and logistic regression to neural networks<a class="headerlink" href="#classification-and-regression-from-linear-and-logistic-regression-to-neural-networks" title="Permalink to this headline"></a></h2>
<p>The main aim of this project is to study both classification and
regression problems by developing our own feed-forward neural network
(FFNN) code. We can reuse the regression algorithms studied in project</p>
<ol class="simple">
<li><p>We will also include logistic regression for classification
problems and write our own FFNN code for studying both regression and
classification problems. The codes developed in project 1, including
bootstrap <strong>and/or</strong> cross-validation as well as the computation of the
mean-squared error and/or the <span class="math notranslate nohighlight">\(R2\)</span> or the accuracy score
(classification problems) functions can also be utilized in the
present analysis.</p></li>
</ol>
<p>The data sets that we propose here are (the default sets)</p>
<ul class="simple">
<li><p>Regression (fitting a continuous function). In this part you will need to bring back your results from project 1 and compare these with what you get from your Neural Network code to be developed here. The data sets could be</p></li>
</ul>
<p>a. A simple one-dimensional function or the Franke function or the terrain data from project 1, or data sets your propose. It could be a simpler function than the Franke function. We recommend testing a simpler function (see below). But if you wish to try more complex function, feel free to do so.</p>
<ul class="simple">
<li><p>Classification. Here you will also need to develop a Logistic regression code that you will use to compare with the Neural Network code. The data set we propose are the so-called <a class="reference external" href="https://www.kaggle.com/uciml/breast-cancer-wisconsin-data">Wisconsin Breat Cancer Data</a> data set of images representing various features of tumors. These are discussed intensively in the lecture notes, see for example the slides from <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week41/html/week41.html">week 41</a>. A longer explanation with links to the scientific literature can be found at the <a class="reference external" href="https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29">Machine Learning repository of the University of California at Irvine</a>. Feel free to consult this site and the pertinent literature.</p></li>
</ul>
<p>You can find more information about this at the <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html">Scikit-Learn site</a> or at the <a class="reference external" href="https://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+(original)">University of California at Irvine</a>.</p>
<p>However, if you would like to study other data sets, feel free to
propose other sets. What we list here are mere suggestions from our
side. If you opt for another data set, consider using a set which has
been studied in the scientific literature. This makes it easier for
you to compare and analyze your results. Comparing with existing
results from the scientific literature is also an essential element of
the scientific discussion. The University of California at Irvine
with its Machine Learning repository at
<a class="reference external" href="https://archive.ics.uci.edu/ml/index.php">https://archive.ics.uci.edu/ml/index.php</a> is an excellent site to
look up for examples and
inspiration. <a class="reference external" href="https://www.kaggle.com/">Kaggle.com</a> is an equally
interesting site. Feel free to explore these sites.</p>
<p>We will start with a regression problem and we will reuse our codes from project 1 starting with writing our own Stochastic Gradient Descent (SGD) code.</p>
<div class="section" id="part-a-write-your-own-stochastic-gradient-descent-code-first-step">
<h3>Part a): Write your own Stochastic Gradient Descent code, first step<a class="headerlink" href="#part-a-write-your-own-stochastic-gradient-descent-code-first-step" title="Permalink to this headline"></a></h3>
<p>In order to get started, we will now replace in our standard ordinary
least squares (OLS) and Ridge regression codes (from project 1) the
matrix inversion algorithm with our own gradient descent (GD) and SGD
codes. You can use the Franke function or the terrain data from
project 1. <strong>However, we recommend using a simpler function like</strong>
<span class="math notranslate nohighlight">\(f(x)=a_0+a_1x+a_2x^2\)</span> or higher-order one-dimensional polynomials.
You can obviously test your final codes against for example the Franke
function.</p>
<p>You should include in your analysis of the GD and SGD codes the following elements</p>
<ol class="simple">
<li><p>A plain gradient descent with a fixed learning rate (you will need to tune it) using the analytical expression for the gradient.</p></li>
<li><p>Add momentum to the plain GD code and compare convergence with a fixed learning rate (you may need to tune the learning rate). Keep using the analytical expression for the gradient.</p></li>
<li><p>Repeat these steps for stochastic gradient descent with mini batches and a given number of epochs. Use a tunable learning rate as discussed in the lectures from weeks 39 and 40. Discuss the results as functions of the various parameters (size of batches, number of epochs etc). Use the analytical gradient.</p></li>
<li><p>Implement the Adagrad method in order to tune the learning rate. Do this with and without momentum for plain gradient descent and SGD.</p></li>
<li><p>Add RMSprop and Adam to your library of methods for tuning the learning rate.</p></li>
</ol>
<p>The lecture notes from <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week39/html/week39.html">weeks 39 and 40contain more
details</a> and code examples. Feel free to use these examples.</p>
<ol class="simple">
<li><p>Replace thereafter your analytical gradient with either <strong>Autograd</strong> or <strong>JAX</strong></p></li>
</ol>
<p>In summary, you should
perform an analysis of the results for OLS and Ridge regression as
function of the chosen learning rates, the number of mini-batches and
epochs as well as algorithm for scaling the learning rate. You can
also compare your own results with those that can be obtained using
for example <strong>Scikit-Learn</strong>s various SGD options. Discuss your
results. For Ridge regression you need now to study the results as functions of the hyper-parameter <span class="math notranslate nohighlight">\(\lambda\)</span> and
the learning rate <span class="math notranslate nohighlight">\(\eta\)</span>. Discuss your results.</p>
<p>You will need your SGD code for the setup of the Neural Network and
Logistic Regression codes. You will find the Python <a class="reference external" href="https://seaborn.pydata.org/generated/seaborn.heatmap.html">Seaborn
package</a>
useful when plotting the results as function of the learning rate
<span class="math notranslate nohighlight">\(\eta\)</span> and the hyper-parameter <span class="math notranslate nohighlight">\(\lambda\)</span> when you use Ridge
regression.</p>
<p>We recommend reading chapter 8 on optimization from the textbook of <a class="reference external" href="https://www.deeplearningbook.org/">Goodfellow, Bengio and Courville</a>. This chapter contains many useful insights and discussions on the optimization part of machine learning.</p>
</div>
<div class="section" id="part-b-writing-your-own-neural-network-code">
<h3>Part b): Writing your own Neural Network code<a class="headerlink" href="#part-b-writing-your-own-neural-network-code" title="Permalink to this headline"></a></h3>
<p>Your aim now, and this is the central part of this project, is to
write your own Feed Forward Neural Network code implementing the back
propagation algorithm discussed in the lecture slides from <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week41/html/week40.html">week 40</a> and
<a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week41/html/week41.html">week 41</a>.</p>
<p>We will focus on a regression problem first and study either the simple second-order polynomial from part a) or the
Franke function or terrain data (or both or other data sets) from
project 1.</p>
<p>Discuss again your choice of cost function.</p>
<p>Write an FFNN code for regression with a flexible number of hidden
layers and nodes using the Sigmoid function as activation function for
the hidden layers. Initialize the weights using a normal
distribution. How would you initialize the biases? And which
activation function would you select for the final output layer?</p>
<p>Train your network and compare the results with those from your OLS and Ridge Regression codes from project 1 if you use the Franke function or the terrain data.
You should test your results against a similar code using <strong>Scikit-Learn</strong> (see the examples in the above lecture notes from week 41) or <strong>tensorflow/keras</strong>.</p>
<p>Comment your results and give a critical discussion of the results
obtained with the Linear Regression code and your own Neural Network
code.<br />
Make an analysis of the regularization parameters and the learning rates employed to find the optimal MSE and <span class="math notranslate nohighlight">\(R2\)</span> scores.</p>
<p>A useful reference on the back progagation algorithm is <a class="reference external" href="http://neuralnetworksanddeeplearning.com/">Nielsens
book</a>. It is an excellent
read.</p>
</div>
<div class="section" id="part-c-testing-different-activation-functions">
<h3>Part c): Testing different activation functions<a class="headerlink" href="#part-c-testing-different-activation-functions" title="Permalink to this headline"></a></h3>
<p>You should now also test different activation functions for the hidden layers. Try out the Sigmoid, the RELU and the Leaky RELU functions and discuss your results. You may also study the way you initialize your weights and biases.</p>
</div>
<div class="section" id="part-d-classification-analysis-using-neural-networks">
<h3>Part d): Classification analysis using neural networks<a class="headerlink" href="#part-d-classification-analysis-using-neural-networks" title="Permalink to this headline"></a></h3>
<p>With a well-written code it should now be easy to change the
activation function for the output layer.</p>
<p>Here we will change the cost function for our neural network code
developed in parts b) and c) in order to perform a classification analysis.</p>
<p>We will here study the Wisconsin Breast Cancer data set. This is a typical binary classification problem with just one single output, either True or Fale, <span class="math notranslate nohighlight">\(0\)</span> or <span class="math notranslate nohighlight">\(1\)</span> etc.
You find more information about this at the <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html">Scikit-Learn
site</a> or at the <a class="reference external" href="https://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+(original)">University of California
at Irvine</a>.</p>
<p>To measure the performance of our classification problem we use the
so-called <em>accuracy</em> score. The accuracy is as you would expect just
the number of correctly guessed targets <span class="math notranslate nohighlight">\(t_i\)</span> divided by the total
number of targets, that is</p>
<div class="math notranslate nohighlight">
\[
\text{Accuracy} = \frac{\sum_{i=1}^n I(t_i = y_i)}{n} ,
\]</div>
<p>where <span class="math notranslate nohighlight">\(I\)</span> is the indicator function, <span class="math notranslate nohighlight">\(1\)</span> if <span class="math notranslate nohighlight">\(t_i = y_i\)</span> and <span class="math notranslate nohighlight">\(0\)</span>
otherwise if we have a binary classification problem. Here <span class="math notranslate nohighlight">\(t_i\)</span>
represents the target and <span class="math notranslate nohighlight">\(y_i\)</span> the outputs of your FFNN code and <span class="math notranslate nohighlight">\(n\)</span> is simply the number of targets <span class="math notranslate nohighlight">\(t_i\)</span>.</p>
<p>Discuss your results and give a critical analysis of the various parameters, including hyper-parameters like the learning rates and the regularization parameter <span class="math notranslate nohighlight">\(\lambda\)</span> (as you did in Ridge Regression), various activation functions, number of hidden layers and nodes and activation functions.</p>
<p>As stated in the introduction, it can also be useful to study other
datasets.</p>
<p>Again, we strongly recommend that you compare your own neural Network
code for classification and pertinent results against a similar code using <strong>Scikit-Learn</strong> or <strong>tensorflow/keras</strong> or <strong>pytorch</strong>.</p>
</div>
<div class="section" id="part-e-write-your-logistic-regression-code-final-step">
<h3>Part e): Write your Logistic Regression code, final step<a class="headerlink" href="#part-e-write-your-logistic-regression-code-final-step" title="Permalink to this headline"></a></h3>
<p>Finally, we want to compare the FFNN code we have developed with
Logistic regression, that is we wish to compare our neural network
classification results with the results we can obtain with another
method.</p>
<p>Define your cost function and the design matrix before you start writing your code.
Write thereafter a Logistic regression code using your SGD algorithm. You can also use standard gradient descent in this case, with a learning rate as hyper-parameter.
Study the results as functions of the chosen learning rates.
Add also an <span class="math notranslate nohighlight">\(l_2\)</span> regularization parameter <span class="math notranslate nohighlight">\(\lambda\)</span>. Compare your results with those from your FFNN code as well as those obtained using <strong>Scikit-Learn</strong>s logistic regression functionality.</p>
<p>The weblink here <a class="reference external" href="https://medium.com/ai-in-plain-english/comparison-between-logistic-regression-and-neural-networks-in-classifying-digits-dc5e85cd93c3">https://medium.com/ai-in-plain-english/comparison-between-logistic-regression-and-neural-networks-in-classifying-digits-dc5e85cd93c3</a>compares logistic regression and FFNN using the so-called MNIST data set. You may find several useful hints and ideas from this article.</p>
</div>
<div class="section" id="part-f-critical-evaluation-of-the-various-algorithms">
<h3>Part f) Critical evaluation of the various algorithms<a class="headerlink" href="#part-f-critical-evaluation-of-the-various-algorithms" title="Permalink to this headline"></a></h3>
<p>After all these glorious calculations, you should now summarize the
various algorithms and come with a critical evaluation of their pros
and cons. Which algorithm works best for the regression case and which
is best for the classification case. These codes can also be part of
your final project 3, but now applied to other data sets.</p>
</div>
</div>
<div class="section" id="background-literature">
<h2>Background literature<a class="headerlink" href="#background-literature" title="Permalink to this headline"></a></h2>
<ol class="simple">
<li><p>The text of Michael Nielsen is highly recommended, see <a class="reference external" href="http://neuralnetworksanddeeplearning.com/">Nielsens book</a>. It is an excellent read.</p></li>
<li><p><a class="reference external" href="https://arxiv.org/abs/1803.08823">Mehta et al, arXiv 1803.08823</a>, <em>A high-bias, low-variance introduction to Machine Learning for physicists</em>, ArXiv:1803.08823.</p></li>
</ol>
<p>c. <a class="reference external" href="https://www.deeplearningbook.org/">Goodfellow, Bengio and Courville</a>, <em>Deep Learning</em>.</p>
</div>
<div class="section" id="introduction-to-numerical-projects">
<h2>Introduction to numerical projects<a class="headerlink" href="#introduction-to-numerical-projects" title="Permalink to this headline"></a></h2>
<p>Here follows a brief recipe and recommendation on how to write a report for each
project.</p>
<ul class="simple">
<li><p>Give a short description of the nature of the problem and the eventual numerical methods you have used.</p></li>
<li><p>Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.</p></li>
<li><p>Include the source code of your program. Comment your program properly.</p></li>
<li><p>If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.</p></li>
<li><p>Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.</p></li>
<li><p>Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.</p></li>
<li><p>Try to give an interpretation of you results in your answers to the problems.</p></li>
<li><p>Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts youve made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.</p></li>
<li><p>Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you dont properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.</p></li>
</ul>
</div>
<div class="section" id="format-for-electronic-delivery-of-report-and-programs">
<h2>Format for electronic delivery of report and programs<a class="headerlink" href="#format-for-electronic-delivery-of-report-and-programs" title="Permalink to this headline"></a></h2>
<p>The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:</p>
<ul class="simple">
<li><p>Use Canvas to hand in your projects, log in at <a class="reference external" href="https://www.uio.no/english/services/it/education/canvas/">https://www.uio.no/english/services/it/education/canvas/</a> with your normal UiO username and password.</p></li>
<li><p>Upload <strong>only</strong> the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.</p></li>
<li><p>In your GitHub/GitLab or similar repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.</p></li>
</ul>
<p>Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.</p>
</div>
</div>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
kernelName: "python3",
path: "./."
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</div>
<!-- Previous / next buttons -->
<div class='prev-next-area'>
</div>
</div>
</div>
<footer class="footer">
<p>
By Morten Hjorth-Jensen<br/>
&copy; Copyright 2021.<br/>
</p>
</footer>
</main>
</div>
</div>
<script src="_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
</body>
</html>
-845
View File
@@ -1,845 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Project 3 on Machine Learning, deadline December 18 (midnight), 2023 &#8212; Applied Data Analysis and Machine Learning</title>
<link href="_static/css/theme.css" rel="stylesheet">
<link href="_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-book-theme.css?digest=c3fdc42140077d1ad13ad2f1588a4309" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="preload" as="script" href="_static/js/index.be7d3bbb2ef33a8344ce.js">
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script>let toggleHintShow = 'Click to show';</script>
<script>let toggleHintHide = 'Click to hide';</script>
<script>let toggleOpenOnPrint = 'true';</script>
<script src="_static/togglebutton.js"></script>
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="_static/sphinx-book-theme.d59cb220de22ca1c485ebbdc042f0030.js"></script>
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
const thebe_selector = ".thebe,.cell"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output, .cell_output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
<!-- Google Analytics -->
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-fluid" id="banner"></div>
<div class="container-xl">
<div class="row">
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
<div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="index.html">
<!-- `logo` is deprecated in Sphinx 4.0, so remove this when we stop supporting 3 -->
<img src="_static/logo.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">Applied Data Analysis and Machine Learning</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
<div class="bd-toc-item active">
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="intro.html">
Applied Data Analysis and Machine Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
About the course
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="schedule.html">
Teaching schedule with links to material
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="teachers.html">
Teachers and Grading
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="textbooks.html">
Textbooks
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Review of Statistics with Resampling Techniques and Linear Algebra
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="statistics.html">
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
From Regression to Support Vector Machines
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter1.html">
3. Linear Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter2.html">
4. Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter3.html">
5. Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter4.html">
6. Logistic Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapteroptimization.html">
7. Optimization, the central part of any Machine Learning algortithm
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter5.html">
8. Support Vector Machines, overarching aims
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Decision Trees, Ensemble Methods and Boosting
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter6.html">
9. Decision trees, overarching aims
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter7.html">
10. Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Dimensionality Reduction
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter8.html">
11. Basic ideas of the Principal Component Analysis (PCA)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="clustering.html">
12. Clustering and Unsupervised Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Deep Learning Methods
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter9.html">
13. Neural networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter10.html">
14. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
15. Solving Differential Equations with Deep Learning
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter12.html">
16. Convolutional Neural Networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter13.html">
17. Recurrent neural networks: Overarching view
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Weekly material, notes and exercises
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek34.html">
Exercises week 34
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week34.html">
Week 34: Introduction to the course, Logistics and Practicalities
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek35.html">
Exercises week 35
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week35.html">
Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek36.html">
Exercises week 36
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
</a>
</li>
</ul>
</div>
</nav> <!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
</div>
</div>
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
<div class="topbar container-xl fixed-top">
<div class="topbar-contents row">
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
<div class="col pl-md-4 topbar-main">
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
<i class="fas fa-bars"></i>
<i class="fas fa-arrow-left"></i>
<i class="fas fa-arrow-up"></i>
</button>
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
class="fas fa-download"></i></button>
<div class="dropdown-buttons">
<!-- ipynb file if we had a myst markdown file -->
<!-- Download raw file -->
<a class="dropdown-buttons" href="_sources/project3.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
data-placement="left">.ipynb</button></a>
<!-- Download PDF via print -->
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
</div>
</div>
<!-- Source interaction buttons -->
<!-- Full screen (wrap in <a> to have style consistency -->
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
title="Fullscreen mode"><i
class="fas fa-expand"></i></button></a>
<!-- Launch buttons -->
</div>
<!-- Table of contents -->
<div class="d-none d-md-block col-md-2 bd-toc show noprint">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> Contents
</div>
<nav id="bd-toc-nav" aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#">
Project 3 on Machine Learning, deadline December 18 (midnight), 2023
</a>
</li>
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#paths-for-project-3">
Paths for project 3
</a>
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#defining-the-data-sets-to-analyze-yourself">
Defining the data sets to analyze yourself
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#the-basic-structure-of-your-project">
The basic structure of your project
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a">
Part a)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-b">
Part b)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c">
Part c)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d">
Part d)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-e">
Part e)
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#solving-partial-differential-equations-with-neural-networks">
Solving partial differential equations with neural networks
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#alternative-differential-equations">
Alternative differential equations
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a-setting-up-the-problem">
Part a), setting up the problem
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id1">
Part b)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c-neural-networks">
Part c) Neural networks
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d-neural-network-complexity">
Part d) Neural network complexity
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id2">
Part e)
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction-to-numerical-projects">
Introduction to numerical projects
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#format-for-electronic-delivery-of-report-and-programs">
Format for electronic delivery of report and programs
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#software-and-needed-installations">
Software and needed installations
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="main-content" class="row">
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<!-- Table of contents that is only displayed when printing the page -->
<div id="jb-print-docs-body" class="onlyprint">
<h1>Project 3 on Machine Learning, deadline December 18 (midnight), 2023</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
<div>
<h2> Contents </h2>
</div>
<nav aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#">
Project 3 on Machine Learning, deadline December 18 (midnight), 2023
</a>
</li>
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#paths-for-project-3">
Paths for project 3
</a>
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#defining-the-data-sets-to-analyze-yourself">
Defining the data sets to analyze yourself
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#the-basic-structure-of-your-project">
The basic structure of your project
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a">
Part a)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-b">
Part b)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c">
Part c)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d">
Part d)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-e">
Part e)
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#solving-partial-differential-equations-with-neural-networks">
Solving partial differential equations with neural networks
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#alternative-differential-equations">
Alternative differential equations
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a-setting-up-the-problem">
Part a), setting up the problem
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id1">
Part b)
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c-neural-networks">
Part c) Neural networks
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d-neural-network-complexity">
Part d) Neural network complexity
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id2">
Part e)
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction-to-numerical-projects">
Introduction to numerical projects
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#format-for-electronic-delivery-of-report-and-programs">
Format for electronic delivery of report and programs
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#software-and-needed-installations">
Software and needed installations
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div>
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
doconce format html Project3.do.txt -->
<!-- dom:TITLE: Project 3 on Machine Learning, deadline December 18 (midnight), 2023 --><div class="tex2jax_ignore mathjax_ignore section" id="project-3-on-machine-learning-deadline-december-18-midnight-2023">
<h1>Project 3 on Machine Learning, deadline December 18 (midnight), 2023<a class="headerlink" href="#project-3-on-machine-learning-deadline-december-18-midnight-2023" title="Permalink to this headline"></a></h1>
<p><strong><a class="reference external" href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a></strong>, Department of Physics, University of Oslo, Norway</p>
<p>Date: <strong>Nov 13, 2023</strong></p>
<p>Copyright 1999-2023, <a class="reference external" href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a>. Released under CC Attribution-NonCommercial 4.0 license</p>
</div>
<div class="tex2jax_ignore mathjax_ignore section" id="paths-for-project-3">
<h1>Paths for project 3<a class="headerlink" href="#paths-for-project-3" title="Permalink to this headline"></a></h1>
<div class="section" id="defining-the-data-sets-to-analyze-yourself">
<h2>Defining the data sets to analyze yourself<a class="headerlink" href="#defining-the-data-sets-to-analyze-yourself" title="Permalink to this headline"></a></h2>
<p>For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say</p>
<ol class="simple">
<li><p><a class="reference external" href="https://www.kaggle.com/datasets">Kaggle</a></p></li>
<li><p>The <a class="reference external" href="https://archive.ics.uci.edu/ml/index.php">University of California at Irvine (UCI) with its machine learning repository</a>.</p></li>
<li><p>Or other sources.</p></li>
</ol>
<p>The approach to the analysis of these new data sets should follow to a large extent what you did in projects 1 and 2. That is:</p>
<ol class="simple">
<li><p>Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among <strong>linear regression (including Ridge and Lasso)</strong>, <strong>Logistic Regression</strong>, <strong>Neural Networks</strong>, <strong>Convolution Neural Networks</strong>, <strong>Recurrent Neural Networks</strong>, and <strong>Decision Trees, Random Forests, Bagging and Boosting</strong>.</p></li>
</ol>
<p>Feel also free to use support vector machines, <span class="math notranslate nohighlight">\(k\)</span>-means and principal components analysis, although the latter have not been covered during the lectures. This material can be found in the lecture notes.</p>
<p>You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into <strong>convolutional neural networks</strong> or <strong>recurrent neural networks</strong>, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attention to supervised learning.</p>
<p>For Boosting, feel also free to write your own codes.</p>
<ol class="simple">
<li><p>For project 3, you should feel free to use your own codes from projects 1 and 2, eventually write your own for Decision trees/random forests/bagging/boosting or use the available functionality of <strong>Scikit-Learn</strong>, <strong>Tensorflow</strong>, PyTorch etc.</p></li>
<li><p>The estimates you used and tested in projects 1 and 2 should also be included, that is the <span class="math notranslate nohighlight">\(R2\)</span>-score, <strong>MSE</strong>, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.</p></li>
<li><p>Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.</p></li>
<li><p>If possible, you should link the data sets with exisiting research and analyses thereof. Scientific articles which have used Machine Learning algorithms to analyze the data are highly welcome. Perhaps you can improve previous analyses and even publish a new article?</p></li>
<li><p>A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.</p></li>
</ol>
<p>All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..</p>
<p>We propose also an alternative to the above. This is a project on using machine learning methods (neural networks mainly) to the solution of ordinary differential equations and partial differential equations, with a final twist on how to diagonalize a symmetric matrix with neural networks.</p>
<p>This is a field with large scientific interest, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week43/html/week42.html">from week 43</a> and/or the textbook by <a class="reference external" href="https://www.springer.com/gp/book/9789401798150">Yadav et al</a>.</p>
</div>
<div class="section" id="the-basic-structure-of-your-project">
<h2>The basic structure of your project<a class="headerlink" href="#the-basic-structure-of-your-project" title="Permalink to this headline"></a></h2>
<p>Here follows a set up on how to structure your report and analyze the data you have opted for.</p>
<div class="section" id="part-a">
<h3>Part a)<a class="headerlink" href="#part-a" title="Permalink to this headline"></a></h3>
<p>The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context.</p>
</div>
<div class="section" id="part-b">
<h3>Part b)<a class="headerlink" href="#part-b" title="Permalink to this headline"></a></h3>
<p>You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.</p>
</div>
<div class="section" id="part-c">
<h3>Part c)<a class="headerlink" href="#part-c" title="Permalink to this headline"></a></h3>
<p>Then describe your algorithm and its implementation and tests you have performed.</p>
</div>
<div class="section" id="part-d">
<h3>Part d)<a class="headerlink" href="#part-d" title="Permalink to this headline"></a></h3>
<p>Then presents your results and findings, link with existing literature and more.</p>
</div>
<div class="section" id="part-e">
<h3>Part e)<a class="headerlink" href="#part-e" title="Permalink to this headline"></a></h3>
<p>Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature.</p>
</div>
</div>
<div class="section" id="solving-partial-differential-equations-with-neural-networks">
<h2>Solving partial differential equations with neural networks<a class="headerlink" href="#solving-partial-differential-equations-with-neural-networks" title="Permalink to this headline"></a></h2>
<p>For this variant of project 3, we will assume that you have some
background in the solution of partial differential equations using
finite difference schemes. We will study the solution of the diffusion
equation in one dimension using a standard explicit scheme and neural
networks to solve the same equations.</p>
<p>For the explicit scheme, you can study for example chapter 10 of the lecture notes in <a class="reference external" href="https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf">Computational Physics, FYS3150/4150</a> or alternative sources from courses like <a class="reference external" href="https://www.uio.no/studier/emner/matnat/math/MAT-MEK4270/index.html">MAT-MEK4270</a>. For the solution of ordinary and partial differential equations using neural networks, the lectures by <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week43.html">included in the lectures of week 43</a> at this course are highly recommended.</p>
<p>For the machine learning part you can use your own code from project 2 or the functionality of for example <strong>Tensorflow/Keras</strong>, <strong>PyTorch</strong> or other libraries such <a class="reference external" href="https://maziarraissi.github.io/PINNs/">Physics informed machine learning</a>.</p>
<div class="section" id="alternative-differential-equations">
<h3>Alternative differential equations<a class="headerlink" href="#alternative-differential-equations" title="Permalink to this headline"></a></h3>
<p>Note that you can replace the one-dimensional diffusion equation discussed below with other sets of either ordinary differential equations or partial differential equations.
Please discuss such a change with us at the lab.</p>
</div>
<div class="section" id="part-a-setting-up-the-problem">
<h3>Part a), setting up the problem<a class="headerlink" href="#part-a-setting-up-the-problem" title="Permalink to this headline"></a></h3>
<p>The physical problem can be that of the temperature gradient in a rod of length <span class="math notranslate nohighlight">\(L=1\)</span> at <span class="math notranslate nohighlight">\(x=0\)</span> and <span class="math notranslate nohighlight">\(x=1\)</span>.
We are looking at a one-dimensional
problem</p>
<div class="math notranslate nohighlight">
\[
\frac{\partial^2 u(x,t)}{\partial x^2} =\frac{\partial u(x,t)}{\partial t}, t&gt; 0, x\in [0,L]
\]</div>
<p>or</p>
<div class="math notranslate nohighlight">
\[
u_{xx} = u_t,
\]</div>
<p>with initial conditions, i.e., the conditions at <span class="math notranslate nohighlight">\(t=0\)</span>,</p>
<div class="math notranslate nohighlight">
\[
u(x,0)= \sin{(\pi x)} \hspace{0.5cm} 0 &lt; x &lt; L,
\]</div>
<p>with <span class="math notranslate nohighlight">\(L=1\)</span> the length of the <span class="math notranslate nohighlight">\(x\)</span>-region of interest. The
boundary conditions are</p>
<div class="math notranslate nohighlight">
\[
u(0,t)= 0 \hspace{0.5cm} t \ge 0,
\]</div>
<p>and</p>
<div class="math notranslate nohighlight">
\[
u(L,t)= 0 \hspace{0.5cm} t \ge 0.
\]</div>
<p>The function <span class="math notranslate nohighlight">\(u(x,t)\)</span> can be the temperature gradient of a rod.
As time increases, the velocity approaches a linear variation with <span class="math notranslate nohighlight">\(x\)</span>.</p>
<p>We will limit ourselves to the so-called explicit forward Euler algorithm with discretized versions of time given by a forward formula and a centered difference in space resulting in</p>
<div class="math notranslate nohighlight">
\[
u_t\approx \frac{u(x,t+\Delta t)-u(x,t)}{\Delta t}=\frac{u(x_i,t_j+\Delta t)-u(x_i,t_j)}{\Delta t}
\]</div>
<p>and</p>
<div class="math notranslate nohighlight">
\[
u_{xx}\approx \frac{u(x+\Delta x,t)-2u(x,t)+u(x-\Delta x,t)}{\Delta x^2},
\]</div>
<p>or</p>
<div class="math notranslate nohighlight">
\[
u_{xx}\approx \frac{u(x_i+\Delta x,t_j)-2u(x_i,t_j)+u(x_i-\Delta x,t_j)}{\Delta x^2}.
\]</div>
<p>Write down the algorithm and the equations you need to implement.
Find also the analytical solution to the problem.</p>
</div>
<div class="section" id="id1">
<h3>Part b)<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h3>
<p>Implement the explicit scheme algorithm and perform tests of the solution
for <span class="math notranslate nohighlight">\(\Delta x=1/10\)</span>, <span class="math notranslate nohighlight">\(\Delta x=1/100\)</span> using <span class="math notranslate nohighlight">\(\Delta t\)</span> as dictated by the stability limit of the explicit scheme. The stability criterion for the explicit scheme requires that <span class="math notranslate nohighlight">\(\Delta t/\Delta x^2 \leq 1/2\)</span>.</p>
<p>Study the solutions at two time points <span class="math notranslate nohighlight">\(t_1\)</span> and <span class="math notranslate nohighlight">\(t_2\)</span> where <span class="math notranslate nohighlight">\(u(x,t_1)\)</span> is smooth but still significantly curved
and <span class="math notranslate nohighlight">\(u(x,t_2)\)</span> is almost linear, close to the stationary state.</p>
</div>
<div class="section" id="part-c-neural-networks">
<h3>Part c) Neural networks<a class="headerlink" href="#part-c-neural-networks" title="Permalink to this headline"></a></h3>
<p>Study now the lecture notes on solving ODEs and PDEs with neural
network and use either your own code from project 2 or the
functionality of tensorflow/keras to solve the same equation as in
part b). Discuss your results and compare them with the standard
explicit scheme. Include also the analytical solution and compare with
that.</p>
</div>
<div class="section" id="part-d-neural-network-complexity">
<h3>Part d) Neural network complexity<a class="headerlink" href="#part-d-neural-network-complexity" title="Permalink to this headline"></a></h3>
<p>Here we study the stability of the results of the results as functions of the number of hidden nodes, layers and activation functions for the hidden layers.
Increase the number of hidden nodes and layers in order to see if this improves your results. Try also different activation functions for the hidden layers, such as the <strong>tanh</strong>, <strong>ReLU</strong>, and other activation functions.
Discuss your results.</p>
</div>
<div class="section" id="id2">
<h3>Part e)<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h3>
<p>Finally, present a critical assessment of the methods you have studied
and discuss the potential for the solving differential equations with machine learning methods.</p>
</div>
</div>
<div class="section" id="introduction-to-numerical-projects">
<h2>Introduction to numerical projects<a class="headerlink" href="#introduction-to-numerical-projects" title="Permalink to this headline"></a></h2>
<p>Here follows a brief recipe and recommendation on how to write a report for each
project.</p>
<ul class="simple">
<li><p>Give a short description of the nature of the problem and the eventual numerical methods you have used.</p></li>
<li><p>Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.</p></li>
<li><p>Include the source code of your program. Comment your program properly.</p></li>
<li><p>If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.</p></li>
<li><p>Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.</p></li>
<li><p>Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.</p></li>
<li><p>Try to give an interpretation of you results in your answers to the problems.</p></li>
<li><p>Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts youve made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.</p></li>
<li><p>Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you dont properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.</p></li>
</ul>
</div>
<div class="section" id="format-for-electronic-delivery-of-report-and-programs">
<h2>Format for electronic delivery of report and programs<a class="headerlink" href="#format-for-electronic-delivery-of-report-and-programs" title="Permalink to this headline"></a></h2>
<p>The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:</p>
<ul class="simple">
<li><p>Use Canvas to hand in your projects, log in at <a class="reference external" href="https://www.uio.no/english/services/it/education/canvas/">https://www.uio.no/english/services/it/education/canvas/</a> with your normal UiO username and password.</p></li>
<li><p>Upload <strong>only</strong> the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.</p></li>
<li><p>In your GitHub/GitLab or similar repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.</p></li>
</ul>
<p>Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.</p>
</div>
<div class="section" id="software-and-needed-installations">
<h2>Software and needed installations<a class="headerlink" href="#software-and-needed-installations" title="Permalink to this headline"></a></h2>
<p>If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
we recommend that you install the following Python packages via <strong>pip</strong> as</p>
<ol class="simple">
<li><p>pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow</p></li>
</ol>
<p>For Python3, replace <strong>pip</strong> with <strong>pip3</strong>.</p>
<p>See below for a discussion of <strong>tensorflow</strong> and <strong>scikit-learn</strong>.</p>
<p>For OSX users we recommend also, after having installed Xcode, to install <strong>brew</strong>. Brew allows
for a seamless installation of additional software via for example</p>
<ol class="simple">
<li><p>brew install python3</p></li>
</ol>
<p>For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use <strong>pip</strong> as well and simply install Python as</p>
<ol class="simple">
<li><p>sudo apt-get install python3 (or python for python2.7)</p></li>
</ol>
<p>etc etc.</p>
<p>If you dont want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely</p>
<ol class="simple">
<li><p><a class="reference external" href="https://docs.anaconda.com/">Anaconda</a> Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system <strong>conda</strong></p></li>
<li><p><a class="reference external" href="https://www.enthought.com/product/canopy/">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</p></li>
</ol>
<p>Popular software packages written in Python for ML are</p>
<ul class="simple">
<li><p><a class="reference external" href="http://scikit-learn.org/stable/">Scikit-learn</a>,</p></li>
<li><p><a class="reference external" href="https://www.tensorflow.org/">Tensorflow</a>,</p></li>
<li><p><a class="reference external" href="http://pytorch.org/">PyTorch</a> and</p></li>
<li><p><a class="reference external" href="https://keras.io/">Keras</a>.</p></li>
</ul>
<p>These are all freely available at their respective GitHub sites. They
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing.</p>
</div>
</div>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
kernelName: "python3",
path: "./."
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</div>
<!-- Previous / next buttons -->
<div class='prev-next-area'>
</div>
</div>
</div>
<footer class="footer">
<p>
By Morten Hjorth-Jensen<br/>
&copy; Copyright 2021.<br/>
</p>
</footer>
</main>
</div>
</div>
<script src="_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
</body>
</html>
+28 -1
View File
@@ -273,7 +273,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
File diff suppressed because one or more lines are too long
+69 -32
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -953,27 +980,37 @@ uncorrelated.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>2.66617168469673
[[ 1.31901056 1.37040343 4.92740215 0.39706027 2.78890834 5.48780047
5.56413916 3.99371466 6.81203214 3.34782766]
[ 1.37040343 1.42379872 5.11938949 0.41253101 2.89757312 5.70162272
5.7809358 4.14932255 7.07745069 3.47826973]
[ 4.92740215 5.11938949 18.40720059 1.48329035 10.41847076 20.50066971
20.78584667 14.91924234 25.44757627 12.50641483]
[ 0.39706027 0.41253101 1.48329035 0.11952661 0.83954195 1.65198643
1.67496658 1.20222345 2.05061841 1.00779281]
[ 2.78890834 2.89757312 10.41847076 0.83954195 5.89685175 11.60337375
11.76478383 8.4442873 14.40332158 7.07862755]
[ 5.48780047 5.70162272 20.50066971 1.65198643 11.60337375 22.83223115
23.14984157 16.61602252 28.34175429 13.92878175]
[ 5.56413916 5.7809358 20.78584667 1.67496658 11.76478383 23.14984157
23.47187014 16.84716164 28.73600557 14.1225397 ]
[ 3.99371466 4.14932255 14.91924234 1.20222345 8.4442873 16.61602252
16.84716164 12.09221309 20.62554572 10.13658936]
[ 6.81203214 7.07745069 25.44757627 2.05061841 14.40332158 28.34175429
28.73600557 20.62554572 35.18075088 17.28986131]
[ 3.34782766 3.47826973 12.50641483 1.00779281 7.07862755 13.92878175
14.1225397 10.13658936 17.28986131 8.49724059]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>3.1732863504708044
[[8.55460327e+00 4.59630232e+00 7.71507714e+00 3.56832496e-01
1.62620041e+01 3.84661230e+00 8.38865681e+00 1.18285689e+01
1.78876155e+01 4.77352152e+00]
[4.59630232e+00 2.46954702e+00 4.14523337e+00 1.91722512e-01
8.73741131e+00 2.06674611e+00 4.50714096e+00 6.35537114e+00
9.61083596e+00 2.56476512e+00]
[7.71507714e+00 4.14523337e+00 6.95793988e+00 3.21813899e-01
1.46660941e+01 3.46911594e+00 7.56541622e+00 1.06677444e+01
1.61321722e+01 4.30506075e+00]
[3.56832496e-01 1.91722512e-01 3.21813899e-01 1.48843174e-02
6.78326199e-01 1.60451189e-01 3.49910481e-01 4.93397254e-01
7.46134248e-01 1.99114739e-01]
[1.62620041e+01 8.73741131e+00 1.46660941e+01 6.78326199e-01
3.09135059e+01 7.31227657e+00 1.59465457e+01 2.24856992e+01
3.40037367e+01 9.07429886e+00]
[3.84661230e+00 2.06674611e+00 3.46911594e+00 1.60451189e-01
7.31227657e+00 1.72964493e+00 3.77199379e+00 5.31876431e+00
8.04323936e+00 2.14643345e+00]
[8.38865681e+00 4.50714096e+00 7.56541622e+00 3.49910481e-01
1.59465457e+01 3.77199379e+00 8.22592946e+00 1.15991124e+01
1.75406226e+01 4.68092237e+00]
[1.18285689e+01 6.35537114e+00 1.06677444e+01 4.93397254e-01
2.24856992e+01 5.31876431e+00 1.15991124e+01 1.63555267e+01
2.47334547e+01 6.60041459e+00]
[1.78876155e+01 9.61083596e+00 1.61321722e+01 7.46134248e-01
3.40037367e+01 8.04323936e+00 1.75406226e+01 2.47334547e+01
3.74028787e+01 9.98140006e+00]
[4.77352152e+00 2.56476512e+00 4.30506075e+00 1.99114739e-01
9.07429886e+00 2.14643345e+00 4.68092237e+00 6.60041459e+00
9.98140006e+00 2.66365453e+00]]
</pre></div>
</div>
</div>
@@ -1241,15 +1278,15 @@ more practically oriented methods like the blocking technique.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.04944931918420588
3.9197998358799464
-0.7106484566285455
0.9059370566788297 9.700258285068488 9.7423220054006
2.7796611648499043 2.2456969087678473 7.0827744231113545
[[0.90593706 2.77966116 2.24569691]
[2.77966116 9.70025829 7.08277442]
[2.24569691 7.08277442 9.74232201]]
[17.56239321 0.09298511 2.69313903]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.03872795610436844
3.8505072899794293
0.03015288036252618
0.8896094720230128 9.323184775146844 7.56423957069263
2.7487814387207385 2.000626681519836 6.325228546249804
[[0.88960947 2.74878144 2.00062668]
[2.74878144 9.32318478 6.32522855]
[2.00062668 6.32522855 7.56423957]]
[15.60940356 0.06849372 2.09913654]
</pre></div>
</div>
</div>
@@ -1579,7 +1616,7 @@ assumption for approximating <span class="math notranslate nohighlight">\(\sigma
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.031696741936652305 0.9106590586410548
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.011156605304609659 0.9767506308987675
</pre></div>
</div>
<img alt="_images/statistics_188_1.png" src="_images/statistics_188_1.png" />
+28 -1
View File
@@ -273,7 +273,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+28 -1
View File
@@ -273,7 +273,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
+58 -31
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -1641,8 +1668,8 @@ developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly he
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 1.55217048 0.41383693 0.79189954 2.5545673 -1.22668089 -0.00445922
-1.2662882 -0.64605756 0.5972962 -0.22398902]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 0.27600259 -1.0831367 -2.92599642 -0.36091273 -0.39398622 -1.03979291
0.93237862 1.4635149 0.01552874 0.4761747 ]
</pre></div>
</div>
</div>
@@ -1867,26 +1894,26 @@ lowercase letters for vectors and uppercase letters for matrices)</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.35514368 0.73972932 0.76212914 0.13867518 0.13118774 0.68772578
0.99509854 0.72532661 0.31471398 0.74840039]
[0.50470576 0.98650215 0.40892859 0.45312744 0.73435999 0.02180258
0.09650726 0.01846688 0.55640817 0.42742185]
[0.66865889 0.38157698 0.90914803 0.6377013 0.57169969 0.62958747
0.0334336 0.31566127 0.85013763 0.15807529]
[0.47647836 0.36417623 0.63023737 0.23117504 0.3199881 0.61810248
0.46659511 0.34693879 0.60314816 0.56963365]
[0.89800468 0.93792515 0.21378153 0.81700981 0.79689487 0.11967653
0.86528841 0.27518808 0.92397145 0.35768161]
[0.89906633 0.80291466 0.94897736 0.41237041 0.13858317 0.80006807
0.04373024 0.32186558 0.8492168 0.49905638]
[0.09900923 0.98650823 0.62528192 0.64961094 0.00987022 0.57652181
0.93176482 0.84388592 0.58384652 0.35577273]
[0.01312254 0.0494262 0.93742122 0.45937581 0.76428845 0.09004029
0.25529356 0.51566561 0.75079864 0.41790782]
[0.44049151 0.89794988 0.98368659 0.7458376 0.13633112 0.81194394
0.54213195 0.36985812 0.30873019 0.0538391 ]
[0.58310989 0.51631859 0.78546777 0.17576105 0.11368985 0.01384313
0.1949983 0.55960462 0.01496065 0.63588621]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.89184351 0.97435908 0.73122034 0.58084123 0.86891741 0.74957448
0.65593984 0.06020264 0.48306473 0.47729832]
[0.86445334 0.75532041 0.31162122 0.57261202 0.2257449 0.31160886
0.68591105 0.01084359 0.57192197 0.83466807]
[0.39525059 0.32684035 0.91648657 0.34904819 0.47052809 0.7029975
0.0057065 0.1074792 0.6389681 0.16567361]
[0.46984559 0.3241988 0.77559615 0.16431956 0.92604454 0.08624193
0.17567503 0.96919836 0.00859693 0.39692815]
[0.26817703 0.49224801 0.05240397 0.14260706 0.91365263 0.2876045
0.38381781 0.23526911 0.28109198 0.01024875]
[0.47892661 0.88377332 0.51858116 0.02345858 0.52087499 0.63309898
0.589841 0.19433318 0.24071032 0.76262775]
[0.67464946 0.69903406 0.44838546 0.72952595 0.41987877 0.0907958
0.21998973 0.54856099 0.54725976 0.29390668]
[0.75600095 0.3882273 0.13024288 0.19677112 0.6401576 0.34599598
0.62351789 0.49211524 0.6267112 0.82121282]
[0.77959897 0.35714377 0.08946029 0.70039784 0.60418171 0.618746
0.46107913 0.41636775 0.94625725 0.85079059]
[0.0525733 0.16201555 0.18147009 0.41408221 0.15173932 0.88501323
0.01376216 0.8030191 0.61192203 0.64399916]]
</pre></div>
</div>
</div>
@@ -1941,13 +1968,13 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.014891664497538563
3.926564304542535
-0.09715081560068299
[[ 1.04876305 3.19688765 3.16855533]
[ 3.19688765 10.60958647 9.74474996]
[ 3.16855533 9.74474996 15.34369306]]
[23.87923449 0.07172103 3.05108705]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.028638258927275215
4.036527092051294
0.19009085621304586
[[ 1.07405556 3.2781456 2.97935648]
[ 3.2781456 11.21805426 9.35966688]
[ 2.97935648 9.35966688 14.77152924]]
[23.38440469 0.10036694 3.57886743]
</pre></div>
</div>
</div>
@@ -2172,7 +2199,7 @@ Name: Aragorn, dtype: object
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">AttributeError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="nn">/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_49291/1326197715.py</span> in <span class="ni">?</span><span class="nt">()</span>
<span class="nn">/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1539/1326197715.py</span> in <span class="ni">?</span><span class="nt">()</span>
<span class="ne">----&gt; </span><span class="mi">6</span> <span class="n">new_hobbit</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;First Name&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Peregrin&quot;</span><span class="p">],</span>
<span class="g g-Whitespace"> </span><span class="mi">7</span> <span class="s1">&#39;Last Name&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Took&quot;</span><span class="p">],</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="s1">&#39;Place of birth&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Shire&quot;</span><span class="p">],</span>
+52 -33
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -1609,7 +1636,7 @@ Since we are not using <strong>Scikit-Learn</strong> here we can define our own
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.9964486445275116
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.9952537939995855
</pre></div>
</div>
</div>
@@ -1626,7 +1653,7 @@ Since we are not using <strong>Scikit-Learn</strong> here we can define our own
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.008831941890485846
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.011208613520466846
</pre></div>
</div>
</div>
@@ -1641,31 +1668,23 @@ Since we are not using <strong>Scikit-Learn</strong> here we can define our own
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[3.06442194e-02 4.73537890e-02 3.17755779e-02 1.51383260e-02
7.46749552e-02 6.37409975e-02 2.52554699e-02 4.98279090e-03
6.51178631e-02 7.74647981e-03 5.41761415e-03 2.97108525e-02
2.82566059e-02 2.35389684e-02 3.74830119e-02 1.60010693e-02
5.42765083e-02 1.15330788e-02 2.16632351e-02 1.46124943e-02
1.00902152e-02 2.58102999e-02 2.39990572e-02 1.04321941e-02
3.32351459e-02 5.63376422e-03 1.37416502e-02 1.21733307e-02
4.91402008e-03 2.73185968e-02 3.94556653e-02 1.74222022e-03
8.61562855e-03 2.13179053e-02 3.29487549e-02 5.99021575e-03
4.74063343e-03 1.32791346e-02 9.56466087e-03 3.74303070e-03
2.74070824e-02 5.52656770e-03 1.95782166e-02 4.32740721e-02
5.08750220e-02 1.46260797e-02 2.78058232e-02 6.72219105e-03
9.68078357e-03 3.62788541e-02 5.12122786e-03 2.09047191e-02
5.08323973e-02 4.05073207e-02 3.21117128e-02 4.76187240e-04
8.71538320e-03 1.54428380e-03 3.46608732e-02 7.51681181e-03
9.49622615e-03 7.23177156e-05 2.76887029e-02 3.93356853e-02
3.23505507e-02 1.98625331e-02 8.86557766e-03 2.82168579e-03
5.88253432e-02 1.67851352e-02 4.99217800e-02 1.89971681e-03
6.65367685e-02 3.13641587e-03 8.97992238e-04 3.55757089e-02
4.72545392e-02 1.95980855e-02 1.51198558e-02 3.43246775e-03
5.17748443e-02 1.65904730e-02 3.62201698e-03 1.20488808e-02
6.72793290e-02 1.72664028e-02 5.25325161e-03 7.70435575e-03
4.60004008e-02 2.60656897e-04 1.69087404e-02 1.01813007e-02
3.73223692e-02 1.89954169e-02 3.30764357e-02 6.71384474e-02
1.58314173e-02 2.04242885e-02 4.47734350e-02 5.36097931e-02]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[0.05040878 0.02601643 0.01922269 0.05006037 0.02572685 0.10595991
0.04487298 0.00334047 0.00330046 0.00606382 0.02500488 0.03247316
0.01897462 0.0241039 0.0606958 0.00472276 0.01756114 0.06536971
0.02809972 0.04955942 0.00956827 0.00667611 0.02576358 0.04216532
0.04808723 0.01625794 0.00282226 0.00220013 0.00017733 0.0211429
0.02207054 0.02156196 0.0694226 0.01119738 0.0041148 0.01783096
0.0062202 0.03317599 0.02032056 0.00798909 0.06901081 0.01353638
0.01863203 0.01179128 0.01178857 0.00634299 0.01793261 0.00018053
0.13055762 0.02441422 0.05029018 0.0253208 0.01979808 0.02693015
0.05336637 0.01373484 0.09291806 0.00168745 0.04588592 0.01013849
0.04018985 0.03887801 0.03033791 0.01811279 0.02540212 0.02980537
0.02784266 0.03158013 0.01060492 0.01620955 0.00942574 0.0043587
0.02651857 0.00053001 0.0337609 0.01131771 0.00023813 0.02091662
0.01315875 0.00434043 0.04161572 0.05045 0.0121289 0.01532738
0.02334754 0.01206221 0.00930146 0.03244944 0.00702721 0.02576685
0.05224117 0.0262517 0.02946852 0.09604976 0.01406777 0.02183817
0.0164974 0.02322594 0.04238763 0.00647029]
</pre></div>
</div>
</div>
@@ -1734,15 +1753,15 @@ but now splitting the data into a training set and a test set.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 2.06926365 -1.13588335 10.35444257 -8.67801834 4.51542953]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 1.82079885 2.45560415 -4.73595198 14.38102552 -7.04838148]
Training R2
0.9951502749739212
0.9952183728736417
Training MSE
0.011265488125148788
0.009338082195270294
Test R2
0.9923539830272697
0.9969461173312454
Test MSE
0.009522910538005715
0.008043811612683473
</pre></div>
</div>
</div>
+18 -3
View File
@@ -55,7 +55,7 @@ const thebe_selector_output = ".output, .cell_output"
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Project 1 on Machine Learning, deadline October 7 (midnight), 2024" href="project1.html" />
<link rel="next" title="Exercises week 37" href="exercisesweek37.html" />
<link rel="prev" title="Exercises week 36" href="exercisesweek36.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
@@ -278,6 +278,21 @@ const thebe_selector_output = ".output, .cell_output"
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -2917,10 +2932,10 @@ C(\boldsymbol{\beta})=(4-2\beta_0)^2+(2-\beta_1)^2+\lambda(\vert\beta_0\vert+\ve
<p class="prev-next-title">Exercises week 36</p>
</div>
</a>
<a class='right-next' id="next-link" href="project1.html" title="next page">
<a class='right-next' id="next-link" href="exercisesweek37.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Project 1 on Machine Learning, deadline October 7 (midnight), 2024</p>
<p class="prev-next-title">Exercises week 37</p>
</div>
<i class="fas fa-angle-right"></i>
</a>
+10 -13
View File
@@ -1624,7 +1624,7 @@ theorem.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Bootstrap Statistics :
original bias std. error
99.7217 14.8193 99.7194 0.147557
100.211 14.8834 100.212 0.149388
</pre></div>
</div>
</div>
@@ -1849,9 +1849,7 @@ Error: 0.10398646080125035
Bias^2: 0.1007711427354898
Var: 0.0032153180657605116
0.10398646080125035 &gt;= 0.1007711427354898 + 0.0032153180657605116 = 0.10398646080125032
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 3
Polynomial degree: 3
Error: 0.06547790180152355
Bias^2: 0.06208238634231949
Var: 0.0033955154592040936
@@ -1868,7 +1866,9 @@ Error: 0.05227921801205686
Bias^2: 0.0481872773043029
Var: 0.004091940707753939
0.05227921801205686 &gt;= 0.0481872773043029 + 0.004091940707753939 = 0.052279218012056844
Polynomial degree: 6
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 6
Error: 0.037813671417389005
Bias^2: 0.033657685071527665
Var: 0.00415598634586135
@@ -1890,10 +1890,7 @@ Var: 0.016587414993043573
0.02660572763718093 &gt;= 0.010018312644137363 + 0.016587414993043573 = 0.026605727637180936
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree:
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 10
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 10
Error: 0.021592704588025025
Bias^2: 0.010516485576645508
Var: 0.011076219011379514
@@ -1915,7 +1912,7 @@ Var: 0.20867052175034223
0.22842468702219465 &gt;= 0.01975416527185249 + 0.20867052175034223 = 0.2284246870221947
</pre></div>
</div>
<img alt="_images/week37_139_5.png" src="_images/week37_139_5.png" />
<img alt="_images/week37_139_4.png" src="_images/week37_139_4.png" />
</div>
</div>
</div>
@@ -2346,9 +2343,9 @@ Mean squared error on training data: 0.00063866
Mean squared error on test data: 3099.60342978
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_405/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1579/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(trainingerror), label=&#39;Training Error&#39;)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_405/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1579/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(testerror), label=&#39;Test Error&#39;)
</pre></div>
</div>
@@ -2433,7 +2430,7 @@ Mean squared error on test data: 3099.60342978
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_405/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_1579/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(estimated_mse_sklearn), label=&#39;Test Error&#39;)
</pre></div>
</div>