PYTHON CODE HELP NEEDED. So far I have the code numpy.random.binomial(1,.1,10000
ID: 673620 • Letter: P
Question
PYTHON CODE HELP NEEDED. So far I have the code numpy.random.binomial(1,.1,10000) but I'm stuck on the other part. question (2) IS JUST FOR REFERENCE PURPOSES. ONLY (10) NEEDS TO BE COMPLETED, but some of the info from question (2) is necessary. Thanks!
(2) An insurance company has N 10000 clients. Each of them can get into a car accident with probability 10%, independently of each other. If a client gets into a car accident, the amount of the claim is 1000 dollars. The company charges each of them a premium x. Calculate the minimal amount of x so that the company gets bankrupt only with probability 5%.Explanation / Answer
a Bernoulli RV with parameter q is an RV X that takes value 1 with probability q
and value 0 with probability 1-q. The simplest way to
simulate such a thing is to observe that if x is a
real number chosen uniformly at random from [0, 1),
then P[x<q] = q. So to generate a Bernoulli RV, we
first generate a uniform random number x from [0, 1),
and then we return 1 if x < q and we return 0 otherwise:
'''
import random
def bernoulli(q):
"""Returns a random sample of a Bernoulli
random variable with parameter q"""
x = random.random()
if x < q:
return 1
else:
return 0
import matplotlib.pyplot as plt
N = 1000
heads = numpy.zeros(N, dtype=int)
for i in range(N):
Company[i] = numpy.random.binomial(1,.1,10000) ).sum()
plt.stem(numpy.bincount(heads), marker=’o’)
plt.margins(0.10)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.