From c35005a900ed85e3003915435fe98df88c4818be Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Wed, 8 Nov 2023 06:50:16 +0100 Subject: [PATCH] update --- doc/pub/week45/html/._week45-bs000.html | 55 ++- doc/pub/week45/html/._week45-bs001.html | 55 ++- doc/pub/week45/html/._week45-bs002.html | 55 ++- doc/pub/week45/html/._week45-bs003.html | 55 ++- doc/pub/week45/html/._week45-bs004.html | 55 ++- doc/pub/week45/html/._week45-bs005.html | 55 ++- doc/pub/week45/html/._week45-bs006.html | 55 ++- doc/pub/week45/html/._week45-bs007.html | 55 ++- doc/pub/week45/html/._week45-bs008.html | 55 ++- doc/pub/week45/html/._week45-bs009.html | 62 ++- doc/pub/week45/html/._week45-bs010.html | 111 ++--- doc/pub/week45/html/._week45-bs011.html | 95 ++-- doc/pub/week45/html/._week45-bs012.html | 82 ++-- doc/pub/week45/html/._week45-bs013.html | 84 ++-- doc/pub/week45/html/._week45-bs014.html | 120 ++--- doc/pub/week45/html/._week45-bs015.html | 66 ++- doc/pub/week45/html/._week45-bs016.html | 125 +++-- doc/pub/week45/html/._week45-bs017.html | 155 ++---- doc/pub/week45/html/._week45-bs018.html | 201 ++------ doc/pub/week45/html/._week45-bs019.html | 168 +++++-- doc/pub/week45/html/._week45-bs020.html | 193 +++++--- doc/pub/week45/html/._week45-bs021.html | 129 ++--- doc/pub/week45/html/._week45-bs022.html | 255 +++++----- doc/pub/week45/html/._week45-bs023.html | 177 +++---- doc/pub/week45/html/._week45-bs024.html | 206 ++++---- doc/pub/week45/html/._week45-bs025.html | 264 +++------- doc/pub/week45/html/._week45-bs026.html | 376 +++++++++------ doc/pub/week45/html/._week45-bs027.html | 476 +++++++++++++------ doc/pub/week45/html/week45-bs.html | 55 ++- doc/pub/week45/html/week45-reveal.html | 69 ++- doc/pub/week45/html/week45-solarized.html | 66 ++- doc/pub/week45/html/week45.html | 66 ++- doc/pub/week45/ipynb/ipynb-week45-src.tar.gz | Bin 6057452 -> 6057452 bytes doc/pub/week45/ipynb/week45.ipynb | 347 ++++++++------ doc/src/week45/week45.do.txt | 59 ++- 35 files changed, 2431 insertions(+), 2071 deletions(-) diff --git a/doc/pub/week45/html/._week45-bs000.html b/doc/pub/week45/html/._week45-bs000.html index fe1e65103..877c6bf0c 100644 --- a/doc/pub/week45/html/._week45-bs000.html +++ b/doc/pub/week45/html/._week45-bs000.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -252,7 +259,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs001.html b/doc/pub/week45/html/._week45-bs001.html index b43f869ca..a7bdd286f 100644 --- a/doc/pub/week45/html/._week45-bs001.html +++ b/doc/pub/week45/html/._week45-bs001.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -261,7 +268,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs002.html b/doc/pub/week45/html/._week45-bs002.html index 4ee068c9e..20aebbb2d 100644 --- a/doc/pub/week45/html/._week45-bs002.html +++ b/doc/pub/week45/html/._week45-bs002.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -228,7 +235,7 @@ MathJax.Hub.Config({
  • 11
  • 12
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs003.html b/doc/pub/week45/html/._week45-bs003.html index bc83720eb..9c9258a9b 100644 --- a/doc/pub/week45/html/._week45-bs003.html +++ b/doc/pub/week45/html/._week45-bs003.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -308,7 +315,7 @@ This becomes however less functional in the long run.
  • 12
  • 13
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs004.html b/doc/pub/week45/html/._week45-bs004.html index 5e68271b5..429c0b6f0 100644 --- a/doc/pub/week45/html/._week45-bs004.html +++ b/doc/pub/week45/html/._week45-bs004.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -307,7 +314,7 @@ contains more information on how to set the different parameters.
  • 13
  • 14
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs005.html b/doc/pub/week45/html/._week45-bs005.html index cb43ca66e..b4b97f48e 100644 --- a/doc/pub/week45/html/._week45-bs005.html +++ b/doc/pub/week45/html/._week45-bs005.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -307,7 +314,7 @@ ypredictRidge = gridsearch14
  • 15
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs006.html b/doc/pub/week45/html/._week45-bs006.html index 7e0d4e67e..ddf680c4f 100644 --- a/doc/pub/week45/html/._week45-bs006.html +++ b/doc/pub/week45/html/._week45-bs006.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -276,7 +283,7 @@ logreg.fit(X_train, y_train)
  • 15
  • 16
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs007.html b/doc/pub/week45/html/._week45-bs007.html index d79111691..8ffbc6466 100644 --- a/doc/pub/week45/html/._week45-bs007.html +++ b/doc/pub/week45/html/._week45-bs007.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -293,7 +300,7 @@ plt.show()
  • 16
  • 17
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs008.html b/doc/pub/week45/html/._week45-bs008.html index a17269f48..ae4641878 100644 --- a/doc/pub/week45/html/._week45-bs008.html +++ b/doc/pub/week45/html/._week45-bs008.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -302,7 +309,7 @@ applications. This will be discussed later this semester (17
  • 18
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs009.html b/doc/pub/week45/html/._week45-bs009.html index 4b65fd3fa..8ff9cf3f6 100644 --- a/doc/pub/week45/html/._week45-bs009.html +++ b/doc/pub/week45/html/._week45-bs009.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -222,6 +229,13 @@ The following quantities are then used
  • The false positive \( FP \) number, a so-called type I error which tells us about the fraction of positive test result which are wrongly classified
  • A false negative \( FN \) number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified.
  • +

    It is is easy to think in terms of illness. You could think of the above as

    +
      +
    1. True positive: Sick people correctly identified as sick
    2. +
    3. False positive: Healthy people incorrectly identified as sick
    4. +
    5. True negative: Healthy people correctly identified as healthy
    6. +
    7. False negative: Sick people incorrectly identified as healthy
    8. +

    diff --git a/doc/pub/week45/html/._week45-bs010.html b/doc/pub/week45/html/._week45-bs010.html index 2c56f7dce..ff9125e36 100644 --- a/doc/pub/week45/html/._week45-bs010.html +++ b/doc/pub/week45/html/._week45-bs010.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -222,41 +229,7 @@ $$ - -
    -
    - -$$ -{\displaystyle \mathrm {TNR} ={\frac {\mathrm {TN} }{\mathrm {N} }}={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FP} }}=1-\mathrm {FPR} } -$$ - -

    with the fall-out false positive rate

    -$$ -{\displaystyle \mathrm {FPR} ={\frac {\mathrm {FP} }{\mathrm {N} }}={\frac {\mathrm {FP} }{\mathrm {FP} +\mathrm {TN} }}=1-\mathrm {TNR} } -$$ -
    -
    - - -
    -
    - -$$ -{\displaystyle \mathrm {PPV} ={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FP} }}=1-\mathrm {FDR} } -$$ -
    -
    - - -
    -
    - -$$ -{\displaystyle \mathrm {NPV} ={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FN} }}=1-\mathrm {FOR} } -$$ -
    -
    - +

    The \( TPR \) defines how many correct positive results occur among all positive samples available during the test

    @@ -272,21 +245,19 @@ $$
    $$ -{\displaystyle \mathrm {FDR} ={\frac {\mathrm {FP} }{\mathrm {FP} +\mathrm {TP} }}=1-\mathrm {PPV} } -$$ -
    -
    - - -
    -
    - -$$ -{\displaystyle \mathrm {FOR} ={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TN} }}=1-\mathrm {NPV} } +{\displaystyle \mathrm {TNR} ={\frac {\mathrm {TN} }{\mathrm {N} }}={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FP} }}=1-\mathrm {FPR} } +$$ + +

    with the fall-out false positive rate

    +$$ +{\displaystyle \mathrm {FPR} ={\frac {\mathrm {FP} }{\mathrm {N} }}={\frac {\mathrm {FP} }{\mathrm {FP} +\mathrm {TN} }}=1-\mathrm {TNR} } $$
    +

    The \( FPR \) defines how many incorrect positive results occur among +all negative samples available during the test. +

    @@ -313,7 +284,7 @@ $$

  • 19
  • 20
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs011.html b/doc/pub/week45/html/._week45-bs011.html index c484ccf01..0c3b85546 100644 --- a/doc/pub/week45/html/._week45-bs011.html +++ b/doc/pub/week45/html/._week45-bs011.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,30 +216,34 @@ MathJax.Hub.Config({

     

     

     

    -

    \( F_1 \) score

    +

    Positive and negative prediction values

    -

    In statistical analysis of binary classification, the F-score or -F-measure is a measure of a test's accuracy. It is calculated from the -precision and recall of the test, where the precision is the number of -true positive results divided by the number of all positive results, -including those not identified correctly, and the recall is the number -of true positive results divided by the number of all samples that -should have been identified as positive. Precision is also known as -positive predictive value, and recall is also known as sensitivity in -diagnostic binary classification. +

    The positive and negative predictive values +are the proportions of positive and negative results in statistics and +diagnostic tests that are true positive and true negative results, +respectively.[1] The PPV and NPV describe the performance of a +diagnostic test or other statistical measure. A high result can be +interpreted as indicating the accuracy of such a statistic.

    -

    The F1 score is the harmonic mean of the precision and recall. It thus -symmetrically represents both precision and recall in one metric. The -highest possible value of an F-score is 1.0, indicating perfect -precision and recall, and the lowest possible value is 0, if either -precision or recall are zero. -

    +
    +
    + +$$ +{\displaystyle \mathrm {PPV} ={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FP} }}=1-\mathrm {FDR} } +$$ +
    +
    -

    It is defined as

    + +
    +
    + $$ -{\displaystyle \mathrm {F} _{1}=2\times {\frac {\mathrm {PPV} \times \mathrm {TPR} }{\mathrm {PPV} +\mathrm {TPR} }}={\frac {2\mathrm {TP} }{2\mathrm {TP} +\mathrm {FP} +\mathrm {FN} }}} +{\displaystyle \mathrm {NPV} ={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FN} }}=1-\mathrm {FOR} } $$ +
    +

    @@ -260,7 +271,7 @@ $$

  • 20
  • 21
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs012.html b/doc/pub/week45/html/._week45-bs012.html index 5ac9a4bae..d0613380c 100644 --- a/doc/pub/week45/html/._week45-bs012.html +++ b/doc/pub/week45/html/._week45-bs012.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,16 +216,27 @@ MathJax.Hub.Config({

     

     

     

    -

    ROC curve

    +

    Other quantities

    -

    A receiver operating characteristic curve, or ROC curve, is a -graphical plot that illustrates the performance of a binary classifier -model at varying threshold values. -

    +
    +
    + +$$ +{\displaystyle \mathrm {FDR} ={\frac {\mathrm {FP} }{\mathrm {FP} +\mathrm {TP} }}=1-\mathrm {PPV} } +$$ +
    +
    + + +
    +
    + +$$ +{\displaystyle \mathrm {FOR} ={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TN} }}=1-\mathrm {NPV} } +$$ +
    +
    -

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting. -See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions. -

    @@ -245,7 +263,7 @@ See 21

  • 22
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs013.html b/doc/pub/week45/html/._week45-bs013.html index a28d30aa0..7d6ce561e 100644 --- a/doc/pub/week45/html/._week45-bs013.html +++ b/doc/pub/week45/html/._week45-bs013.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,15 +216,32 @@ MathJax.Hub.Config({

     

     

     

    -

    Cumulative gain curve

    +

    \( F_1 \) score

    -

    The cumulative gain curve is a performance evaluation used typically for binary classification problems. -It plots the \( TPR \) True Positive Rate or Sensitivity (which represents the -fraction of examples correctly classified -against Predictive Positive Rate, which represents -the fraction of positively predicted examples. +

    In statistical analysis of binary classification, the F-score or +F-measure is a measure of a test's accuracy. It is calculated from the +precision and recall of the test, where the precision is the number of +true positive results divided by the number of all positive results, +including those not identified correctly, and the recall is the number +of true positive results divided by the number of all samples that +should have been identified as positive. Precision is also known as +positive predictive value, and recall is also known as sensitivity in +diagnostic binary classification.

    +

    The F1 score is the harmonic mean of the precision and recall. It thus +symmetrically represents both precision and recall in one metric. The +highest possible value of an F-score is 1.0, indicating perfect +precision and recall, and the lowest possible value is 0, if either +precision or recall are zero. +

    + +

    It is defined as

    +$$ +{\displaystyle \mathrm {F} _{1}=2\times {\frac {\mathrm {PPV} \times \mathrm {TPR} }{\mathrm {PPV} +\mathrm {TPR} }}={\frac {2\mathrm {TP} }{2\mathrm {TP} +\mathrm {FP} +\mathrm {FN} }}} +$$ + +

      @@ -243,7 +267,7 @@ the fraction of positively predicted examples.
    • 22
    • 23
    • ...
    • -
    • 26
    • +
    • 28
    • »
    diff --git a/doc/pub/week45/html/._week45-bs014.html b/doc/pub/week45/html/._week45-bs014.html index 67bb54df9..180bb9fc8 100644 --- a/doc/pub/week45/html/._week45-bs014.html +++ b/doc/pub/week45/html/._week45-bs014.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,61 +216,24 @@ MathJax.Hub.Config({

     

     

     

    -

    Other measures in classification studies: Cancer Data again

    +

    ROC curve

    - -
    -
    -
    -
    -
    -
    import matplotlib.pyplot as plt
    -import numpy as np
    -from sklearn.model_selection import  train_test_split 
    -from sklearn.datasets import load_breast_cancer
    -from sklearn.linear_model import LogisticRegression
    +

    A receiver operating characteristic curve, or ROC curve, is a +graphical plot that illustrates the performance of a binary classifier +model at varying threshold values. +

    -# Load the data -cancer = load_breast_cancer() +

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting.

    -X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0) -print(X_train.shape) -print(X_test.shape) -# Logistic Regression -logreg = LogisticRegression(solver='lbfgs') -logreg.fit(X_train, y_train) - -from sklearn.preprocessing import LabelEncoder -from sklearn.model_selection import cross_validate -#Cross validation -accuracy = cross_validate(logreg,X_test,y_test,cv=10)['test_score'] -print(accuracy) -print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) - -import scikitplot as skplt -y_pred = logreg.predict(X_test) -skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) -plt.show() -y_probas = logreg.predict_proba(X_test) -skplt.metrics.plot_roc(y_test, y_probas) -plt.show() -skplt.metrics.plot_cumulative_gain(y_test, y_probas) -plt.show() -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    To draw a ROC curve, only the true positive rate (TPR) and false +positive rate (FPR) are needed (as functions of some classifier +parameter). The TPR defines how many correct positive results occur +among all positive samples available during the test. FPR, on the +other hand, defines how many incorrect positive results occur among +all negative samples available during the test. +

    +

    See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions.

    @@ -290,7 +260,7 @@ plt.show()

  • 23
  • 24
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs015.html b/doc/pub/week45/html/._week45-bs015.html index 33b964b08..819b24014 100644 --- a/doc/pub/week45/html/._week45-bs015.html +++ b/doc/pub/week45/html/._week45-bs015.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,7 +216,16 @@ MathJax.Hub.Config({

     

     

     

    -

    Material for Lecture Thursday November 9

    +

    Cumulative gain curve

    + +

    The cumulative gain curve is a performance evaluation used typically for binary classification problems. +It plots the \( TPR \) True Positive Rate or Sensitivity (which represents the +fraction of examples correctly classified +against Predictive Positive Rate, which represents +the fraction of positively predicted examples. +

    + +

    The examples below show the confusion matrix, the ROC curve and the cumulative gain for the Wisconsin cancer data.

    @@ -236,7 +252,7 @@ MathJax.Hub.Config({

  • 24
  • 25
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs016.html b/doc/pub/week45/html/._week45-bs016.html index 6f9b94d3c..3cd1fdfe3 100644 --- a/doc/pub/week45/html/._week45-bs016.html +++ b/doc/pub/week45/html/._week45-bs016.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,27 +216,61 @@ MathJax.Hub.Config({

     

     

     

    -

    Recurrent neural networks (RNNs): Overarching view

    +

    Other measures in classification studies: Cancer Data again

    -

    Till now our focus has been, including convolutional neural networks -as well, on feedforward neural networks. The output or the activations -flow only in one direction, from the input layer to the output layer. -

    + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.datasets import load_breast_cancer
    +from sklearn.linear_model import LogisticRegression
     
    -

    A recurrent neural network (RNN) looks very much like a feedforward -neural network, except that it also has connections pointing -backward. -

    +# Load the data +cancer = load_breast_cancer() + +X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0) +print(X_train.shape) +print(X_test.shape) +# Logistic Regression +logreg = LogisticRegression(solver='lbfgs') +logreg.fit(X_train, y_train) + +from sklearn.preprocessing import LabelEncoder +from sklearn.model_selection import cross_validate +#Cross validation +accuracy = cross_validate(logreg,X_test,y_test,cv=10)['test_score'] +print(accuracy) +print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test))) + +import scikitplot as skplt +y_pred = logreg.predict(X_test) +skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True) +plt.show() +y_probas = logreg.predict_proba(X_test) +skplt.metrics.plot_roc(y_test, y_probas) +plt.show() +skplt.metrics.plot_cumulative_gain(y_test, y_probas) +plt.show() +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    RNNs are used to analyze time series data such as stock prices, and -tell you when to buy or sell. In autonomous driving systems, they can -anticipate car trajectories and help avoid accidents. More generally, -they can work on sequences of arbitrary lengths, rather than on -fixed-sized inputs like all the nets we have discussed so far. For -example, they can take sentences, documents, or audio samples as -input, making them extremely useful for natural language processing -systems such as automatic translation and speech-to-text. -

    @@ -255,6 +296,8 @@ systems such as automatic translation and speech-to-text.

  • 24
  • 25
  • 26
  • +
  • ...
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs017.html b/doc/pub/week45/html/._week45-bs017.html index 665fc534a..5f7beec94 100644 --- a/doc/pub/week45/html/._week45-bs017.html +++ b/doc/pub/week45/html/._week45-bs017.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,104 +216,7 @@ MathJax.Hub.Config({

     

     

     

    -

    A simple example

    - - - -
    -
    -
    -
    -
    -
    # Start importing packages
    -import pandas as pd
    -import numpy as np
    -import matplotlib.pyplot as plt
    -import tensorflow as tf
    -from tensorflow.keras import datasets, layers, models
    -from tensorflow.keras.layers import Input
    -from tensorflow.keras.models import Model, Sequential 
    -from tensorflow.keras.layers import Dense, SimpleRNN, LSTM, GRU
    -from tensorflow.keras import optimizers     
    -from tensorflow.keras import regularizers           
    -from tensorflow.keras.utils import to_categorical 
    -
    -
    -
    -# convert into dataset matrix
    -def convertToMatrix(data, step):
    - X, Y =[], []
    - for i in range(len(data)-step):
    -  d=i+step  
    -  X.append(data[i:d,])
    -  Y.append(data[d,])
    - return np.array(X), np.array(Y)
    -
    -step = 4
    -N = 1000    
    -Tp = 800    
    -
    -t=np.arange(0,N)
    -x=np.sin(0.02*t)+2*np.random.rand(N)
    -df = pd.DataFrame(x)
    -df.head()
    -
    -values=df.values
    -train,test = values[0:Tp,:], values[Tp:N,:]
    -
    -# add step elements into train and test
    -test = np.append(test,np.repeat(test[-1,],step))
    -train = np.append(train,np.repeat(train[-1,],step))
    - 
    -trainX,trainY =convertToMatrix(train,step)
    -testX,testY =convertToMatrix(test,step)
    -trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
    -testX = np.reshape(testX, (testX.shape[0], 1, testX.shape[1]))
    -
    -model = Sequential()
    -model.add(SimpleRNN(units=32, input_shape=(1,step), activation="relu"))
    -model.add(Dense(8, activation="relu")) 
    -model.add(Dense(1))
    -model.compile(loss='mean_squared_error', optimizer='rmsprop')
    -model.summary()
    -
    -model.fit(trainX,trainY, epochs=100, batch_size=16, verbose=2)
    -trainPredict = model.predict(trainX)
    -testPredict= model.predict(testX)
    -predicted=np.concatenate((trainPredict,testPredict),axis=0)
    -
    -trainScore = model.evaluate(trainX, trainY, verbose=0)
    -print(trainScore)
    -plt.plot(df)
    -plt.plot(predicted)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -

    RNNs

    - -

    RNNs are very powerful, because they -combine two properties: -

    -
      -
    1. Distributed hidden state that allows them to store a lot of information about the past efficiently.
    2. -
    3. Non-linear dynamics that allows them to update their hidden state in complicated ways.
    4. -
    -

    With enough neurons and time, RNNs -can compute anything that can be -computed by your computer! -

    +

    Material for Lecture Thursday November 9

    @@ -331,6 +241,9 @@ computed by your computer!

  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • ...
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs018.html b/doc/pub/week45/html/._week45-bs018.html index 29bc99721..bed310f63 100644 --- a/doc/pub/week45/html/._week45-bs018.html +++ b/doc/pub/week45/html/._week45-bs018.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,139 +216,27 @@ MathJax.Hub.Config({

     

     

     

    -

    Basic layout

    +

    Recurrent neural networks (RNNs): Overarching view

    -

    -
    -

    -
    -

    -

    We need to specify the initial activity state of all the hidden and output units

    - -
      -
    1. We could just fix these initial states to have some default value like 0.5.
    2. -
    3. But it is better to treat the initial states as learned parameters.
    4. -
    5. We learn them in the same way as we learn the weights.
    6. -
    7. Start off with an initial random guess for the initial states. -
        -
      1. At the end of each training sequence, backpropagate through time all the way to the initial states to get the gradient of the error function with respect to each initial state.
      2. -
      3. Adjust the initial states by following the negative gradient.
      4. -
      -
    -

    We can specify inputs in several ways

    - -
      -
    1. Specify the initial states of all the units.
    2. -
    3. Specify the initial states of a subset of the units.
    4. -
    5. Specify the states of the same subset of the units at every time step.
    6. -
    -

    This is the natural way to model most sequential data.

    -

    We can specify targets in several ways

    - -
      -
    1. Specify desired final activities of all the units
    2. -
    3. Specify desired activities of all units for the last few steps
    4. -
    5. Good for learning attractors
    6. -
    7. It is easy to add in extra error derivatives as we backpropagate.
    8. -
        -
      • Specify the desired activity of a subset of the units.
      • -
      -
    9. The other units are input or hidden units.
    10. -
    -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    -

    Backpropagation through time

    - -
    -
    - -

    We can think of the recurrent net as a layered, feed-forward -net with shared weights and then train the feed-forward net -with weight constraints. -

    -
    -
    - - -

    We can also think of this training algorithm in the time domain:

    -
      -
    1. The forward pass builds up a stack of the activities of all the units at each time step.
    2. -
    3. The backward pass peels activities off the stack to compute the error derivatives at each time step.
    4. -
    5. After the backward pass we add together the derivatives at all the different times for each weight.
    6. -
    -

    The backward pass is linear

    - -
      -
    1. There is a big difference between the forward and backward passes.
    2. -
    3. In the forward pass we use squashing functions (like the logistic) to prevent the activity vectors from exploding.
    4. -
    5. The backward pass, is completely linear. If you double the error derivatives at the final layer, all the error derivatives will double.
    6. -
    -

    The forward pass determines the slope of the linear function used for -backpropagating through each neuron +

    Till now our focus has been, including convolutional neural networks +as well, on feedforward neural networks. The output or the activations +flow only in one direction, from the input layer to the output layer.

    -

    -
    -

    -
    -

    +

    A recurrent neural network (RNN) looks very much like a feedforward +neural network, except that it also has connections pointing +backward. +

    -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    +

    RNNs are used to analyze time series data such as stock prices, and +tell you when to buy or sell. In autonomous driving systems, they can +anticipate car trajectories and help avoid accidents. More generally, +they can work on sequences of arbitrary lengths, rather than on +fixed-sized inputs like all the nets we have discussed so far. For +example, they can take sentences, documents, or audio samples as +input, making them extremely useful for natural language processing +systems such as automatic translation and speech-to-text. +

    @@ -365,6 +260,8 @@ backpropagating through each neuron

  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs019.html b/doc/pub/week45/html/._week45-bs019.html index dbd976e23..dea258efa 100644 --- a/doc/pub/week45/html/._week45-bs019.html +++ b/doc/pub/week45/html/._week45-bs019.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -208,22 +215,105 @@ MathJax.Hub.Config({

     

     

     

    - -

    The problem of exploding or vanishing gradients

    -
      -
    • What happens to the magnitude of the gradients as we backpropagate through many layers? -
        -
      1. If the weights are small, the gradients shrink exponentially.
      2. -
      3. If the weights are big the gradients grow exponentially.
      4. + +

        A simple example

        + + + +
        +
        +
        +
        +
        +
        # Start importing packages
        +import pandas as pd
        +import numpy as np
        +import matplotlib.pyplot as plt
        +import tensorflow as tf
        +from tensorflow.keras import datasets, layers, models
        +from tensorflow.keras.layers import Input
        +from tensorflow.keras.models import Model, Sequential 
        +from tensorflow.keras.layers import Dense, SimpleRNN, LSTM, GRU
        +from tensorflow.keras import optimizers     
        +from tensorflow.keras import regularizers           
        +from tensorflow.keras.utils import to_categorical 
        +
        +
        +
        +# convert into dataset matrix
        +def convertToMatrix(data, step):
        + X, Y =[], []
        + for i in range(len(data)-step):
        +  d=i+step  
        +  X.append(data[i:d,])
        +  Y.append(data[d,])
        + return np.array(X), np.array(Y)
        +
        +step = 4
        +N = 1000    
        +Tp = 800    
        +
        +t=np.arange(0,N)
        +x=np.sin(0.02*t)+2*np.random.rand(N)
        +df = pd.DataFrame(x)
        +df.head()
        +
        +values=df.values
        +train,test = values[0:Tp,:], values[Tp:N,:]
        +
        +# add step elements into train and test
        +test = np.append(test,np.repeat(test[-1,],step))
        +train = np.append(train,np.repeat(train[-1,],step))
        + 
        +trainX,trainY =convertToMatrix(train,step)
        +testX,testY =convertToMatrix(test,step)
        +trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
        +testX = np.reshape(testX, (testX.shape[0], 1, testX.shape[1]))
        +
        +model = Sequential()
        +model.add(SimpleRNN(units=32, input_shape=(1,step), activation="relu"))
        +model.add(Dense(8, activation="relu")) 
        +model.add(Dense(1))
        +model.compile(loss='mean_squared_error', optimizer='rmsprop')
        +model.summary()
        +
        +model.fit(trainX,trainY, epochs=100, batch_size=16, verbose=2)
        +trainPredict = model.predict(trainX)
        +testPredict= model.predict(testX)
        +predicted=np.concatenate((trainPredict,testPredict),axis=0)
        +
        +trainScore = model.evaluate(trainX, trainY, verbose=0)
        +print(trainScore)
        +plt.plot(df)
        +plt.plot(predicted)
        +plt.show()
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +
        +

        RNNs

        + +

        RNNs are very powerful, because they +combine two properties: +

        +
          +
        1. Distributed hidden state that allows them to store a lot of information about the past efficiently.
        2. +
        3. Non-linear dynamics that allows them to update their hidden state in complicated ways.
        -
      5. Typical feed-forward neural nets can cope with these exponential effects because they only have a few hidden layers.
      6. -
      7. In an RNN trained on long sequences (e.g. 100 time steps) the gradients can easily explode or vanish. -
          -
        1. We can avoid this by initializing the weights very carefully.
        2. -
        -
      8. Even with good initial weights, its very hard to detect that the current target output depends on an input from many time-steps ago.
      9. -
    -

    RNNs have difficulty dealing with long-range dependencies.

    +

    With enough neurons and time, RNNs +can compute anything that can be +computed by your computer! +

    @@ -246,6 +336,8 @@ MathJax.Hub.Config({

  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs020.html b/doc/pub/week45/html/._week45-bs020.html index 0cbdf6c79..da5d264a7 100644 --- a/doc/pub/week45/html/._week45-bs020.html +++ b/doc/pub/week45/html/._week45-bs020.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,99 +216,137 @@ MathJax.Hub.Config({

     

     

     

    -

    Four effective ways to learn an RNN

    +

    Basic layout

    + +

    +
    +

    +
    +

    +

    We need to specify the initial activity state of all the hidden and output units

    +
      -
    1. Long Short Term Memory Make the RNN out of little modules that are designed to remember values for a long time.
    2. -
    3. Hessian Free Optimization: Deal with the vanishing gradients problem by using a fancy optimizer that can detect directions with a tiny gradient but even smaller curvature.
    4. -
    5. Echo State Networks: Initialize the input a hidden and hidden-hidden and output-hidden connections very carefully so that the hidden state has a huge reservoir of weakly coupled oscillators which can be selectively driven by the input.
    6. +
    7. We could just fix these initial states to have some default value like 0.5.
    8. +
    9. But it is better to treat the initial states as learned parameters.
    10. +
    11. We learn them in the same way as we learn the weights.
    12. +
    13. Start off with an initial random guess for the initial states. +
        +
      1. At the end of each training sequence, backpropagate through time all the way to the initial states to get the gradient of the error function with respect to each initial state.
      2. +
      3. Adjust the initial states by following the negative gradient.
      4. +
      +
    +

    We can specify inputs in several ways

    + +
      +
    1. Specify the initial states of all the units.
    2. +
    3. Specify the initial states of a subset of the units.
    4. +
    5. Specify the states of the same subset of the units at every time step.
    6. +
    +

    This is the natural way to model most sequential data.

    +

    We can specify targets in several ways

    + +
      +
    1. Specify desired final activities of all the units
    2. +
    3. Specify desired activities of all units for the last few steps
    4. +
    5. Good for learning attractors
    6. +
    7. It is easy to add in extra error derivatives as we backpropagate.
      • -
      • ESNs only need to learn the hidden-output connections.
      • +
      • Specify the desired activity of a subset of the units.
      -
    8. Good initialization with momentum Initialize like in Echo State Networks, but then learn all of the connections using momentum
    9. +
    10. The other units are input or hidden units.
    -

    Long Short Term Memory (LSTM)

    +

    +
    +

    +
    +

    -

    LSTM uses a memory cell for - modeling long-range dependencies and avoid vanishing gradient - problems. +

    +

    +

    +
    +

    + +

    +
    +

    +
    +

    + +

    +
    +

    +
    +

    +

    Backpropagation through time

    + +
    +
    + +

    We can think of the recurrent net as a layered, feed-forward +net with shared weights and then train the feed-forward net +with weight constraints.

    +
    +
    + + +

    We can also think of this training algorithm in the time domain:

    +
      +
    1. The forward pass builds up a stack of the activities of all the units at each time step.
    2. +
    3. The backward pass peels activities off the stack to compute the error derivatives at each time step.
    4. +
    5. After the backward pass we add together the derivatives at all the different times for each weight.
    6. +
    +

    The backward pass is linear

      -
    1. Introduced by Hochreiter and Schmidhuber (1997) who solved the problem of getting an RNN to remember things for a long time (like hundreds of time steps).
    2. -
    3. They designed a memory cell using logistic and linear units with multiplicative interactions.
    4. -
    5. Information gets into the cell whenever its “write” gate is on.
    6. -
    7. The information stays in the cell so long as its keep gate is on.
    8. -
    9. Information can be read from the cell by turning on its read gate.
    10. +
    11. There is a big difference between the forward and backward passes.
    12. +
    13. In the forward pass we use squashing functions (like the logistic) to prevent the activity vectors from exploding.
    14. +
    15. The backward pass, is completely linear. If you double the error derivatives at the final layer, all the error derivatives will double.
    -

    Implementing a memory cell in a neural network

    -

    To preserve information for a long time in -the activities of an RNN, we use a circuit -that implements an analog memory cell. +

    The forward pass determines the slope of the linear function used for +backpropagating through each neuron

    -
      -
    1. A linear unit that has a self-link with a weight of 1 will maintain its state.
    2. -
    3. Information is stored in the cell by activating its write gate.
    4. -
    5. Information is retrieved by activating the read gate.
    6. -
    7. We can backpropagate through this circuit because logistics are have nice derivatives.
    8. -


    -

    +





    -

    +





    -

    +





    -

    +





    -

    +





    -

    +





    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    -
    -

    - -

    -
    -

    +



    @@ -325,6 +370,8 @@ that implements an analog memory cell.
  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs021.html b/doc/pub/week45/html/._week45-bs021.html index 2c8ea46f4..2fb6ebf7b 100644 --- a/doc/pub/week45/html/._week45-bs021.html +++ b/doc/pub/week45/html/._week45-bs021.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -208,64 +215,22 @@ MathJax.Hub.Config({

     

     

     

    - -

    An extrapolation example

    - -

    The following code provides an example of how recurrent neural -networks can be used to extrapolate to unknown values of physics data -sets. Specifically, the data sets used in this program come from -a quantum mechanical many-body calculation of energies as functions of the number of particles. -

    - - - -
    -
    -
    -
    -
    -
    # For matrices and calculations
    -import numpy as np
    -# For machine learning (backend for keras)
    -import tensorflow as tf
    -# User-friendly machine learning library
    -# Front end for TensorFlow
    -import tensorflow.keras
    -# Different methods from Keras needed to create an RNN
    -# This is not necessary but it shortened function calls 
    -# that need to be used in the code.
    -from tensorflow.keras import datasets, layers, models
    -from tensorflow.keras.layers import Input
    -from tensorflow.keras import regularizers
    -from tensorflow.keras.models import Model, Sequential
    -from tensorflow.keras.layers import Dense, SimpleRNN, LSTM, GRU
    -# For timing the code
    -from timeit import default_timer as timer
    -# For plotting
    -import matplotlib.pyplot as plt
    -
    -
    -# The data set
    -datatype='VaryDimension'
    -X_tot = np.arange(2, 42, 2)
    -y_tot = np.array([-0.03077640549, -0.08336233266, -0.1446729567, -0.2116753732, -0.2830637392, -0.3581341341, -0.436462435, -0.5177783846,
    -	-0.6019067271, -0.6887363571, -0.7782028952, -0.8702784034, -0.9649652536, -1.062292565, -1.16231451, 
    -	-1.265109911, -1.370782966, -1.479465113, -1.591317992, -1.70653767])
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - + +

    The problem of exploding or vanishing gradients

    +
      +
    • What happens to the magnitude of the gradients as we backpropagate through many layers? +
        +
      1. If the weights are small, the gradients shrink exponentially.
      2. +
      3. If the weights are big the gradients grow exponentially.
      4. +
      +
    • Typical feed-forward neural nets can cope with these exponential effects because they only have a few hidden layers.
    • +
    • In an RNN trained on long sequences (e.g. 100 time steps) the gradients can easily explode or vanish. +
        +
      1. We can avoid this by initializing the weights very carefully.
      2. +
      +
    • Even with good initial weights, its very hard to detect that the current target output depends on an input from many time-steps ago.
    • +
    +

    RNNs have difficulty dealing with long-range dependencies.

    @@ -286,6 +251,8 @@ y_tot = np.24

  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs022.html b/doc/pub/week45/html/._week45-bs022.html index f19740b44..cd49d5393 100644 --- a/doc/pub/week45/html/._week45-bs022.html +++ b/doc/pub/week45/html/._week45-bs022.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,137 +216,101 @@ MathJax.Hub.Config({

     

     

     

    -

    Formatting the Data

    +

    Four effective ways to learn an RNN

    +
      +
    1. Long Short Term Memory Make the RNN out of little modules that are designed to remember values for a long time.
    2. +
    3. Hessian Free Optimization: Deal with the vanishing gradients problem by using a fancy optimizer that can detect directions with a tiny gradient but even smaller curvature.
    4. +
    5. Echo State Networks: Initialize the input a hidden and hidden-hidden and output-hidden connections very carefully so that the hidden state has a huge reservoir of weakly coupled oscillators which can be selectively driven by the input.
    6. +
        +
      • ESNs only need to learn the hidden-output connections.
      • +
      +
    7. Good initialization with momentum Initialize like in Echo State Networks, but then learn all of the connections using momentum
    8. +
    +

    Long Short Term Memory (LSTM)

    -

    The way the recurrent neural networks are trained in this program -differs from how machine learning algorithms are usually trained. -Typically a machine learning algorithm is trained by learning the -relationship between the x data and the y data. In this program, the -recurrent neural network will be trained to recognize the relationship -in a sequence of y values. This is type of data formatting is -typically used time series forcasting, but it can also be used in any -extrapolation (time series forecasting is just a specific type of -extrapolation along the time axis). This method of data formatting -does not use the x data and assumes that the y data are evenly spaced. +

    LSTM uses a memory cell for + modeling long-range dependencies and avoid vanishing gradient + problems.

    -

    For a standard machine learning algorithm, the training data has the -form of (x,y) so the machine learning algorithm learns to assiciate a -y value with a given x value. This is useful when the test data has x -values within the same range as the training data. However, for this -application, the x values of the test data are outside of the x values -of the training data and the traditional method of training a machine -learning algorithm does not work as well. For this reason, the -recurrent neural network is trained on sequences of y values of the -form ((y1, y2), y3), so that the network is concerned with learning -the pattern of the y data and not the relation between the x and y -data. As long as the pattern of y data outside of the training region -stays relatively stable compared to what was inside the training -region, this method of training can produce accurate extrapolations to -y values far removed from the training data set. +

      +
    1. Introduced by Hochreiter and Schmidhuber (1997) who solved the problem of getting an RNN to remember things for a long time (like hundreds of time steps).
    2. +
    3. They designed a memory cell using logistic and linear units with multiplicative interactions.
    4. +
    5. Information gets into the cell whenever its “write” gate is on.
    6. +
    7. The information stays in the cell so long as its keep gate is on.
    8. +
    9. Information can be read from the cell by turning on its read gate.
    10. +
    +

    Implementing a memory cell in a neural network

    +

    To preserve information for a long time in +the activities of an RNN, we use a circuit +that implements an analog memory cell.

    - - - - - - +
      +
    1. A linear unit that has a self-link with a weight of 1 will maintain its state.
    2. +
    3. Information is stored in the cell by activating its write gate.
    4. +
    5. Information is retrieved by activating the read gate.
    6. +
    7. We can backpropagate through this circuit because logistics are have nice derivatives.
    8. +
    +

    +
    +

    +
    +

    +

    +
    +

    +
    +

    - -
    -
    -
    -
    -
    -
    # FORMAT_DATA
    -def format_data(data, length_of_sequence = 2):  
    -    """
    -        Inputs:
    -            data(a numpy array): the data that will be the inputs to the recurrent neural
    -                network
    -            length_of_sequence (an int): the number of elements in one iteration of the
    -                sequence patter.  For a function approximator use length_of_sequence = 2.
    -        Returns:
    -            rnn_input (a 3D numpy array): the input data for the recurrent neural network.  Its
    -                dimensions are length of data - length of sequence, length of sequence, 
    -                dimnsion of data
    -            rnn_output (a numpy array): the training data for the neural network
    -        Formats data to be used in a recurrent neural network.
    -    """
    +

    +
    +

    +
    +

    - X, Y = [], [] - for i in range(len(data)-length_of_sequence): - # Get the next length_of_sequence elements - a = data[i:i+length_of_sequence] - # Get the element that immediately follows that - b = data[i+length_of_sequence] - # Reshape so that each data point is contained in its own array - a = np.reshape (a, (len(a), 1)) - X.append(a) - Y.append(b) - rnn_input = np.array(X) - rnn_output = np.array(Y) +

    +
    +

    +
    +

    - return rnn_input, rnn_output +

    +
    +

    +
    +

    +

    +
    +

    +
    +

    -# ## Defining the Recurrent Neural Network Using Keras -# -# The following method defines a simple recurrent neural network in keras consisting of one input layer, one hidden layer, and one output layer. +

    +
    +

    +
    +

    -def rnn(length_of_sequences, batch_size = None, stateful = False): - """ - Inputs: - length_of_sequences (an int): the number of y values in "x data". This is determined - when the data is formatted - batch_size (an int): Default value is None. See Keras documentation of SimpleRNN. - stateful (a boolean): Default value is False. See Keras documentation of SimpleRNN. - Returns: - model (a Keras model): The recurrent neural network that is built and compiled by this - method - Builds and compiles a recurrent neural network with one hidden layer and returns the model. - """ - # Number of neurons in the input and output layers - in_out_neurons = 1 - # Number of neurons in the hidden layer - hidden_neurons = 200 - # Define the input layer - inp = Input(batch_shape=(batch_size, - length_of_sequences, - in_out_neurons)) - # Define the hidden layer as a simple RNN layer with a set number of neurons and add it to - # the network immediately after the input layer - rnn = SimpleRNN(hidden_neurons, - return_sequences=False, - stateful = stateful, - name="RNN")(inp) - # Define the output layer as a dense neural network layer (standard neural network layer) - #and add it to the network immediately after the hidden layer. - dens = Dense(in_out_neurons,name="dense")(rnn) - # Create the machine learning model starting with the input layer and ending with the - # output layer - model = Model(inputs=[inp],outputs=[dens]) - # Compile the machine learning model using the mean squared error function as the loss - # function and an Adams optimizer. - model.compile(loss="mean_squared_error", optimizer="adam") - return model -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    +
    +

    +
    +

    +

    +
    +

    +
    +

    + +

    +
    +

    +
    +

    @@ -359,6 +330,8 @@ y values far removed from the training data set.

  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs023.html b/doc/pub/week45/html/._week45-bs023.html index a8f37dc40..36a9ca5f2 100644 --- a/doc/pub/week45/html/._week45-bs023.html +++ b/doc/pub/week45/html/._week45-bs023.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,7 +216,13 @@ MathJax.Hub.Config({

     

     

     

    -

    Predicting New Points With A Trained Recurrent Neural Network

    +

    An extrapolation example

    + +

    The following code provides an example of how recurrent neural +networks can be used to extrapolate to unknown values of physics data +sets. Specifically, the data sets used in this program come from +a quantum mechanical many-body calculation of energies as functions of the number of particles. +

    @@ -218,97 +231,33 @@ MathJax.Hub.Config({
    -
    def test_rnn (x1, y_test, plot_min, plot_max):
    -    """
    -        Inputs:
    -            x1 (a list or numpy array): The complete x component of the data set
    -            y_test (a list or numpy array): The complete y component of the data set
    -            plot_min (an int or float): the smallest x value used in the training data
    -            plot_max (an int or float): the largest x valye used in the training data
    -        Returns:
    -            None.
    -        Uses a trained recurrent neural network model to predict future points in the 
    -        series.  Computes the MSE of the predicted data set from the true data set, saves
    -        the predicted data set to a csv file, and plots the predicted and true data sets w
    -        while also displaying the data range used for training.
    -    """
    -    # Add the training data as the first dim points in the predicted data array as these
    -    # are known values.
    -    y_pred = y_test[:dim].tolist()
    -    # Generate the first input to the trained recurrent neural network using the last two 
    -    # points of the training data.  Based on how the network was trained this means that it
    -    # will predict the first point in the data set after the training data.  All of the 
    -    # brackets are necessary for Tensorflow.
    -    next_input = np.array([[[y_test[dim-2]], [y_test[dim-1]]]])
    -    # Save the very last point in the training data set.  This will be used later.
    -    last = [y_test[dim-1]]
    -
    -    # Iterate until the complete data set is created.
    -    for i in range (dim, len(y_test)):
    -        # Predict the next point in the data set using the previous two points.
    -        next = model.predict(next_input)
    -        # Append just the number of the predicted data set
    -        y_pred.append(next[0][0])
    -        # Create the input that will be used to predict the next data point in the data set.
    -        next_input = np.array([[last, next[0]]], dtype=np.float64)
    -        last = next
    -
    -    # Print the mean squared error between the known data set and the predicted data set.
    -    print('MSE: ', np.square(np.subtract(y_test, y_pred)).mean())
    -    # Save the predicted data set as a csv file for later use
    -    name = datatype + 'Predicted'+str(dim)+'.csv'
    -    np.savetxt(name, y_pred, delimiter=',')
    -    # Plot the known data set and the predicted data set.  The red box represents the region that was used
    -    # for the training data.
    -    fig, ax = plt.subplots()
    -    ax.plot(x1, y_test, label="true", linewidth=3)
    -    ax.plot(x1, y_pred, 'g-.',label="predicted", linewidth=4)
    -    ax.legend()
    -    # Created a red region to represent the points used in the training data.
    -    ax.axvspan(plot_min, plot_max, alpha=0.25, color='red')
    -    plt.show()
    -
    -# Check to make sure the data set is complete
    -assert len(X_tot) == len(y_tot)
    -
    -# This is the number of points that will be used in as the training data
    -dim=12
    -
    -# Separate the training data from the whole data set
    -X_train = X_tot[:dim]
    -y_train = y_tot[:dim]
    +  
    # For matrices and calculations
    +import numpy as np
    +# For machine learning (backend for keras)
    +import tensorflow as tf
    +# User-friendly machine learning library
    +# Front end for TensorFlow
    +import tensorflow.keras
    +# Different methods from Keras needed to create an RNN
    +# This is not necessary but it shortened function calls 
    +# that need to be used in the code.
    +from tensorflow.keras import datasets, layers, models
    +from tensorflow.keras.layers import Input
    +from tensorflow.keras import regularizers
    +from tensorflow.keras.models import Model, Sequential
    +from tensorflow.keras.layers import Dense, SimpleRNN, LSTM, GRU
    +# For timing the code
    +from timeit import default_timer as timer
    +# For plotting
    +import matplotlib.pyplot as plt
     
     
    -# Generate the training data for the RNN, using a sequence of 2
    -rnn_input, rnn_training = format_data(y_train, 2)
    -
    -
    -# Create a recurrent neural network in Keras and produce a summary of the 
    -# machine learning model
    -model = rnn(length_of_sequences = rnn_input.shape[1])
    -model.summary()
    -
    -# Start the timer.  Want to time training+testing
    -start = timer()
    -# Fit the model using the training data genenerated above using 150 training iterations and a 5%
    -# validation split.  Setting verbose to True prints information about each training iteration.
    -hist = model.fit(rnn_input, rnn_training, batch_size=None, epochs=150, 
    -                 verbose=True,validation_split=0.05)
    -
    -for label in ["loss","val_loss"]:
    -    plt.plot(hist.history[label],label=label)
    -
    -plt.ylabel("loss")
    -plt.xlabel("epoch")
    -plt.title("The final validation loss: {}".format(hist.history["val_loss"][-1]))
    -plt.legend()
    -plt.show()
    -
    -# Use the trained neural network to predict more points of the data set
    -test_rnn(X_tot, y_tot, X_tot[0], X_tot[dim-1])
    -# Stop the timer and calculate the total time needed.
    -end = timer()
    -print('Time: ', end-start)
    +# The data set
    +datatype='VaryDimension'
    +X_tot = np.arange(2, 42, 2)
    +y_tot = np.array([-0.03077640549, -0.08336233266, -0.1446729567, -0.2116753732, -0.2830637392, -0.3581341341, -0.436462435, -0.5177783846,
    +	-0.6019067271, -0.6887363571, -0.7782028952, -0.8702784034, -0.9649652536, -1.062292565, -1.16231451, 
    +	-1.265109911, -1.370782966, -1.479465113, -1.591317992, -1.70653767])
     
    @@ -342,6 +291,8 @@ end = timer()
  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs024.html b/doc/pub/week45/html/._week45-bs024.html index 130164759..e6ffdd17e 100644 --- a/doc/pub/week45/html/._week45-bs024.html +++ b/doc/pub/week45/html/._week45-bs024.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,20 +216,43 @@ MathJax.Hub.Config({

     

     

     

    -

    Other Things to Try

    +

    Formatting the Data

    -

    Changing the size of the recurrent neural network and its parameters -can drastically change the results you get from the model. The below -code takes the simple recurrent neural network from above and adds a -second hidden layer, changes the number of neurons in the hidden -layer, and explicitly declares the activation function of the hidden -layers to be a sigmoid function. The loss function and optimizer can -also be changed but are kept the same as the above network. These -parameters can be tuned to provide the optimal result from the -network. For some ideas on how to improve the performance of a -recurrent neural network. +

    The way the recurrent neural networks are trained in this program +differs from how machine learning algorithms are usually trained. +Typically a machine learning algorithm is trained by learning the +relationship between the x data and the y data. In this program, the +recurrent neural network will be trained to recognize the relationship +in a sequence of y values. This is type of data formatting is +typically used time series forcasting, but it can also be used in any +extrapolation (time series forecasting is just a specific type of +extrapolation along the time axis). This method of data formatting +does not use the x data and assumes that the y data are evenly spaced.

    +

    For a standard machine learning algorithm, the training data has the +form of (x,y) so the machine learning algorithm learns to assiciate a +y value with a given x value. This is useful when the test data has x +values within the same range as the training data. However, for this +application, the x values of the test data are outside of the x values +of the training data and the traditional method of training a machine +learning algorithm does not work as well. For this reason, the +recurrent neural network is trained on sequences of y values of the +form ((y1, y2), y3), so that the network is concerned with learning +the pattern of the y data and not the relation between the x and y +data. As long as the pattern of y data outside of the training region +stays relatively stable compared to what was inside the training +region, this method of training can produce accurate extrapolations to +y values far removed from the training data set. +

    + + + + + + + +
    @@ -230,7 +260,43 @@ network. For some ideas on how to improve the performance of a
    -
    def rnn_2layers(length_of_sequences, batch_size = None, stateful = False):
    +  
    # FORMAT_DATA
    +def format_data(data, length_of_sequence = 2):  
    +    """
    +        Inputs:
    +            data(a numpy array): the data that will be the inputs to the recurrent neural
    +                network
    +            length_of_sequence (an int): the number of elements in one iteration of the
    +                sequence patter.  For a function approximator use length_of_sequence = 2.
    +        Returns:
    +            rnn_input (a 3D numpy array): the input data for the recurrent neural network.  Its
    +                dimensions are length of data - length of sequence, length of sequence, 
    +                dimnsion of data
    +            rnn_output (a numpy array): the training data for the neural network
    +        Formats data to be used in a recurrent neural network.
    +    """
    +
    +    X, Y = [], []
    +    for i in range(len(data)-length_of_sequence):
    +        # Get the next length_of_sequence elements
    +        a = data[i:i+length_of_sequence]
    +        # Get the element that immediately follows that
    +        b = data[i+length_of_sequence]
    +        # Reshape so that each data point is contained in its own array
    +        a = np.reshape (a, (len(a), 1))
    +        X.append(a)
    +        Y.append(b)
    +    rnn_input = np.array(X)
    +    rnn_output = np.array(Y)
    +
    +    return rnn_input, rnn_output
    +
    +
    +# ## Defining the Recurrent Neural Network Using Keras
    +# 
    +# The following method defines a simple recurrent neural network in keras consisting of one input layer, one hidden layer, and one output layer.
    +
    +def rnn(length_of_sequences, batch_size = None, stateful = False):
         """
             Inputs:
                 length_of_sequences (an int): the number of y values in "x data".  This is determined
    @@ -240,29 +306,25 @@ network.  For some ideas on how to improve the performance of a
             Returns:
                 model (a Keras model): The recurrent neural network that is built and compiled by this
                     method
    -        Builds and compiles a recurrent neural network with two hidden layers and returns the model.
    +        Builds and compiles a recurrent neural network with one hidden layer and returns the model.
         """
         # Number of neurons in the input and output layers
         in_out_neurons = 1
    -    # Number of neurons in the hidden layer, increased from the first network
    -    hidden_neurons = 500
    +    # Number of neurons in the hidden layer
    +    hidden_neurons = 200
         # Define the input layer
         inp = Input(batch_shape=(batch_size, 
                     length_of_sequences, 
                     in_out_neurons))  
    -    # Create two hidden layers instead of one hidden layer.  Explicitly set the activation
    -    # function to be the sigmoid function (the default value is hyperbolic tangent)
    -    rnn1 = SimpleRNN(hidden_neurons, 
    -                    return_sequences=True,  # This needs to be True if another hidden layer is to follow
    -                    stateful = stateful, activation = 'sigmoid',
    -                    name="RNN1")(inp)
    -    rnn2 = SimpleRNN(hidden_neurons, 
    -                    return_sequences=False, activation = 'sigmoid',
    +    # Define the hidden layer as a simple RNN layer with a set number of neurons and add it to 
    +    # the network immediately after the input layer
    +    rnn = SimpleRNN(hidden_neurons, 
    +                    return_sequences=False,
                         stateful = stateful,
    -                    name="RNN2")(rnn1)
    +                    name="RNN")(inp)
         # Define the output layer as a dense neural network layer (standard neural network layer)
         #and add it to the network immediately after the hidden layer.
    -    dens = Dense(in_out_neurons,name="dense")(rnn2)
    +    dens = Dense(in_out_neurons,name="dense")(rnn)
         # Create the machine learning model starting with the input layer and ending with the 
         # output layer
         model = Model(inputs=[inp],outputs=[dens])
    @@ -270,52 +332,6 @@ network.  For some ideas on how to improve the performance of a
         # function and an Adams optimizer.
         model.compile(loss="mean_squared_error", optimizer="adam")  
         return model
    -
    -# Check to make sure the data set is complete
    -assert len(X_tot) == len(y_tot)
    -
    -# This is the number of points that will be used in as the training data
    -dim=12
    -
    -# Separate the training data from the whole data set
    -X_train = X_tot[:dim]
    -y_train = y_tot[:dim]
    -
    -
    -# Generate the training data for the RNN, using a sequence of 2
    -rnn_input, rnn_training = format_data(y_train, 2)
    -
    -
    -# Create a recurrent neural network in Keras and produce a summary of the 
    -# machine learning model
    -model = rnn_2layers(length_of_sequences = 2)
    -model.summary()
    -
    -# Start the timer.  Want to time training+testing
    -start = timer()
    -# Fit the model using the training data genenerated above using 150 training iterations and a 5%
    -# validation split.  Setting verbose to True prints information about each training iteration.
    -hist = model.fit(rnn_input, rnn_training, batch_size=None, epochs=150, 
    -                 verbose=True,validation_split=0.05)
    -
    -
    -# This section plots the training loss and the validation loss as a function of training iteration.
    -# This is not required for analyzing the couple cluster data but can help determine if the network is
    -# being overtrained.
    -for label in ["loss","val_loss"]:
    -    plt.plot(hist.history[label],label=label)
    -
    -plt.ylabel("loss")
    -plt.xlabel("epoch")
    -plt.title("The final validation loss: {}".format(hist.history["val_loss"][-1]))
    -plt.legend()
    -plt.show()
    -
    -# Use the trained neural network to predict more points of the data set
    -test_rnn(X_tot, y_tot, X_tot[0], X_tot[dim-1])
    -# Stop the timer and calculate the total time needed.
    -end = timer()
    -print('Time: ', end-start)
     
    @@ -348,6 +364,8 @@ end = timer()
  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs025.html b/doc/pub/week45/html/._week45-bs025.html index 68d9ea8b1..dda421683 100644 --- a/doc/pub/week45/html/._week45-bs025.html +++ b/doc/pub/week45/html/._week45-bs025.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -209,24 +216,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Other Types of Recurrent Neural Networks

    - -

    Besides a simple recurrent neural network layer, there are two other -commonly used types of recurrent neural network layers: Long Short -Term Memory (LSTM) and Gated Recurrent Unit (GRU). For a short -introduction to these layers see https://medium.com/mindboard/lstm-vs-gru-experimental-comparison-955820c21e8b -and https://medium.com/mindboard/lstm-vs-gru-experimental-comparison-955820c21e8b. -

    - -

    The first network created below is similar to the previous network, -but it replaces the SimpleRNN layers with LSTM layers. The second -network below has two hidden layers made up of GRUs, which are -preceeded by two dense (feeddorward) neural network layers. These -dense layers "preprocess" the data before it reaches the recurrent -layers. This architecture has been shown to improve the performance -of recurrent neural networks (see the link above and also -https://arxiv.org/pdf/1807.02857.pdf. -

    +

    Predicting New Points With A Trained Recurrent Neural Network

    @@ -235,83 +225,55 @@ of recurrent neural networks (see the link above and also
    -
    def lstm_2layers(length_of_sequences, batch_size = None, stateful = False):
    +  
    def test_rnn (x1, y_test, plot_min, plot_max):
         """
             Inputs:
    -            length_of_sequences (an int): the number of y values in "x data".  This is determined
    -                when the data is formatted
    -            batch_size (an int): Default value is None.  See Keras documentation of SimpleRNN.
    -            stateful (a boolean): Default value is False.  See Keras documentation of SimpleRNN.
    +            x1 (a list or numpy array): The complete x component of the data set
    +            y_test (a list or numpy array): The complete y component of the data set
    +            plot_min (an int or float): the smallest x value used in the training data
    +            plot_max (an int or float): the largest x valye used in the training data
             Returns:
    -            model (a Keras model): The recurrent neural network that is built and compiled by this
    -                method
    -        Builds and compiles a recurrent neural network with two LSTM hidden layers and returns the model.
    +            None.
    +        Uses a trained recurrent neural network model to predict future points in the 
    +        series.  Computes the MSE of the predicted data set from the true data set, saves
    +        the predicted data set to a csv file, and plots the predicted and true data sets w
    +        while also displaying the data range used for training.
         """
    -    # Number of neurons on the input/output layer and the number of neurons in the hidden layer
    -    in_out_neurons = 1
    -    hidden_neurons = 250
    -    # Input Layer
    -    inp = Input(batch_shape=(batch_size, 
    -                length_of_sequences, 
    -                in_out_neurons)) 
    -    # Hidden layers (in this case they are LSTM layers instead if SimpleRNN layers)
    -    rnn= LSTM(hidden_neurons, 
    -                    return_sequences=True,
    -                    stateful = stateful,
    -                    name="RNN", use_bias=True, activation='tanh')(inp)
    -    rnn1 = LSTM(hidden_neurons, 
    -                    return_sequences=False,
    -                    stateful = stateful,
    -                    name="RNN1", use_bias=True, activation='tanh')(rnn)
    -    # Output layer
    -    dens = Dense(in_out_neurons,name="dense")(rnn1)
    -    # Define the midel
    -    model = Model(inputs=[inp],outputs=[dens])
    -    # Compile the model
    -    model.compile(loss='mean_squared_error', optimizer='adam')  
    -    # Return the model
    -    return model
    +    # Add the training data as the first dim points in the predicted data array as these
    +    # are known values.
    +    y_pred = y_test[:dim].tolist()
    +    # Generate the first input to the trained recurrent neural network using the last two 
    +    # points of the training data.  Based on how the network was trained this means that it
    +    # will predict the first point in the data set after the training data.  All of the 
    +    # brackets are necessary for Tensorflow.
    +    next_input = np.array([[[y_test[dim-2]], [y_test[dim-1]]]])
    +    # Save the very last point in the training data set.  This will be used later.
    +    last = [y_test[dim-1]]
     
    -def dnn2_gru2(length_of_sequences, batch_size = None, stateful = False):
    -    """
    -        Inputs:
    -            length_of_sequences (an int): the number of y values in "x data".  This is determined
    -                when the data is formatted
    -            batch_size (an int): Default value is None.  See Keras documentation of SimpleRNN.
    -            stateful (a boolean): Default value is False.  See Keras documentation of SimpleRNN.
    -        Returns:
    -            model (a Keras model): The recurrent neural network that is built and compiled by this
    -                method
    -        Builds and compiles a recurrent neural network with four hidden layers (two dense followed by
    -        two GRU layers) and returns the model.
    -    """    
    -    # Number of neurons on the input/output layers and hidden layers
    -    in_out_neurons = 1
    -    hidden_neurons = 250
    -    # Input layer
    -    inp = Input(batch_shape=(batch_size, 
    -                length_of_sequences, 
    -                in_out_neurons)) 
    -    # Hidden Dense (feedforward) layers
    -    dnn = Dense(hidden_neurons/2, activation='relu', name='dnn')(inp)
    -    dnn1 = Dense(hidden_neurons/2, activation='relu', name='dnn1')(dnn)
    -    # Hidden GRU layers
    -    rnn1 = GRU(hidden_neurons, 
    -                    return_sequences=True,
    -                    stateful = stateful,
    -                    name="RNN1", use_bias=True)(dnn1)
    -    rnn = GRU(hidden_neurons, 
    -                    return_sequences=False,
    -                    stateful = stateful,
    -                    name="RNN", use_bias=True)(rnn1)
    -    # Output layer
    -    dens = Dense(in_out_neurons,name="dense")(rnn)
    -    # Define the model
    -    model = Model(inputs=[inp],outputs=[dens])
    -    # Compile the mdoel
    -    model.compile(loss='mean_squared_error', optimizer='adam')  
    -    # Return the model
    -    return model
    +    # Iterate until the complete data set is created.
    +    for i in range (dim, len(y_test)):
    +        # Predict the next point in the data set using the previous two points.
    +        next = model.predict(next_input)
    +        # Append just the number of the predicted data set
    +        y_pred.append(next[0][0])
    +        # Create the input that will be used to predict the next data point in the data set.
    +        next_input = np.array([[last, next[0]]], dtype=np.float64)
    +        last = next
    +
    +    # Print the mean squared error between the known data set and the predicted data set.
    +    print('MSE: ', np.square(np.subtract(y_test, y_pred)).mean())
    +    # Save the predicted data set as a csv file for later use
    +    name = datatype + 'Predicted'+str(dim)+'.csv'
    +    np.savetxt(name, y_pred, delimiter=',')
    +    # Plot the known data set and the predicted data set.  The red box represents the region that was used
    +    # for the training data.
    +    fig, ax = plt.subplots()
    +    ax.plot(x1, y_test, label="true", linewidth=3)
    +    ax.plot(x1, y_pred, 'g-.',label="predicted", linewidth=4)
    +    ax.legend()
    +    # Created a red region to represent the points used in the training data.
    +    ax.axvspan(plot_min, plot_max, alpha=0.25, color='red')
    +    plt.show()
     
     # Check to make sure the data set is complete
     assert len(X_tot) == len(y_tot)
    @@ -330,8 +292,7 @@ rnn_input, rnn_training = format_data(y_trai
     
     # Create a recurrent neural network in Keras and produce a summary of the 
     # machine learning model
    -# Change the method name to reflect which network you want to use
    -model = dnn2_gru2(length_of_sequences = 2)
    +model = rnn(length_of_sequences = rnn_input.shape[1])
     model.summary()
     
     # Start the timer.  Want to time training+testing
    @@ -341,10 +302,6 @@ start = timer()
     hist = model.fit(rnn_input, rnn_training, batch_size=None, epochs=150, 
                      verbose=True,validation_split=0.05)
     
    -
    -# This section plots the training loss and the validation loss as a function of training iteration.
    -# This is not required for analyzing the couple cluster data but can help determine if the network is
    -# being overtrained.
     for label in ["loss","val_loss"]:
         plt.plot(hist.history[label],label=label)
     
    @@ -359,72 +316,6 @@ test_rnn(X_tot, y_tot, X_tot[0], X_tot[dim# Stop the timer and calculate the total time needed.
     end = timer()
     print('Time: ', end-start)
    -
    -
    -# ### Training Recurrent Neural Networks in the Standard Way (i.e. learning the relationship between the X and Y data)
    -# 
    -# Finally, comparing the performace of a recurrent neural network using the standard data formatting to the performance of the network with time sequence data formatting shows the benefit of this type of data formatting with extrapolation.
    -
    -# Check to make sure the data set is complete
    -assert len(X_tot) == len(y_tot)
    -
    -# This is the number of points that will be used in as the training data
    -dim=12
    -
    -# Separate the training data from the whole data set
    -X_train = X_tot[:dim]
    -y_train = y_tot[:dim]
    -
    -# Reshape the data for Keras specifications
    -X_train = X_train.reshape((dim, 1))
    -y_train = y_train.reshape((dim, 1))
    -
    -
    -# Create a recurrent neural network in Keras and produce a summary of the 
    -# machine learning model
    -# Set the sequence length to 1 for regular data formatting 
    -model = rnn(length_of_sequences = 1)
    -model.summary()
    -
    -# Start the timer.  Want to time training+testing
    -start = timer()
    -# Fit the model using the training data genenerated above using 150 training iterations and a 5%
    -# validation split.  Setting verbose to True prints information about each training iteration.
    -hist = model.fit(X_train, y_train, batch_size=None, epochs=150, 
    -                 verbose=True,validation_split=0.05)
    -
    -
    -# This section plots the training loss and the validation loss as a function of training iteration.
    -# This is not required for analyzing the couple cluster data but can help determine if the network is
    -# being overtrained.
    -for label in ["loss","val_loss"]:
    -    plt.plot(hist.history[label],label=label)
    -
    -plt.ylabel("loss")
    -plt.xlabel("epoch")
    -plt.title("The final validation loss: {}".format(hist.history["val_loss"][-1]))
    -plt.legend()
    -plt.show()
    -
    -# Use the trained neural network to predict the remaining data points
    -X_pred = X_tot[dim:]
    -X_pred = X_pred.reshape((len(X_pred), 1))
    -y_model = model.predict(X_pred)
    -y_pred = np.concatenate((y_tot[:dim], y_model.flatten()))
    -
    -# Plot the known data set and the predicted data set.  The red box represents the region that was used
    -# for the training data.
    -fig, ax = plt.subplots()
    -ax.plot(X_tot, y_tot, label="true", linewidth=3)
    -ax.plot(X_tot, y_pred, 'g-.',label="predicted", linewidth=4)
    -ax.legend()
    -# Created a red region to represent the points used in the training data.
    -ax.axvspan(X_tot[0], X_tot[dim], alpha=0.25, color='red')
    -plt.show()
    -
    -# Stop the timer and calculate the total time needed.
    -end = timer()
    -print('Time: ', end-start)
     
    @@ -456,6 +347,9 @@ end = timer()
  • 24
  • 25
  • 26
  • +
  • 27
  • +
  • 28
  • +
  • »
  • diff --git a/doc/pub/week45/html/._week45-bs026.html b/doc/pub/week45/html/._week45-bs026.html index 24b578f84..1be0c77b5 100644 --- a/doc/pub/week45/html/._week45-bs026.html +++ b/doc/pub/week45/html/._week45-bs026.html @@ -8,8 +8,8 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d - -Week 45: Decisions Trees, Random Forests, Bagging and Boosting + +Week 45, Recurrent Neural Networks @@ -36,109 +36,106 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d @@ -166,52 +163,48 @@ MathJax.Hub.Config({ - Week 45: Decisions Trees, Random Forests, Bagging and Boosting + Week 45, Recurrent Neural Networks
    diff --git a/doc/pub/week45/html/week45-bs.html b/doc/pub/week45/html/week45-bs.html index fe1e65103..877c6bf0c 100644 --- a/doc/pub/week45/html/week45-bs.html +++ b/doc/pub/week45/html/week45-bs.html @@ -65,6 +65,11 @@ doconce format html week45.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -175,29 +180,31 @@ MathJax.Hub.Config({
  • Discussing the correlation data
  • Other ways of presenting a classification problem
  • Combinations of classification results
  • -
  • \( F_1 \) score
  • -
  • ROC curve
  • -
  • Cumulative gain curve
  • -
  • Other measures in classification studies: Cancer Data again
  • -
  • Material for Lecture Thursday November 9
  • -
  • Recurrent neural networks (RNNs): Overarching view
  • -
  • A simple example
  • -
  •    RNNs
  • -
  • Basic layout
  • -
  •    We need to specify the initial activity state of all the hidden and output units
  • -
  •    We can specify inputs in several ways
  • -
  •    We can specify targets in several ways
  • -
  •    Backpropagation through time
  • -
  •    The backward pass is linear
  • -
  • The problem of exploding or vanishing gradients
  • -
  • Four effective ways to learn an RNN
  • -
  •    Long Short Term Memory (LSTM)
  • -
  •    Implementing a memory cell in a neural network
  • -
  • An extrapolation example
  • -
  • Formatting the Data
  • -
  • Predicting New Points With A Trained Recurrent Neural Network
  • -
  • Other Things to Try
  • -
  • Other Types of Recurrent Neural Networks
  • +
  • Positive and negative prediction values
  • +
  • Other quantities
  • +
  • \( F_1 \) score
  • +
  • ROC curve
  • +
  • Cumulative gain curve
  • +
  • Other measures in classification studies: Cancer Data again
  • +
  • Material for Lecture Thursday November 9
  • +
  • Recurrent neural networks (RNNs): Overarching view
  • +
  • A simple example
  • +
  •    RNNs
  • +
  • Basic layout
  • +
  •    We need to specify the initial activity state of all the hidden and output units
  • +
  •    We can specify inputs in several ways
  • +
  •    We can specify targets in several ways
  • +
  •    Backpropagation through time
  • +
  •    The backward pass is linear
  • +
  • The problem of exploding or vanishing gradients
  • +
  • Four effective ways to learn an RNN
  • +
  •    Long Short Term Memory (LSTM)
  • +
  •    Implementing a memory cell in a neural network
  • +
  • An extrapolation example
  • +
  • Formatting the Data
  • +
  • Predicting New Points With A Trained Recurrent Neural Network
  • +
  • Other Things to Try
  • +
  • Other Types of Recurrent Neural Networks
  • @@ -252,7 +259,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 26
  • +
  • 28
  • »
  • diff --git a/doc/pub/week45/html/week45-reveal.html b/doc/pub/week45/html/week45-reveal.html index 73400306d..a108bc9f4 100644 --- a/doc/pub/week45/html/week45-reveal.html +++ b/doc/pub/week45/html/week45-reveal.html @@ -686,6 +686,14 @@ The following quantities are then used

  • The false positive \( FP \) number, a so-called type I error which tells us about the fraction of positive test result which are wrongly classified
  • A false negative \( FN \) number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified.
  • +

    +

    It is is easy to think in terms of illness. You could think of the above as

    +
      +

    1. True positive: Sick people correctly identified as sick
    2. +

    3. False positive: Healthy people incorrectly identified as sick
    4. +

    5. True negative: Healthy people correctly identified as healthy
    6. +

    7. False negative: Sick people incorrectly identified as healthy
    8. +
    @@ -694,7 +702,7 @@ The following quantities are then used

    It is common in the literature to define various combinations the above numbers. The most commonly used are

    -Sensitivity, recall, hit rate, or true positive rate \( TPR \) +Sensitivity, recall, hit rate, or true positive rate \( TPR \). It is the probability of a positive test result, conditioned on the individual truly being positive.

     
    $$ @@ -703,9 +711,21 @@ $$

     

    +

    The \( TPR \) defines how many correct positive results occur among all positive samples available during the test

    -Specificity, selectivity or true negative rate \( TNR \) +Miss rate or false negative rate \( FNR \) +

    +

     
    +$$ +{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } +$$ +

     
    +

    + + +
    +Specificity, selectivity or true negative rate \( TNR \). It is the probability of a negative test result, conditioned on the individual truly being negative.

     
    $$ @@ -721,9 +741,24 @@ $$

     

    +

    The \( FPR \) defines how many incorrect positive results occur among +all negative samples available during the test. +

    +
    + +
    +

    Positive and negative prediction values

    + +

    The positive and negative predictive values +are the proportions of positive and negative results in statistics and +diagnostic tests that are true positive and true negative results, +respectively.[1] The PPV and NPV describe the performance of a +diagnostic test or other statistical measure. A high result can be +interpreted as indicating the accuracy of such a statistic. +

    -Precision or positive predictive value \( PPV \) +Precision or positive predictive value \( PPV \).

     
    $$ @@ -742,18 +777,10 @@ $$ $$

     

    +
    - -
    -Miss rate or false negative rate \( FNR \) -

    -

     
    -$$ -{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } -$$ -

     
    -

    - +
    +

    Other quantities

    False discovery rate \( FDR \) @@ -814,9 +841,17 @@ graphical plot that illustrates the performance of a binary classifier model at varying threshold values.

    -

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting. -See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions. +

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting.

    + +

    To draw a ROC curve, only the true positive rate (TPR) and false +positive rate (FPR) are needed (as functions of some classifier +parameter). The TPR defines how many correct positive results occur +among all positive samples available during the test. FPR, on the +other hand, defines how many incorrect positive results occur among +all negative samples available during the test.

    + +

    See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions.

    @@ -828,6 +863,8 @@ fraction of examples correctly classified against Predictive Positive Rate, which represents the fraction of positively predicted examples.

    + +

    The examples below show the confusion matrix, the ROC curve and the cumulative gain for the Wisconsin cancer data.

    diff --git a/doc/pub/week45/html/week45-solarized.html b/doc/pub/week45/html/week45-solarized.html index 7485be53a..baea49690 100644 --- a/doc/pub/week45/html/week45-solarized.html +++ b/doc/pub/week45/html/week45-solarized.html @@ -92,6 +92,11 @@ div.toc p,a { 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -673,22 +678,39 @@ The following quantities are then used
  • The false positive \( FP \) number, a so-called type I error which tells us about the fraction of positive test result which are wrongly classified
  • A false negative \( FN \) number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified.
  • +

    It is is easy to think in terms of illness. You could think of the above as

    +
      +
    1. True positive: Sick people correctly identified as sick
    2. +
    3. False positive: Healthy people incorrectly identified as sick
    4. +
    5. True negative: Healthy people correctly identified as healthy
    6. +
    7. False negative: Sick people incorrectly identified as healthy
    8. +










    Combinations of classification results

    It is common in the literature to define various combinations the above numbers. The most commonly used are

    -Sensitivity, recall, hit rate, or true positive rate \( TPR \) +Sensitivity, recall, hit rate, or true positive rate \( TPR \). It is the probability of a positive test result, conditioned on the individual truly being positive.

    $$ {\displaystyle \mathrm {TPR} ={\frac {\mathrm {TP} }{\mathrm {P} }}={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FN} }}=1-\mathrm {FNR} } $$

    +

    The \( TPR \) defines how many correct positive results occur among all positive samples available during the test

    -Specificity, selectivity or true negative rate \( TNR \) +Miss rate or false negative rate \( FNR \) +

    +$$ +{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } +$$ +

    + + +
    +Specificity, selectivity or true negative rate \( TNR \). It is the probability of a negative test result, conditioned on the individual truly being negative.

    $$ {\displaystyle \mathrm {TNR} ={\frac {\mathrm {TN} }{\mathrm {N} }}={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FP} }}=1-\mathrm {FPR} } @@ -700,9 +722,23 @@ $$ $$

    +

    The \( FPR \) defines how many incorrect positive results occur among +all negative samples available during the test. +

    + +









    +

    Positive and negative prediction values

    + +

    The positive and negative predictive values +are the proportions of positive and negative results in statistics and +diagnostic tests that are true positive and true negative results, +respectively.[1] The PPV and NPV describe the performance of a +diagnostic test or other statistical measure. A high result can be +interpreted as indicating the accuracy of such a statistic. +

    -Precision or positive predictive value \( PPV \) +Precision or positive predictive value \( PPV \).

    $$ {\displaystyle \mathrm {PPV} ={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FP} }}=1-\mathrm {FDR} } @@ -719,14 +755,8 @@ $$

    -
    -Miss rate or false negative rate \( FNR \) -

    -$$ -{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } -$$ -

    - +









    +

    Other quantities

    False discovery rate \( FDR \) @@ -781,10 +811,18 @@ graphical plot that illustrates the performance of a binary classifier model at varying threshold values.

    -

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting. -See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions. +

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting.

    + +

    To draw a ROC curve, only the true positive rate (TPR) and false +positive rate (FPR) are needed (as functions of some classifier +parameter). The TPR defines how many correct positive results occur +among all positive samples available during the test. FPR, on the +other hand, defines how many incorrect positive results occur among +all negative samples available during the test.

    +

    See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions.

    +









    Cumulative gain curve

    @@ -795,6 +833,8 @@ against Predictive Positive Rate, which represents the fraction of positively predicted examples.

    +

    The examples below show the confusion matrix, the ROC curve and the cumulative gain for the Wisconsin cancer data.

    +









    Other measures in classification studies: Cancer Data again

    diff --git a/doc/pub/week45/html/week45.html b/doc/pub/week45/html/week45.html index 3ee0069b9..09831185b 100644 --- a/doc/pub/week45/html/week45.html +++ b/doc/pub/week45/html/week45.html @@ -169,6 +169,11 @@ div.toc p,a { 2, None, 'combinations-of-classification-results'), + ('Positive and negative prediction values', + 2, + None, + 'positive-and-negative-prediction-values'), + ('Other quantities', 2, None, 'other-quantities'), ('$F_1$ score', 2, None, 'f-1-score'), ('ROC curve', 2, None, 'roc-curve'), ('Cumulative gain curve', 2, None, 'cumulative-gain-curve'), @@ -750,22 +755,39 @@ The following quantities are then used
  • The false positive \( FP \) number, a so-called type I error which tells us about the fraction of positive test result which are wrongly classified
  • A false negative \( FN \) number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified.
  • +

    It is is easy to think in terms of illness. You could think of the above as

    +
      +
    1. True positive: Sick people correctly identified as sick
    2. +
    3. False positive: Healthy people incorrectly identified as sick
    4. +
    5. True negative: Healthy people correctly identified as healthy
    6. +
    7. False negative: Sick people incorrectly identified as healthy
    8. +










    Combinations of classification results

    It is common in the literature to define various combinations the above numbers. The most commonly used are

    -Sensitivity, recall, hit rate, or true positive rate \( TPR \) +Sensitivity, recall, hit rate, or true positive rate \( TPR \). It is the probability of a positive test result, conditioned on the individual truly being positive.

    $$ {\displaystyle \mathrm {TPR} ={\frac {\mathrm {TP} }{\mathrm {P} }}={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FN} }}=1-\mathrm {FNR} } $$

    +

    The \( TPR \) defines how many correct positive results occur among all positive samples available during the test

    -Specificity, selectivity or true negative rate \( TNR \) +Miss rate or false negative rate \( FNR \) +

    +$$ +{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } +$$ +

    + + +
    +Specificity, selectivity or true negative rate \( TNR \). It is the probability of a negative test result, conditioned on the individual truly being negative.

    $$ {\displaystyle \mathrm {TNR} ={\frac {\mathrm {TN} }{\mathrm {N} }}={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FP} }}=1-\mathrm {FPR} } @@ -777,9 +799,23 @@ $$ $$

    +

    The \( FPR \) defines how many incorrect positive results occur among +all negative samples available during the test. +

    + +









    +

    Positive and negative prediction values

    + +

    The positive and negative predictive values +are the proportions of positive and negative results in statistics and +diagnostic tests that are true positive and true negative results, +respectively.[1] The PPV and NPV describe the performance of a +diagnostic test or other statistical measure. A high result can be +interpreted as indicating the accuracy of such a statistic. +

    -Precision or positive predictive value \( PPV \) +Precision or positive predictive value \( PPV \).

    $$ {\displaystyle \mathrm {PPV} ={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FP} }}=1-\mathrm {FDR} } @@ -796,14 +832,8 @@ $$

    -
    -Miss rate or false negative rate \( FNR \) -

    -$$ -{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } -$$ -

    - +









    +

    Other quantities

    False discovery rate \( FDR \) @@ -858,10 +888,18 @@ graphical plot that illustrates the performance of a binary classifier model at varying threshold values.

    -

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting. -See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions. +

    The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting.

    + +

    To draw a ROC curve, only the true positive rate (TPR) and false +positive rate (FPR) are needed (as functions of some classifier +parameter). The TPR defines how many correct positive results occur +among all positive samples available during the test. FPR, on the +other hand, defines how many incorrect positive results occur among +all negative samples available during the test.

    +

    See https://en.wikipedia.org/wiki/Receiver_operating_characteristic for more discussions.

    +









    Cumulative gain curve

    @@ -872,6 +910,8 @@ against Predictive Positive Rate, which represents the fraction of positively predicted examples.

    +

    The examples below show the confusion matrix, the ROC curve and the cumulative gain for the Wisconsin cancer data.

    +









    Other measures in classification studies: Cancer Data again

    diff --git a/doc/pub/week45/ipynb/ipynb-week45-src.tar.gz b/doc/pub/week45/ipynb/ipynb-week45-src.tar.gz index d8fb40c3183ea55e0858af2103ad744cdd76e43f..7ed5ad76fa8f0ee333ffa21b54d9bcdfbd616f55 100644 GIT binary patch delta 295 zcmWN_$07m%0Dxh_UuH%2s1RC4_Kqmovd1fU2#5c|^LQF}r!L+=hwt*$fBpjX2I60# zrqARD(kuaKkydGw#snoK?b0Eg(k0!}BVmb1RC=XPV$v@IGAKhbEF&^1V=^ui5|@M| zWm2YOT2eA2voa@X$w*dml9zc|kVRRNf-K95tje0K%Z6;qmTb$8?8=_(OHmHwP)c$n q$5NJxoJdtpuH{B*aw~UoFAwr4Px34;^7_r&@B2R(=u3gjuT4` diff --git a/doc/pub/week45/ipynb/week45.ipynb b/doc/pub/week45/ipynb/week45.ipynb index 9159c52e4..749491e98 100644 --- a/doc/pub/week45/ipynb/week45.ipynb +++ b/doc/pub/week45/ipynb/week45.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "a91a3cf4", + "id": "31a10e2b", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "8db3e881", + "id": "019daa83", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "3ed14c36", + "id": "6ecf1c2b", "metadata": { "editable": true }, @@ -67,7 +67,7 @@ }, { "cell_type": "markdown", - "id": "71c9e4bb", + "id": "d80a4db8", "metadata": { "editable": true }, @@ -77,7 +77,7 @@ }, { "cell_type": "markdown", - "id": "3f775bfb", + "id": "1ded5c92", "metadata": { "editable": true }, @@ -96,7 +96,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "bdebe955", + "id": "6dea0513", "metadata": { "collapsed": false, "editable": true @@ -153,7 +153,7 @@ }, { "cell_type": "markdown", - "id": "82392abb", + "id": "440bf579", "metadata": { "editable": true }, @@ -165,7 +165,7 @@ }, { "cell_type": "markdown", - "id": "9bd30237", + "id": "683b1da2", "metadata": { "editable": true }, @@ -180,7 +180,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "ca525d79", + "id": "38be79e0", "metadata": { "collapsed": false, "editable": true @@ -233,7 +233,7 @@ }, { "cell_type": "markdown", - "id": "4891694c", + "id": "081fbe5c", "metadata": { "editable": true }, @@ -248,7 +248,7 @@ }, { "cell_type": "markdown", - "id": "d021327b", + "id": "a9798c07", "metadata": { "editable": true }, @@ -268,7 +268,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "536e718c", + "id": "0a7e4e2e", "metadata": { "collapsed": false, "editable": true @@ -322,7 +322,7 @@ }, { "cell_type": "markdown", - "id": "037b80bd", + "id": "dcd07cb8", "metadata": { "editable": true }, @@ -337,7 +337,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "e705152f", + "id": "65061d95", "metadata": { "collapsed": false, "editable": true @@ -364,7 +364,7 @@ }, { "cell_type": "markdown", - "id": "b0ebbcc5", + "id": "50492453", "metadata": { "editable": true }, @@ -378,7 +378,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "e773c60c", + "id": "08a2ab17", "metadata": { "collapsed": false, "editable": true @@ -423,7 +423,7 @@ }, { "cell_type": "markdown", - "id": "6404bcfd", + "id": "5408b7dd", "metadata": { "editable": true }, @@ -448,7 +448,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "8b7a1596", + "id": "76c3d259", "metadata": { "collapsed": false, "editable": true @@ -460,7 +460,7 @@ }, { "cell_type": "markdown", - "id": "6427270d", + "id": "83903231", "metadata": { "editable": true }, @@ -471,7 +471,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "0123027c", + "id": "58ccd6c3", "metadata": { "collapsed": false, "editable": true @@ -483,7 +483,7 @@ }, { "cell_type": "markdown", - "id": "977f2e06", + "id": "adda54cb", "metadata": { "editable": true }, @@ -496,7 +496,7 @@ }, { "cell_type": "markdown", - "id": "e1eb90fb", + "id": "8799c034", "metadata": { "editable": true }, @@ -515,12 +515,21 @@ "\n", "5. The false positive $FP$ number, a so-called type I error which tells us about the fraction of positive test result which are wrongly classified\n", "\n", - "6. A false negative $FN$ number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified." + "6. A false negative $FN$ number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified.\n", + "\n", + "It is is easy to think in terms of illness. You could think of the above as\n", + "1. True positive: Sick people correctly identified as sick\n", + "\n", + "2. False positive: Healthy people incorrectly identified as sick\n", + "\n", + "3. True negative: Healthy people correctly identified as healthy\n", + "\n", + "4. False negative: Sick people incorrectly identified as healthy" ] }, { "cell_type": "markdown", - "id": "b67ce142", + "id": "dfbe0571", "metadata": { "editable": true }, @@ -529,12 +538,12 @@ "\n", "It is common in the literature to define various combinations the above numbers. The most commonly used are\n", "\n", - "**Sensitivity, recall, hit rate, or true positive rate $TPR$.**" + "**Sensitivity, recall, hit rate, or true positive rate $TPR$. It is the probability of a positive test result, conditioned on the individual truly being positive.**" ] }, { "cell_type": "markdown", - "id": "4d0d5574", + "id": "65f7c63d", "metadata": { "editable": true }, @@ -546,105 +555,19 @@ }, { "cell_type": "markdown", - "id": "4e08a900", - "metadata": { - "editable": true - }, - "source": [ - "**Specificity, selectivity or true negative rate $TNR$.**" - ] - }, - { - "cell_type": "markdown", - "id": "120a6d17", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\displaystyle \\mathrm {TNR} ={\\frac {\\mathrm {TN} }{\\mathrm {N} }}={\\frac {\\mathrm {TN} }{\\mathrm {TN} +\\mathrm {FP} }}=1-\\mathrm {FPR} }\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7d54b7e1", - "metadata": { - "editable": true - }, - "source": [ - "with the fall-out false positive rate" - ] - }, - { - "cell_type": "markdown", - "id": "8e023421", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\displaystyle \\mathrm {FPR} ={\\frac {\\mathrm {FP} }{\\mathrm {N} }}={\\frac {\\mathrm {FP} }{\\mathrm {FP} +\\mathrm {TN} }}=1-\\mathrm {TNR} }\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "50944d13", - "metadata": { - "editable": true - }, - "source": [ - "**Precision or positive predictive value $PPV$.**" - ] - }, - { - "cell_type": "markdown", - "id": "e7c3c9ec", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\displaystyle \\mathrm {PPV} ={\\frac {\\mathrm {TP} }{\\mathrm {TP} +\\mathrm {FP} }}=1-\\mathrm {FDR} }\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "fa44b1f6", - "metadata": { - "editable": true - }, - "source": [ - "**Negative predictive value $NPV$.**" - ] - }, - { - "cell_type": "markdown", - "id": "fd300015", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\displaystyle \\mathrm {NPV} ={\\frac {\\mathrm {TN} }{\\mathrm {TN} +\\mathrm {FN} }}=1-\\mathrm {FOR} }\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "84c23174", + "id": "2e674d10", "metadata": { "editable": true }, "source": [ + "The $TPR$ defines how many correct positive results occur among all positive samples available during the test\n", + "\n", "**Miss rate or false negative rate $FNR$.**" ] }, { "cell_type": "markdown", - "id": "755d63a6", + "id": "65577837", "metadata": { "editable": true }, @@ -656,17 +579,127 @@ }, { "cell_type": "markdown", - "id": "d0710790", + "id": "e5e8802d", "metadata": { "editable": true }, "source": [ + "**Specificity, selectivity or true negative rate $TNR$. It is the probability of a negative test result, conditioned on the individual truly being negative.**" + ] + }, + { + "cell_type": "markdown", + "id": "07c61591", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\displaystyle \\mathrm {TNR} ={\\frac {\\mathrm {TN} }{\\mathrm {N} }}={\\frac {\\mathrm {TN} }{\\mathrm {TN} +\\mathrm {FP} }}=1-\\mathrm {FPR} }\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b3f61bb3", + "metadata": { + "editable": true + }, + "source": [ + "with the fall-out false positive rate" + ] + }, + { + "cell_type": "markdown", + "id": "6544105e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\displaystyle \\mathrm {FPR} ={\\frac {\\mathrm {FP} }{\\mathrm {N} }}={\\frac {\\mathrm {FP} }{\\mathrm {FP} +\\mathrm {TN} }}=1-\\mathrm {TNR} }\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0b571e85", + "metadata": { + "editable": true + }, + "source": [ + "The $FPR$ defines how many incorrect positive results occur among\n", + "all negative samples available during the test." + ] + }, + { + "cell_type": "markdown", + "id": "17d6872a", + "metadata": { + "editable": true + }, + "source": [ + "## Positive and negative prediction values\n", + "\n", + "The positive and negative predictive values \n", + "are the proportions of positive and negative results in statistics and\n", + "diagnostic tests that are true positive and true negative results,\n", + "respectively.[1] The PPV and NPV describe the performance of a\n", + "diagnostic test or other statistical measure. A high result can be\n", + "interpreted as indicating the accuracy of such a statistic.\n", + "\n", + "**Precision or positive predictive value $PPV$.**" + ] + }, + { + "cell_type": "markdown", + "id": "122f7e6c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\displaystyle \\mathrm {PPV} ={\\frac {\\mathrm {TP} }{\\mathrm {TP} +\\mathrm {FP} }}=1-\\mathrm {FDR} }\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f44a5e78", + "metadata": { + "editable": true + }, + "source": [ + "**Negative predictive value $NPV$.**" + ] + }, + { + "cell_type": "markdown", + "id": "86fa9670", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\displaystyle \\mathrm {NPV} ={\\frac {\\mathrm {TN} }{\\mathrm {TN} +\\mathrm {FN} }}=1-\\mathrm {FOR} }\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a30e358d", + "metadata": { + "editable": true + }, + "source": [ + "## Other quantities\n", + "\n", "**False discovery rate $FDR$.**" ] }, { "cell_type": "markdown", - "id": "41eec12a", + "id": "3f0de6de", "metadata": { "editable": true }, @@ -678,7 +711,7 @@ }, { "cell_type": "markdown", - "id": "6b24bd9c", + "id": "0b4cc93f", "metadata": { "editable": true }, @@ -688,7 +721,7 @@ }, { "cell_type": "markdown", - "id": "928a7525", + "id": "4866ec0a", "metadata": { "editable": true }, @@ -700,7 +733,7 @@ }, { "cell_type": "markdown", - "id": "a063439d", + "id": "9b1c8c45", "metadata": { "editable": true }, @@ -728,7 +761,7 @@ }, { "cell_type": "markdown", - "id": "e56aed6a", + "id": "0e651a1f", "metadata": { "editable": true }, @@ -740,7 +773,7 @@ }, { "cell_type": "markdown", - "id": "52bd5f13", + "id": "d83efe41", "metadata": { "editable": true }, @@ -752,12 +785,20 @@ "model at varying threshold values.\n", "\n", "The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting.\n", + "\n", + "To draw a ROC curve, only the true positive rate (TPR) and false\n", + "positive rate (FPR) are needed (as functions of some classifier\n", + "parameter). The TPR defines how many correct positive results occur\n", + "among all positive samples available during the test. FPR, on the\n", + "other hand, defines how many incorrect positive results occur among\n", + "all negative samples available during the test.\n", + "\n", "See for more discussions." ] }, { "cell_type": "markdown", - "id": "034337bf", + "id": "d088215b", "metadata": { "editable": true }, @@ -768,12 +809,14 @@ "It plots the $TPR$ True Positive Rate or Sensitivity (which represents the \n", "fraction of examples correctly classified\n", "against Predictive Positive Rate, which represents \n", - "the fraction of positively predicted examples." + "the fraction of positively predicted examples.\n", + "\n", + "The examples below show the confusion matrix, the ROC curve and the cumulative gain for the Wisconsin cancer data." ] }, { "cell_type": "markdown", - "id": "24c88fd3", + "id": "5c0bcd1f", "metadata": { "editable": true }, @@ -784,7 +827,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "f3b6a9a4", + "id": "2a6f80df", "metadata": { "collapsed": false, "editable": true @@ -827,7 +870,7 @@ }, { "cell_type": "markdown", - "id": "40b53cc8", + "id": "58e5b521", "metadata": { "editable": true }, @@ -837,7 +880,7 @@ }, { "cell_type": "markdown", - "id": "24428775", + "id": "4ebe5a91", "metadata": { "editable": true }, @@ -864,7 +907,7 @@ }, { "cell_type": "markdown", - "id": "6969ac06", + "id": "182f425e", "metadata": { "editable": true }, @@ -875,7 +918,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "d4d64be1", + "id": "8b3ca785", "metadata": { "collapsed": false, "editable": true @@ -948,7 +991,7 @@ }, { "cell_type": "markdown", - "id": "249554fa", + "id": "b0c12b4c", "metadata": { "editable": true }, @@ -968,7 +1011,7 @@ }, { "cell_type": "markdown", - "id": "da3a2e68", + "id": "d81020f6", "metadata": { "editable": true }, @@ -984,7 +1027,7 @@ }, { "cell_type": "markdown", - "id": "b2123e31", + "id": "2d7453c9", "metadata": { "editable": true }, @@ -1006,7 +1049,7 @@ }, { "cell_type": "markdown", - "id": "c2ad84e7", + "id": "fc4a082e", "metadata": { "editable": true }, @@ -1024,7 +1067,7 @@ }, { "cell_type": "markdown", - "id": "4089e1e8", + "id": "c1106ad9", "metadata": { "editable": true }, @@ -1070,7 +1113,7 @@ }, { "cell_type": "markdown", - "id": "94d331a7", + "id": "b139ef7b", "metadata": { "editable": true }, @@ -1091,7 +1134,7 @@ }, { "cell_type": "markdown", - "id": "af7ba6cb", + "id": "70c95078", "metadata": { "editable": true }, @@ -1152,7 +1195,7 @@ }, { "cell_type": "markdown", - "id": "f12cba0f", + "id": "2ca24031", "metadata": { "editable": true }, @@ -1177,7 +1220,7 @@ }, { "cell_type": "markdown", - "id": "7024d34f", + "id": "93648979", "metadata": { "editable": true }, @@ -1196,7 +1239,7 @@ }, { "cell_type": "markdown", - "id": "a763b476", + "id": "b8806dcd", "metadata": { "editable": true }, @@ -1220,7 +1263,7 @@ }, { "cell_type": "markdown", - "id": "fcfad15d", + "id": "b0edad40", "metadata": { "editable": true }, @@ -1302,7 +1345,7 @@ }, { "cell_type": "markdown", - "id": "8f72cf10", + "id": "58fd18f9", "metadata": { "editable": true }, @@ -1318,7 +1361,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "c8e3fc7d", + "id": "a604caa5", "metadata": { "collapsed": false, "editable": true @@ -1357,7 +1400,7 @@ }, { "cell_type": "markdown", - "id": "934633d8", + "id": "545336c9", "metadata": { "editable": true }, @@ -1401,7 +1444,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "726fb72d", + "id": "3ef3ed13", "metadata": { "collapsed": false, "editable": true @@ -1484,7 +1527,7 @@ }, { "cell_type": "markdown", - "id": "17b2d211", + "id": "8a8b29b8", "metadata": { "editable": true }, @@ -1495,7 +1538,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "242b2375", + "id": "d840beea", "metadata": { "collapsed": false, "editable": true @@ -1597,7 +1640,7 @@ }, { "cell_type": "markdown", - "id": "59fa6d43", + "id": "2e5b339f", "metadata": { "editable": true }, @@ -1619,7 +1662,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "cf53a4e5", + "id": "370e799d", "metadata": { "collapsed": false, "editable": true @@ -1716,7 +1759,7 @@ }, { "cell_type": "markdown", - "id": "4ea80824", + "id": "d8f62fc4", "metadata": { "editable": true }, @@ -1742,7 +1785,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "7ac7f0fd", + "id": "4ea36ea9", "metadata": { "collapsed": false, "editable": true diff --git a/doc/src/week45/week45.do.txt b/doc/src/week45/week45.do.txt index 8e64774c2..497807c99 100644 --- a/doc/src/week45/week45.do.txt +++ b/doc/src/week45/week45.do.txt @@ -329,21 +329,38 @@ o The true negative $TN$ number which represents whether a negative test has bee o The false positive $FP$ number, a so-called type I error which tells us about the fraction of positive test result which are wrongly classified o A false negative $FN$ number, a so-called type II error which, should be pretty obvious, indicates if a negative test has been wrongly classified. +It is is easy to think in terms of illness. You could think of the above as +o True positive: Sick people correctly identified as sick +o False positive: Healthy people incorrectly identified as sick +o True negative: Healthy people correctly identified as healthy +o False negative: Sick people incorrectly identified as healthy !split ===== Combinations of classification results ===== It is common in the literature to define various combinations the above numbers. The most commonly used are -!bblock Sensitivity, recall, hit rate, or true positive rate $TPR$ +!bblock Sensitivity, recall, hit rate, or true positive rate $TPR$. It is the probability of a positive test result, conditioned on the individual truly being positive. !bt \[ {\displaystyle \mathrm {TPR} ={\frac {\mathrm {TP} }{\mathrm {P} }}={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FN} }}=1-\mathrm {FNR} } \] !et !eblock +The $TPR$ defines how many correct positive results occur among all positive samples available during the test -!bblock Specificity, selectivity or true negative rate $TNR$ + +!bblock Miss rate or false negative rate $FNR$ +!bt +\[ +{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } +\] +!et +!eblock + + + +!bblock Specificity, selectivity or true negative rate $TNR$. It is the probability of a negative test result, conditioned on the individual truly being negative. !bt \[ {\displaystyle \mathrm {TNR} ={\frac {\mathrm {TN} }{\mathrm {N} }}={\frac {\mathrm {TN} }{\mathrm {TN} +\mathrm {FP} }}=1-\mathrm {FPR} } @@ -356,8 +373,21 @@ with the fall-out false positive rate \] !et !eblock +The $FPR$ defines how many incorrect positive results occur among +all negative samples available during the test. -!bblock Precision or positive predictive value $PPV$ +!split +===== Positive and negative prediction values ===== + +The positive and negative predictive values +are the proportions of positive and negative results in statistics and +diagnostic tests that are true positive and true negative results, +respectively.[1] The PPV and NPV describe the performance of a +diagnostic test or other statistical measure. A high result can be +interpreted as indicating the accuracy of such a statistic. + + +!bblock Precision or positive predictive value $PPV$. !bt \[ {\displaystyle \mathrm {PPV} ={\frac {\mathrm {TP} }{\mathrm {TP} +\mathrm {FP} }}=1-\mathrm {FDR} } @@ -374,13 +404,9 @@ with the fall-out false positive rate !eblock -!bblock Miss rate or false negative rate $FNR$ -!bt -\[ -{\displaystyle \mathrm {FNR} ={\frac {\mathrm {FN} }{\mathrm {P} }}={\frac {\mathrm {FN} }{\mathrm {FN} +\mathrm {TP} }} } -\] -!et -!eblock +!split +===== Other quantities ===== + !bblock False discovery rate $FDR$ @@ -434,10 +460,17 @@ graphical plot that illustrates the performance of a binary classifier model at varying threshold values. The ROC curve is the plot of the true positive rate (TPR) against the false positive rate (FPR) at each threshold setting. + +To draw a ROC curve, only the true positive rate (TPR) and false +positive rate (FPR) are needed (as functions of some classifier +parameter). The TPR defines how many correct positive results occur +among all positive samples available during the test. FPR, on the +other hand, defines how many incorrect positive results occur among +all negative samples available during the test. + + See URL:"https://en.wikipedia.org/wiki/Receiver_operating_characteristic" for more discussions. - - !split ===== Cumulative gain curve ===== @@ -447,7 +480,7 @@ fraction of examples correctly classified against Predictive Positive Rate, which represents the fraction of positively predicted examples. - +The examples below show the confusion matrix, the ROC curve and the cumulative gain for the Wisconsin cancer data. !split