Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TODO 16 Next, let's review what normal or Gaussian distribution is while also practicing some equation to code conversion. Now this weeks math review didn't

TODO 16

Next, let's review what normal or Gaussian distribution is while also practicing some equation to code conversion. Now this weeks math review didn't mention normal distributions but we did lightly cover probability distributions. Recall a probability distribution is a list of outcomes and their associated probabilities. Meaning, a distribution is simply a collection of values or frequencies for a given observation, like age of a population. A normal distribution is a specific type of probability distribution which looks like the following.

Further recall a normal distribution has the parameters (referred to as mu) which represents the mean and (referred to as sigma) represents the standard deviation. Throughout the semester we'll frequently make the assumption that our data is normally distributed. This is because many natural phenomena are like age, height, test-scores, IQ scores, sum of the rolls of two dices and so on follow normal distributions, thus making such an assumption reasonable. As normal distributions are found in so many different places they are one of the important probability distribution in statistics and machine learning!

The formula for a normal distribution is given as follows:

For this TODO let's convert the normal distribution equation to code and plot what a normal distribution looks like using Matplotlib.

Define a function called gaussian() that takes in the arguments x, mu, and sig. Convert the above normal equation into code and return the output of the equation. Recall that mu represents and sig represents .

Use the NumPy function np.linspace() (docs) to generate an array of 120 numbers between -4 and 4. Pass the arguments -4, 4, and 120 to do so. Store the output into the variable x_values.

Call the gaussian() function that receives x_values, mu, and sig. Store the output into the variable y_values.

Plot the x_values and y_values using Matplotlib plt.plot() function. You should see a normal distribution being plotted like in the above image!

# TODO 16.3 y_values = gaussian(x_values, mu, sig)

display(y_values)

todo_check([ (y_values.shape == (120,), 'y_values does not have the correct shape of (120,)'), (np.all(np.isclose(y_values, np.array([1.33830226e-04, 1.74726145e-04, 2.27090415e-04, 2.93817012e-04, 3.78435874e-04, 4.85226918e-04, 6.19347941e-04, 7.86976449e-04, 9.95465009e-04, 1.25350909e-03, 1.57132566e-03, 1.96083994e-03, 2.43587675e-03, 3.01235189e-03, 3.70845762e-03, 4.54483545e-03, 5.54472782e-03, 6.73409948e-03, 8.14171785e-03, 9.79918133e-03, 1.17408832e-02, 1.40038988e-02, 1.66277845e-02, 1.96542754e-02, 2.31268728e-02, 2.70903123e-02, 3.15899063e-02, 3.66707582e-02, 4.23768496e-02, 4.87500056e-02, 5.58287494e-02, 6.36470609e-02, 7.22330635e-02, 8.16076628e-02, 9.17831740e-02, 1.02761972e-01, 1.14535209e-01, 1.27081643e-01, 1.40366624e-01, 1.54341287e-01, 1.68941989e-01, 1.84090049e-01, 1.99691809e-01, 2.15639052e-01, 2.31809806e-01, 2.48069526e-01, 2.64272673e-01, 2.80264650e-01, 2.95884091e-01, 3.10965445e-01, 3.25341808e-01, 3.38847936e-01, 3.51323369e-01, 3.62615579e-01, 3.72583059e-01, 3.81098269e-01, 3.88050344e-01, 3.93347502e-01, 3.96919051e-01, 3.98716969e-01, 3.98716969e-01, 3.96919051e-01, 3.93347502e-01, 3.88050344e-01, 3.81098269e-01, 3.72583059e-01, 3.62615579e-01, 3.51323369e-01, 3.38847936e-01, 3.25341808e-01, 3.10965445e-01, 2.95884091e-01, 2.80264650e-01, 2.64272673e-01, 2.48069526e-01, 2.31809806e-01, 2.15639052e-01, 1.99691809e-01, 1.84090049e-01, 1.68941989e-01, 1.54341287e-01, 1.40366624e-01, 1.27081643e-01, 1.14535209e-01, 1.02761972e-01, 9.17831740e-02, 8.16076628e-02, 7.22330635e-02, 6.36470609e-02, 5.58287494e-02, 4.87500056e-02, 4.23768496e-02, 3.66707582e-02, 3.15899063e-02, 2.70903123e-02, 2.31268728e-02, 1.96542754e-02, 1.66277845e-02, 1.40038988e-02, 1.17408832e-02, 9.79918133e-03, 8.14171785e-03, 6.73409948e-03, 5.54472782e-03, 4.54483545e-03, 3.70845762e-03, 3.01235189e-03, 2.43587675e-03, 1.96083994e-03, 1.57132566e-03, 1.25350909e-03, 9.95465009e-04, 7.86976449e-04, 6.19347941e-04, 4.85226918e-04, 3.78435874e-04, 2.93817012e-04, 2.27090415e-04, 1.74726145e-04, 1.33830226e-04]),rtol=.001)), 'y_values does not contain the correct values') ])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions