Python Tutorial : Optimal parameters

Learn how to find optimal parameters for a normal distribution using real data from Michelson's speed-of-light experiments. The instructor shows how to plot empirical and theoretical cumulative distribution functions with NumPy to verify the model fits, then demonstrates that the sample mean and standard deviation are the optimal parameters when the normal model is correct.
Chapters
After completing the prequel to this course, you are now beginning to think probabilistically. Outcomes of measurements follow probability distributions defined by the story of how the data came to be when we looked at Michelson's speed of light and air measurements, we assumed that the results were normally distributed. We verified that both by looking at the PDF and the cdf, which was more effective because there is no binning bias. To compute and plot the CDF, we needed our old friends Numpy and Matplotlib Pyplot. So the first step was to import them with their traditional aliases. To compute the theoretical CDF by sampling, we passed two parameters into NP random normal the mean and standard deviation. The values we chose for these parameters were in fact the mean and standard deviation we calculated directly from the data. The result was that the theoretical CDF overlaid beautifully with the empirical cdf. How did we know that the mean and standard deviation calculated from the data were the appropriate values for the normal parameters? We could have chosen others. What if the standard deviation differs by 50%, the CDFs no longer match, or if the mean varies by just 0.01%? So if we believe that the process that generates our data gives normally distributed results, the set of parameters that brings the model, in this case the normal distribution, in closest agreement with the data uses the mean and standard deviation based computed directly from the data. These are the optimal parameters. Remember though, the parameters are only optimal for the model you choose for your data. When your model is wrong, the optimal parameters are really not meaningful. Finding the optimal parameters is not always as easy as just computing the mean and standard deviation from the data. We will encounter this later in this chapter, but when we do linear regressions and we rely on built in numpy functions to find the optimal parameters for us, I pause here to note that there are great tools in the Python ecosystem for doing statistical inference, including by optimization, Scipy Stats and stats models being two good examples. In this course, however, we focus on hacker statistics because the technique is like a Swiss army knife. The same simple principle is applicable to a wide variety of statistical problems. Now it's time for you to do some exercises to demonstrate how choosing optimal parameters results in best agreement between the theoretical model distribution and your data.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







