Haleshot commited on
Commit
89edddf
·
unverified ·
1 Parent(s): c591d7c

comments address

Browse files
probability/19_maximum_likelihood_estimation.py CHANGED
@@ -48,16 +48,11 @@ def _(mo):
48
 
49
  Likelihood measures how probable our observed data is, given specific values of the parameters $\theta$.
50
 
51
- - For **discrete** distributions: likelihood is the probability mass function (PMF) of our data
52
- - For **continuous** distributions: likelihood is the probability density function (PDF) of our data
53
-
54
  /// note
55
  **Probability vs. Likelihood**
56
 
57
  - **Probability**: Given parameters $\theta$, what's the chance of observing data $X$?
58
  - **Likelihood**: Given observed data $X$, how likely are different parameter values $\theta$?
59
-
60
- They use the same formula but different perspectives!
61
  ///
62
 
63
  To simplify notation, we'll use $f(X=x|\Theta=\theta)$ to represent either the PMF or PDF of our data, conditioned on the parameters.
@@ -687,9 +682,9 @@ def _(
687
  def _(mo):
688
  mo.md(
689
  r"""
690
- ## Interactive Concept: Likelihood vs. Probability
691
 
692
- To better understand the distinction between likelihood and probability, let's create an interactive visualization. This concept is crucial for understanding why MLE works.
693
  """
694
  )
695
  return
@@ -714,7 +709,7 @@ def _(concept_dist_type, mo, np, perspective_selector, plt, stats):
714
 
715
  if concept_dist_type_value == "Normal":
716
  if concept_view_mode == "probability":
717
- # probability perspective: fixed parameters, varying data
718
  concept_mu = 0 # fixed parameter
719
  concept_sigma = 1 # fixed parameter
720
 
@@ -733,11 +728,11 @@ def _(concept_dist_type, mo, np, perspective_selector, plt, stats):
733
  concept_prob = stats.norm.pdf(concept_data, concept_mu, concept_sigma)
734
  concept_ax.plot([concept_data, concept_data], [0, concept_prob], concept_colors[concept_i], linewidth=2)
735
  concept_ax.scatter(concept_data, concept_prob, color=concept_colors[concept_i], s=50,
736
- label=f'P(X={concept_data}|μ=0,σ=1) = {concept_prob:.3f}')
737
 
738
  concept_ax.set_xlabel('Data (x)')
739
  concept_ax.set_ylabel('Probability Density')
740
- concept_ax.set_title('Probability Perspective: Fixed Parameters (μ=0, σ=1), Different Data Points')
741
 
742
  else: # likelihood perspective
743
  # likelihood perspective: fixed data, varying parameters
@@ -900,19 +895,19 @@ def _(concept_dist_type, mo, np, perspective_selector, plt, stats):
900
  if concept_view_mode == "probability":
901
  concept_explanation = mo.md(
902
  f"""
903
- ### Probability Perspective
904
 
905
- In the **probability perspective**, the parameters of the distribution are **fixed and known**, and we calculate the probability (or density) for **different possible data values**.
906
 
907
- For the {concept_dist_type_value} distribution, we've fixed the parameter{'s' if concept_dist_type_value == 'Normal' else ''} and shown the probability of observing different outcomes.
908
 
909
  This is the typical perspective when:
910
 
911
  - We know the true parameters of a distribution
912
- - We want to calculate the probability of different outcomes
913
  - We make predictions based on our model
914
 
915
- **Mathematical notation**: $P(X = x | \theta)$
916
  """
917
  )
918
  else: # likelihood perspective
@@ -982,12 +977,12 @@ def _(mo):
982
 
983
  Which of the following statements about Maximum Likelihood Estimation are correct? Click each statement to check your answer.
984
 
985
- /// details | Probability and likelihood use the same formulas, but probability measures the chance of data given parameters, while likelihood measures how likely parameters are given data.
986
  ✅ **Correct!**
987
 
988
  Probability measures how likely it is to observe particular data when we know the parameters. Likelihood measures how likely particular parameter values are, given observed data.
989
 
990
- Mathematically, probability is $P(X=x|\theta)$ while likelihood is $L(\theta|X=x)$. They use the same formula, but with different perspectives on what's fixed and what varies.
991
  ///
992
 
993
  /// details | We use log-likelihood instead of likelihood because it's mathematically simpler and numerically more stable.
 
48
 
49
  Likelihood measures how probable our observed data is, given specific values of the parameters $\theta$.
50
 
 
 
 
51
  /// note
52
  **Probability vs. Likelihood**
53
 
54
  - **Probability**: Given parameters $\theta$, what's the chance of observing data $X$?
55
  - **Likelihood**: Given observed data $X$, how likely are different parameter values $\theta$?
 
 
56
  ///
57
 
58
  To simplify notation, we'll use $f(X=x|\Theta=\theta)$ to represent either the PMF or PDF of our data, conditioned on the parameters.
 
682
  def _(mo):
683
  mo.md(
684
  r"""
685
+ ## Interactive Concept: Density/Mass Functions vs. Likelihood
686
 
687
+ To better understand the distinction between likelihood and density/mass functions, let's create an interactive visualization. This concept is crucial for understanding why MLE works.
688
  """
689
  )
690
  return
 
709
 
710
  if concept_dist_type_value == "Normal":
711
  if concept_view_mode == "probability":
712
+ # density function perspective: fixed params, varying data
713
  concept_mu = 0 # fixed parameter
714
  concept_sigma = 1 # fixed parameter
715
 
 
728
  concept_prob = stats.norm.pdf(concept_data, concept_mu, concept_sigma)
729
  concept_ax.plot([concept_data, concept_data], [0, concept_prob], concept_colors[concept_i], linewidth=2)
730
  concept_ax.scatter(concept_data, concept_prob, color=concept_colors[concept_i], s=50,
731
+ label=f'PDF at x={concept_data}: {concept_prob:.3f}')
732
 
733
  concept_ax.set_xlabel('Data (x)')
734
  concept_ax.set_ylabel('Probability Density')
735
+ concept_ax.set_title('Density Function Perspective: Fixed Parameters (μ=0, σ=1), Different Data Points')
736
 
737
  else: # likelihood perspective
738
  # likelihood perspective: fixed data, varying parameters
 
895
  if concept_view_mode == "probability":
896
  concept_explanation = mo.md(
897
  f"""
898
+ ### Density/Mass Function Perspective
899
 
900
+ In the **density/mass function perspective**, the parameters of the distribution are **fixed and known**, and we evaluate the function at **different possible data values**.
901
 
902
+ For the {concept_dist_type_value} distribution, we've fixed the parameter{'s' if concept_dist_type_value == 'Normal' else ''} and shown the {'density' if concept_dist_type_value == 'Normal' else 'probability mass'} function evaluated at different data points.
903
 
904
  This is the typical perspective when:
905
 
906
  - We know the true parameters of a distribution
907
+ - We want to evaluate the {'density' if concept_dist_type_value == 'Normal' else 'probability mass'} at different observations
908
  - We make predictions based on our model
909
 
910
+ **Mathematical notation**: $f(x | \theta)$
911
  """
912
  )
913
  else: # likelihood perspective
 
977
 
978
  Which of the following statements about Maximum Likelihood Estimation are correct? Click each statement to check your answer.
979
 
980
+ /// details | Probability and likelihood have different interpretations: probability measures the chance of data given parameters, while likelihood measures how likely parameters are given data.
981
  ✅ **Correct!**
982
 
983
  Probability measures how likely it is to observe particular data when we know the parameters. Likelihood measures how likely particular parameter values are, given observed data.
984
 
985
+ Mathematically, probability is $P(X=x|\theta)$ while likelihood is $L(\theta|X=x)$.
986
  ///
987
 
988
  /// details | We use log-likelihood instead of likelihood because it's mathematically simpler and numerically more stable.