Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help figuring out the python code for numpy assignment as I am still learning how to write all of the python code. Thank you.

Need help figuring out the python code for numpy assignment as I am still learning how to write all of the python code. Thank you. image text in transcribedimage text in transcribedimage text in transcribed

Active Experimentation Q1) In the following cell, write the Python code to perform following tasks. 1. Let low=0 and high=(the last two digits of PSU id, if it is o use 10), set mode = (high-low)/2.0. 2. Generate 1000 random triangular random variables using the low, high, and model parameters. 3. Create the histogram of the random variables using 10 bins. 4. Generate 1000 random triangular random variable using the low, high, and mode = (high-low)/4.0. 5. Create the histogram of the random variables using 10 bins. In (): Q2) Which group of the random variables does have more symmetric distribution? The random variables with mode=(high-low)/2.0 or mode= (high-low)/4.0? What is the meaning of mode in statistics? Enter your answers to the following Markdown cell. In ( ): Q3) Now you will write a code to predict P(X > mode), which is the probability that a random variable will be higher than its mode value. To achieve for this, you need to refer to the previous Numpy reading lab. Below are the steps to achieve this goal. 1. Generate 1000 random triangular random variables using the low, high, and model parameters that you set above. 2. Find how many of those random variables are greater than the mode value (you can use logical indexing for this). 3. Divide the number found in Step 2 by 1000. This is the predicted probability. Predict P(X > mode) for the the cases mode = (high-low)/2.0 and mode = (high-low)/4.0 In which case, the probability is higher? Provide the code in the following Code cell. In [ ]: Normal Distribution In this activity, you will generate random variables from the the normal distribution. The random. normal(mu, sigma, Size=None) returns normally distributed random variables where mu is the mean, and sigma is the standard deviation of the distribution. The size parameter defines the shape of the output similar to the the triangular distribution. [ ]: x=np.random. normal(10,1,1000) plt.hist(x, density=True, bins=10) Q3) Now you will write a code to predict P(X > 10), where X is a random variable, which is the probability that a random variable X will be higher than a. The process to predict this probability is given below 1. Generate 1000 random triangular random variables using the low, high, and model parameters that you set above. 2. Find how many of those random variables are greater than 10 (you can use logical indexing for this). 3. Divide the number found in Step 2 by 1000. This is the predicted probability. Repeat the process two cases mean =5/sigma=2 and mean =5/sigma=3. Provide your code in the following cell. [ ]: Q4) Now compare your results with the theoretical exact values calculated below. Are you close? Repeat the exercise with 10,000 random variable. Provide your observations in the following Markdown cell Random Seed Each time we run the previous cells, we will see that the output will be different because rand() function uses the next random number in the random number stream. Computers actually cannot create truly random numbers. Instead, they create a sequence of random numbers using a math function and use one at a time sequentially each time a random number is requested. The details of the math function to generate a random stream is out of the scope of this course. However, we should know that the sequence of random numbers depends on a parameter called seed. For a given seed value, we always have the same sequence of random numbers. Numpy random.seed ( seed=None) function initialize the random number stream with the given seed value. See the example, below. In [ ]: #two consecutive random numbers are different print(np.random. rand()) print(np. random. rand()) #initialize the random number stream np. random. seed (23233) print(np.random.rand()) print(np. random. rand()) #initialize the random number stream. The random numbers should be repeating. np. random. seed (23233) print(np. random. rand()) print(np. random. rand()) Q4)Let say we have 1000 computers that are tagged from 0 to 999. We would like to select 10 of them randomly for inspection. How would you achieve this in Python? Provide the code. Your code should write 10 randomly selected computers tag number In [ ]: Active Experimentation Q1) In the following cell, write the Python code to perform following tasks. 1. Let low=0 and high=(the last two digits of PSU id, if it is o use 10), set mode = (high-low)/2.0. 2. Generate 1000 random triangular random variables using the low, high, and model parameters. 3. Create the histogram of the random variables using 10 bins. 4. Generate 1000 random triangular random variable using the low, high, and mode = (high-low)/4.0. 5. Create the histogram of the random variables using 10 bins. In (): Q2) Which group of the random variables does have more symmetric distribution? The random variables with mode=(high-low)/2.0 or mode= (high-low)/4.0? What is the meaning of mode in statistics? Enter your answers to the following Markdown cell. In ( ): Q3) Now you will write a code to predict P(X > mode), which is the probability that a random variable will be higher than its mode value. To achieve for this, you need to refer to the previous Numpy reading lab. Below are the steps to achieve this goal. 1. Generate 1000 random triangular random variables using the low, high, and model parameters that you set above. 2. Find how many of those random variables are greater than the mode value (you can use logical indexing for this). 3. Divide the number found in Step 2 by 1000. This is the predicted probability. Predict P(X > mode) for the the cases mode = (high-low)/2.0 and mode = (high-low)/4.0 In which case, the probability is higher? Provide the code in the following Code cell. In [ ]: Normal Distribution In this activity, you will generate random variables from the the normal distribution. The random. normal(mu, sigma, Size=None) returns normally distributed random variables where mu is the mean, and sigma is the standard deviation of the distribution. The size parameter defines the shape of the output similar to the the triangular distribution. [ ]: x=np.random. normal(10,1,1000) plt.hist(x, density=True, bins=10) Q3) Now you will write a code to predict P(X > 10), where X is a random variable, which is the probability that a random variable X will be higher than a. The process to predict this probability is given below 1. Generate 1000 random triangular random variables using the low, high, and model parameters that you set above. 2. Find how many of those random variables are greater than 10 (you can use logical indexing for this). 3. Divide the number found in Step 2 by 1000. This is the predicted probability. Repeat the process two cases mean =5/sigma=2 and mean =5/sigma=3. Provide your code in the following cell. [ ]: Q4) Now compare your results with the theoretical exact values calculated below. Are you close? Repeat the exercise with 10,000 random variable. Provide your observations in the following Markdown cell Random Seed Each time we run the previous cells, we will see that the output will be different because rand() function uses the next random number in the random number stream. Computers actually cannot create truly random numbers. Instead, they create a sequence of random numbers using a math function and use one at a time sequentially each time a random number is requested. The details of the math function to generate a random stream is out of the scope of this course. However, we should know that the sequence of random numbers depends on a parameter called seed. For a given seed value, we always have the same sequence of random numbers. Numpy random.seed ( seed=None) function initialize the random number stream with the given seed value. See the example, below. In [ ]: #two consecutive random numbers are different print(np.random. rand()) print(np. random. rand()) #initialize the random number stream np. random. seed (23233) print(np.random.rand()) print(np. random. rand()) #initialize the random number stream. The random numbers should be repeating. np. random. seed (23233) print(np. random. rand()) print(np. random. rand()) Q4)Let say we have 1000 computers that are tagged from 0 to 999. We would like to select 10 of them randomly for inspection. How would you achieve this in Python? Provide the code. Your code should write 10 randomly selected computers tag number In [ ]

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions