diff --git a/doc/pub/week36/html/week36-bs.html b/doc/pub/week36/html/week36-bs.html index 909936c71..7df89604a 100644 --- a/doc/pub/week36/html/week36-bs.html +++ b/doc/pub/week36/html/week36-bs.html @@ -146,6 +146,15 @@ Automatically generated HTML file from DocOnce source ('Marginal Probability', 2, None, 'marginal-probability'), ('Conditional Probability', 2, None, 'conditional-probability'), ("Bayes' Theorem", 2, None, 'bayes-theorem'), + ("Interpretations of Bayes' Theorem", + 2, + None, + 'interpretations-of-bayes-theorem'), + ("Example of Usage of Bayes' theorem", + 2, + None, + 'example-of-usage-of-bayes-theorem'), + ('Doing it correctly', 2, None, 'doing-it-correctly'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -311,33 +320,36 @@ MathJax.Hub.Config({
  • Marginal Probability
  • Conditional Probability
  • Bayes' Theorem
  • -
  • Why resampling methods
  • -
  • Resampling methods
  • -
  • Resampling approaches can be computationally expensive
  • -
  • Why resampling methods ?
  • -
  • Statistical analysis
  • -
  • Resampling methods
  • -
  • Resampling methods: Jackknife and Bootstrap
  • -
  • Resampling methods: Jackknife
  • -
  • Jackknife code example
  • -
  • Resampling methods: Bootstrap
  • -
  • Resampling methods: Bootstrap background
  • -
  • Resampling methods: More Bootstrap background
  • -
  • Resampling methods: Bootstrap approach
  • -
  • Resampling methods: Bootstrap steps
  • -
  • Code example for the Bootstrap method
  • -
  • Various steps in cross-validation
  • -
  • How to set up the cross-validation for Ridge and/or Lasso
  • -
  • Cross-validation in brief
  • -
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • -
  • The bias-variance tradeoff
  • -
  • Example code for Bias-Variance tradeoff
  • -
  • Understanding what happens
  • -
  • Summing up
  • -
  • Another Example from Scikit-Learn's Repository
  • -
  • More examples on bootstrap and cross-validation and errors
  • -
  • The same example but now with cross-validation
  • -
  • Cross-validation with Ridge
  • +
  • Interpretations of Bayes' Theorem
  • +
  • Example of Usage of Bayes' theorem
  • +
  • Doing it correctly
  • +
  • Why resampling methods
  • +
  • Resampling methods
  • +
  • Resampling approaches can be computationally expensive
  • +
  • Why resampling methods ?
  • +
  • Statistical analysis
  • +
  • Resampling methods
  • +
  • Resampling methods: Jackknife and Bootstrap
  • +
  • Resampling methods: Jackknife
  • +
  • Jackknife code example
  • +
  • Resampling methods: Bootstrap
  • +
  • Resampling methods: Bootstrap background
  • +
  • Resampling methods: More Bootstrap background
  • +
  • Resampling methods: Bootstrap approach
  • +
  • Resampling methods: Bootstrap steps
  • +
  • Code example for the Bootstrap method
  • +
  • Various steps in cross-validation
  • +
  • How to set up the cross-validation for Ridge and/or Lasso
  • +
  • Cross-validation in brief
  • +
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • +
  • The bias-variance tradeoff
  • +
  • Example code for Bias-Variance tradeoff
  • +
  • Understanding what happens
  • +
  • Summing up
  • +
  • Another Example from Scikit-Learn's Repository
  • +
  • More examples on bootstrap and cross-validation and errors
  • +
  • The same example but now with cross-validation
  • +
  • Cross-validation with Ridge
  • @@ -396,7 +408,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 68
  • +
  • 71
  • »
  • diff --git a/doc/pub/week36/html/week36-reveal.html b/doc/pub/week36/html/week36-reveal.html index f7d95d300..a313e8b57 100644 --- a/doc/pub/week36/html/week36-reveal.html +++ b/doc/pub/week36/html/week36-reveal.html @@ -1567,7 +1567,7 @@ If we have independent events then \( p(X,Y)=p(X)p(Y) \).

    The marginal probability is defined in terms of only of the set of variables \( X,Y \). For a discrete probability we have

    -Discrete Probability +

     
    $$ p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). @@ -1612,7 +1612,87 @@ p(X\vert Y)= \frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}=\frac{p(Y\vert $$

     
    -which is Bayes' theorem. More text to be added here by Friday September 10. +which is Bayes' theorem. It allows us to evaluate the uncertainty in in \( X \) after we have observed \( Y \). We can easily interchange \( X \) with \( Y \). + + + +

    +

    Interpretations of Bayes' Theorem

    + +

    +The quantity \( p(Y\vert X) \) on the right-hand side of the theorem is +evaluated for the observed data \( Y \) and can be viewed as a function of +the parameter space represented by \( X \). This function is not +necesseraly normalized and is normally called the likelihood function. + +

    +The function \( p(X) \) on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution. + +

    +Let us try to illustrate Bayes' theorem through an example. +

    + + +
    +

    Example of Usage of Bayes' theorem

    + +

    +Let us suppose that you are undergoing a series of mammography scan in +order to rule out possible breast cancer cases. We define the +sensitivity for a positive event by the variable \( X \) (it takes binary +values with \( X=1 \) representing a positive event and \( X=0 \) being a +negative event. We reserve \( Y \) as a classification parameter for +either a negative or a postive breast cancer confirmation. + +

    +We let \( Y=1 \) represent the the case of having breast cancer and \( Y=0 \) as not. + +

    +Let us assume that if you have breast cancer, the test will be positive with a probability of \( 0.8 \), that is we have + +

     
    +$$ +p(X=1\vert Y=1) =0.8. +$$ +

     
    + +

    +This obviously sounds scaring since many would conclude that if the test is positive, there is a likelihood of \( 80\% \) for having cancer. +It is however not correct, as the following Bayesian analysis shows. +

    + + +
    +

    Doing it correctly

    + +

    +If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. +Let us assume that the prior probability in the population as a whole is + +

     
    +$$ +p(Y=1) =0.004. +$$ +

     
    + +

    +We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have +

     
    +$$ +p(X=1\vert Y=0) =0.1. +$$ +

     
    + +

    +Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute + +

     
    +$$ +p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031. +$$ +

     
    + +That is, in case of a positive test, there is only a \( 3\% \) chance of having cancer!

    diff --git a/doc/pub/week36/html/week36-solarized.html b/doc/pub/week36/html/week36-solarized.html index d0013236e..d336592e8 100644 --- a/doc/pub/week36/html/week36-solarized.html +++ b/doc/pub/week36/html/week36-solarized.html @@ -166,6 +166,15 @@ div { text-align: justify; text-justify: inter-word; } ('Marginal Probability', 2, None, 'marginal-probability'), ('Conditional Probability', 2, None, 'conditional-probability'), ("Bayes' Theorem", 2, None, 'bayes-theorem'), + ("Interpretations of Bayes' Theorem", + 2, + None, + 'interpretations-of-bayes-theorem'), + ("Example of Usage of Bayes' theorem", + 2, + None, + 'example-of-usage-of-bayes-theorem'), + ('Doing it correctly', 2, None, 'doing-it-correctly'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -1554,7 +1563,7 @@ If we have independent events then \( p(X,Y)=p(X)p(Y) \).

    The marginal probability is defined in terms of only of the set of variables \( X,Y \). For a discrete probability we have

    -Discrete Probability +

    $$ p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). @@ -1595,7 +1604,79 @@ $$ p(X\vert Y)= \frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}=\frac{p(Y\vert X)p(X)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}, $$ -which is Bayes' theorem. More text to be added here by Friday September 10. +which is Bayes' theorem. It allows us to evaluate the uncertainty in in \( X \) after we have observed \( Y \). We can easily interchange \( X \) with \( Y \). + +

    +









    + +

    Interpretations of Bayes' Theorem

    + +

    +The quantity \( p(Y\vert X) \) on the right-hand side of the theorem is +evaluated for the observed data \( Y \) and can be viewed as a function of +the parameter space represented by \( X \). This function is not +necesseraly normalized and is normally called the likelihood function. + +

    +The function \( p(X) \) on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution. + +

    +Let us try to illustrate Bayes' theorem through an example. + +

    +









    + +

    Example of Usage of Bayes' theorem

    + +

    +Let us suppose that you are undergoing a series of mammography scan in +order to rule out possible breast cancer cases. We define the +sensitivity for a positive event by the variable \( X \) (it takes binary +values with \( X=1 \) representing a positive event and \( X=0 \) being a +negative event. We reserve \( Y \) as a classification parameter for +either a negative or a postive breast cancer confirmation. + +

    +We let \( Y=1 \) represent the the case of having breast cancer and \( Y=0 \) as not. + +

    +Let us assume that if you have breast cancer, the test will be positive with a probability of \( 0.8 \), that is we have + +$$ +p(X=1\vert Y=1) =0.8. +$$ + +

    +This obviously sounds scaring since many would conclude that if the test is positive, there is a likelihood of \( 80\% \) for having cancer. +It is however not correct, as the following Bayesian analysis shows. + +

    +









    + +

    Doing it correctly

    + +

    +If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. +Let us assume that the prior probability in the population as a whole is + +$$ +p(Y=1) =0.004. +$$ + +

    +We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have +$$ +p(X=1\vert Y=0) =0.1. +$$ + +

    +Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute + +$$ +p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031. +$$ + +That is, in case of a positive test, there is only a \( 3\% \) chance of having cancer!











    diff --git a/doc/pub/week36/html/week36.html b/doc/pub/week36/html/week36.html index d2f112130..ab2642584 100644 --- a/doc/pub/week36/html/week36.html +++ b/doc/pub/week36/html/week36.html @@ -171,6 +171,15 @@ div { text-align: justify; text-justify: inter-word; } ('Marginal Probability', 2, None, 'marginal-probability'), ('Conditional Probability', 2, None, 'conditional-probability'), ("Bayes' Theorem", 2, None, 'bayes-theorem'), + ("Interpretations of Bayes' Theorem", + 2, + None, + 'interpretations-of-bayes-theorem'), + ("Example of Usage of Bayes' theorem", + 2, + None, + 'example-of-usage-of-bayes-theorem'), + ('Doing it correctly', 2, None, 'doing-it-correctly'), ('Why resampling methods', 2, None, 'why-resampling-methods'), ('Resampling methods', 2, None, 'resampling-methods'), ('Resampling approaches can be computationally expensive', @@ -1559,7 +1568,7 @@ If we have independent events then \( p(X,Y)=p(X)p(Y) \).

    The marginal probability is defined in terms of only of the set of variables \( X,Y \). For a discrete probability we have

    -Discrete Probability +

    $$ p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). @@ -1600,7 +1609,79 @@ $$ p(X\vert Y)= \frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}=\frac{p(Y\vert X)p(X)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}, $$ -which is Bayes' theorem. More text to be added here by Friday September 10. +which is Bayes' theorem. It allows us to evaluate the uncertainty in in \( X \) after we have observed \( Y \). We can easily interchange \( X \) with \( Y \). + +

    +









    + +

    Interpretations of Bayes' Theorem

    + +

    +The quantity \( p(Y\vert X) \) on the right-hand side of the theorem is +evaluated for the observed data \( Y \) and can be viewed as a function of +the parameter space represented by \( X \). This function is not +necesseraly normalized and is normally called the likelihood function. + +

    +The function \( p(X) \) on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution. + +

    +Let us try to illustrate Bayes' theorem through an example. + +

    +









    + +

    Example of Usage of Bayes' theorem

    + +

    +Let us suppose that you are undergoing a series of mammography scan in +order to rule out possible breast cancer cases. We define the +sensitivity for a positive event by the variable \( X \) (it takes binary +values with \( X=1 \) representing a positive event and \( X=0 \) being a +negative event. We reserve \( Y \) as a classification parameter for +either a negative or a postive breast cancer confirmation. + +

    +We let \( Y=1 \) represent the the case of having breast cancer and \( Y=0 \) as not. + +

    +Let us assume that if you have breast cancer, the test will be positive with a probability of \( 0.8 \), that is we have + +$$ +p(X=1\vert Y=1) =0.8. +$$ + +

    +This obviously sounds scaring since many would conclude that if the test is positive, there is a likelihood of \( 80\% \) for having cancer. +It is however not correct, as the following Bayesian analysis shows. + +

    +









    + +

    Doing it correctly

    + +

    +If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. +Let us assume that the prior probability in the population as a whole is + +$$ +p(Y=1) =0.004. +$$ + +

    +We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have +$$ +p(X=1\vert Y=0) =0.1. +$$ + +

    +Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute + +$$ +p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031. +$$ + +That is, in case of a positive test, there is only a \( 3\% \) chance of having cancer!











    diff --git a/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz b/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz index b7a8f4e0b..2298cfc20 100644 Binary files a/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz and b/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz differ diff --git a/doc/pub/week36/ipynb/week36.ipynb b/doc/pub/week36/ipynb/week36.ipynb index ae6216f34..4f6aa65c4 100644 --- a/doc/pub/week36/ipynb/week36.ipynb +++ b/doc/pub/week36/ipynb/week36.ipynb @@ -1969,8 +1969,7 @@ "\n", "## Marginal Probability\n", "\n", - "The marginal probability is defined in terms of only of the set of variables $X,Y$. For a discrete probability we have\n", - "**Discrete Probability.**" + "The marginal probability is defined in terms of only of the set of variables $X,Y$. For a discrete probability we have" ] }, { @@ -2038,11 +2037,101 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "which is Bayes' theorem. More text to be added here by Friday September 10.\n", + "which is Bayes' theorem. It allows us to evaluate the uncertainty in in $X$ after we have observed $Y$. We can easily interchange $X$ with $Y$. \n", "\n", + "## Interpretations of Bayes' Theorem\n", "\n", + "The quantity $p(Y\\vert X)$ on the right-hand side of the theorem is\n", + "evaluated for the observed data $Y$ and can be viewed as a function of\n", + "the parameter space represented by $X$. This function is not\n", + "necesseraly normalized and is normally called the likelihood function.\n", "\n", + "The function $p(X)$ on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution.\n", "\n", + "Let us try to illustrate Bayes' theorem through an example.\n", + "\n", + "## Example of Usage of Bayes' theorem\n", + "\n", + "Let us suppose that you are undergoing a series of mammography scan in\n", + "order to rule out possible breast cancer cases. We define the\n", + "sensitivity for a positive event by the variable $X$ (it takes binary\n", + "values with $X=1$ representing a positive event and $X=0$ being a\n", + "negative event. We reserve $Y$ as a classification parameter for\n", + "either a negative or a postive breast cancer confirmation.\n", + "\n", + "We let $Y=1$ represent the the case of having breast cancer and $Y=0$ as not.\n", + "\n", + "Let us assume that if you have breast cancer, the test will be positive with a probability of $0.8$, that is we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "p(X=1\\vert Y=1) =0.8.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This obviously sounds scaring since many would conclude that if the test is positive, there is a likelihood of $80\\%$ for having cancer.\n", + "It is however not correct, as the following Bayesian analysis shows.\n", + "\n", + "## Doing it correctly\n", + "\n", + "If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number.\n", + "Let us assume that the prior probability in the population as a whole is" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "p(Y=1) =0.004.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "p(X=1\\vert Y=0) =0.1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "p(Y=1\\vert X=1)=\\frac{p(X=1\\vert Y=1)p(Y=1)}{p(X=1\\vert Y=1)p(Y=1)+p(X=1\\vert Y=0)p(Y=0)}=\\frac{0.8\\times 0.004}{0.8\\times 0.004+0.1\\times 0.996}=0.031.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "That is, in case of a positive test, there is only a $3\\%$ chance of having cancer!\n", "\n", "## Why resampling methods\n", "\n", diff --git a/doc/src/week36/week36.do.txt b/doc/src/week36/week36.do.txt index d0636d789..9ff0a78b6 100644 --- a/doc/src/week36/week36.do.txt +++ b/doc/src/week36/week36.do.txt @@ -1215,7 +1215,7 @@ If we have independent events then $p(X,Y)=p(X)p(Y)$. ===== Marginal Probability ===== The marginal probability is defined in terms of only of the set of variables $X,Y$. For a discrete probability we have -!bblock Discrete Probability +!bblock !bt \[ p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). @@ -1253,11 +1253,70 @@ which we can rewrite as p(X\vert Y)= \frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}=\frac{p(Y\vert X)p(X)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}, \] !et -which is Bayes' theorem. More text to be added here by Friday September 10. +which is Bayes' theorem. It allows us to evaluate the uncertainty in in $X$ after we have observed $Y$. We can easily interchange $X$ with $Y$. +!split +===== Interpretations of Bayes' Theorem ===== +The quantity $p(Y\vert X)$ on the right-hand side of the theorem is +evaluated for the observed data $Y$ and can be viewed as a function of +the parameter space represented by $X$. This function is not +necesseraly normalized and is normally called the likelihood function. +The function $p(X)$ on the right hand side is called the prior while the function on the left hand side is the called the posterior probability. The denominator on the right hand side serves as a normalization factor for the posterior distribution. +Let us try to illustrate Bayes' theorem through an example. + +!split +===== Example of Usage of Bayes' theorem ===== + +Let us suppose that you are undergoing a series of mammography scan in +order to rule out possible breast cancer cases. We define the +sensitivity for a positive event by the variable $X$ (it takes binary +values with $X=1$ representing a positive event and $X=0$ being a +negative event. We reserve $Y$ as a classification parameter for +either a negative or a postive breast cancer confirmation. + +We let $Y=1$ represent the the case of having breast cancer and $Y=0$ as not. + +Let us assume that if you have breast cancer, the test will be positive with a probability of $0.8$, that is we have + +!bt +\[ +p(X=1\vert Y=1) =0.8. +\] +!et + +This obviously sounds scaring since many would conclude that if the test is positive, there is a likelihood of $80\%$ for having cancer. +It is however not correct, as the following Bayesian analysis shows. + +!split +===== Doing it correctly ===== + +If we look at various national surveys on breast cancer, the general likelihood of developing breast cancer is a very small number. +Let us assume that the prior probability in the population as a whole is + +!bt +\[ +p(Y=1) =0.004. +\] +!et + +We need also to account for the fact that the test may produce a false positive result (false alarm). Let us here assume that we have +!bt +\[ +p(X=1\vert Y=0) =0.1. +\] +!et + +Using Bayes' theorem we can then find the posterior probability that the person has breast cancer in case of a positive test, that is we can compute + +!bt +\[ +p(Y=1\vert X=1)=\frac{p(X=1\vert Y=1)p(Y=1)}{p(X=1\vert Y=1)p(Y=1)+p(X=1\vert Y=0)p(Y=0)}=\frac{0.8\times 0.004}{0.8\times 0.004+0.1\times 0.996}=0.031. +\] +!et +That is, in case of a positive test, there is only a $3\%$ chance of having cancer! !split ===== Why resampling methods =====