Hướng dẫn exponential distribution python example - Ví dụ về python phân phối theo cấp số nhân



Hàm exp(x) trong Python trả về ex.exp(x) trong Python trả về ex.

Show

Nội dung chính ShowShow

  • How to Generate an Exponential Distribution
  • How to Calculate Probabilities Using an Exponential Distribution
  • How to Plot an Exponential Distribution
  • Additional Resources
  • How do you generate a random number from exponential distribution in Python?
  • How do you generate a random number from an exponential distribution?
  • What is scale in Numpy random exponential?
  • How do you fit an exponential distribution in Python?

Nội dung chính

  • How to Generate an Exponential Distribution
  • How to Calculate Probabilities Using an Exponential Distribution
  • How to Plot an Exponential Distribution
  • Additional Resources
  • How do you generate a random number from exponential distribution in Python?
  • How do you generate a random number from an exponential distribution?
  • What is scale in Numpy random exponential?
  • How do you fit an exponential distribution in Python?

Nội dung chính

  • How to Generate an Exponential Distribution
  • How to Calculate Probabilities Using an Exponential Distribution
  • How to Plot an Exponential Distribution
  • Additional Resources
  • How do you generate a random number from exponential distribution in Python?
  • How do you generate a random number from an exponential distribution?
  • What is scale in Numpy random exponential?
  • How do you fit an exponential distribution in Python?

Nội dung chính

  • How to Generate an Exponential Distribution
  • How to Calculate Probabilities Using an Exponential Distribution
  • How to Plot an Exponential Distribution
  • Additional Resources

How do you generate a random number from exponential distribution in Python?

How do you generate a random number from an exponential distribution?exp() trong Python:

What is scale in Numpy random exponential? Hàm này không có thể truy cập trực tiếp, vì thế chúng ta cần import math module và sau đó chúng ta cần gọi hàm này bởi sử dụng đối tượng math.

How do you fit an exponential distribution in Python?

  • Nội dung chính: Đây là một biểu thức số.


Cú pháp

import math
print ("math.exp(-45) : ", math.exp(-45))
print ("math.exp(10.15) : ", math.exp(10.15))
print ("math.exp(100) : ", math.exp(100))
print ("math.exp(math.pi) : ", math.exp(math.pi))

Cú pháp của exp() trong Python:

math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267



Ghi chú: Hàm này không có thể truy cập trực tiếp, vì thế chúng ta cần import math module và sau đó chúng ta cần gọi hàm này bởi sử dụng đối tượng math.

Các tham số:he cumulative distribution function of X can be written as:

x: Đây là một biểu thức số.

where:

  • Ví dụ sau minh họa cách sử dụng của hàm exp() trong Python. the rate parameter (calculated as λ = 1/μ)
  • Chạy chương trình Python trên sẽ cho kết quả: A constant roughly equal to 2.718

The exponential distribution is a probability distribution that is used to model the time we must wait until a certain event occurs.

How to Generate an Exponential Distribution

If a random variable X follows an exponential distribution, then the cumulative distribution function of X can be written as:expon.rvs(scale, size) function from the SciPy library in Python to generate random values from an exponential distribution with a specific rate parameter and sample size:

from scipy.stats import expon

#generate random values from exponential distribution with rate=40 and sample size=10
expon.rvs(scale=40, size=10)

array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
        34.60922432,   2.68266663,  22.70459831,  97.66661811,
         6.64272914,  46.15547298])

F(x; λ) = 1 – e-λx: You can find the complete documentation for the SciPy library here.

How to Calculate Probabilities Using an Exponential Distribution

λ: the rate parameter (calculated as λ = 1/μ)

e: A constant roughly equal to 2.718

  • This tutorial explains how to use the exponential distribution in Python.
  • You can use the expon.rvs(scale, size) function from the SciPy library in Python to generate random values from an exponential distribution with a specific rate parameter and sample size:
  • Note: You can find the complete documentation for the SciPy library here.

Suppose the mean number of minutes between eruptions for a certain geyser is 40 minutes. What is the probability that we’ll have to wait less than 50 minutes for an eruption?

  • To solve this, we need to first calculate the rate parameter:
  • λ = 1/μ
  • λ = 1/40

λ = .0250.7135.

We can plug in λ = .025 and x = 50 to the formula for the CDF:expon.cdf() function from SciPy to solve this problem in Python:

from scipy.stats import expon

#calculate probability that x is less than 50 when mean rate is 40
expon.cdf(x=50, scale=40)

0.7134952031398099

λ = .0250.7135.

We can plug in λ = .025 and x = 50 to the formula for the CDF:

How to Plot an Exponential Distribution

P(X ≤ x) = 1 – e-λx

from scipy.stats import expon
import matplotlib.pyplot as plt

#generate exponential distribution with sample size 10000
x = expon.rvs(scale=40, size=10000)

#create plot of exponential distribution
plt.hist(x, density=True, edgecolor='black')

Hướng dẫn exponential distribution python example - Ví dụ về python phân phối theo cấp số nhân

Additional Resources

P(X ≤ 50) = 1 – e-.025(50)

P(X ≤ 50) = 0.7135
How to Use the t Distribution in Python
How to Use the Uniform Distribution in Python

The probability that we’ll have to wait less than 50 minutes for the next eruption is 0.7135.exponential(scale=1.0, size=None)#

We can use the expon.cdf() function from SciPy to solve this problem in Python:

Nội dung chính

  • How do you generate a random number from exponential distribution in Python?
  • How do you generate a random number from an exponential distribution?
  • What is scale in Numpy random exponential?
  • How do you fit an exponential distribution in Python?

Nội dung chính

Cú pháp

Cú pháp của exp() trong Python:\(\beta\) is the scale parameter, which is the inverse of the rate parameter \(\lambda = 1/\beta\). The rate parameter is an alternative, widely used parameterization of the exponential distribution [3].

Ghi chú: Hàm này không có thể truy cập trực tiếp, vì thế chúng ta cần import math module và sau đó chúng ta cần gọi hàm này bởi sử dụng đối tượng math.

Ghi chú

Mã mới nên sử dụng phương thức exponential của một thể hiện

math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
0 thay thế; Vui lòng xem bắt đầu nhanh chóng.Quick Start.

Tham sốScalefloat hoặc Array_like of Floatsscalefloat or array_like of floats

Tham số tỷ lệ, \ (\ beta = 1/\ lambda \). Phải không âm.\(\beta = 1/\lambda\). Must be non-negative.

kích thước hoặc tuple của int, tùy chọnint or tuple of ints, optional

Hình dạng đầu ra. Nếu hình dạng đã cho là, ví dụ,

math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
1, thì các mẫu
math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
2 được vẽ. Nếu kích thước là
math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
3 (mặc định), một giá trị duy nhất được trả về nếu
math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
4 là vô hướng. Nếu không, các mẫu
math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
5 được rút ra.

ReturnSoutNDarray hoặc vô hướngoutndarray or scalar

Các mẫu rút ra từ phân phối theo cấp số nhân được tham số hóa.

Người giới thiệu

1

Peyton Z. Peebles Jr., Xác suất, biến ngẫu nhiên và nguyên tắc tín hiệu ngẫu nhiên, Ed, 4th, 2001, tr. 57.

2

Wikipedia, Poisson Process, https://en.wikipedia.org/wiki/poisson_process

3

Wikipedia, Phân phối theo cấp số nhân, https://en.wikipedia.org/wiki/Exponential_distribution

Tôi nghĩ rằng bạn thực sự đang hỏi về một vấn đề hồi quy, đó là những gì Praveen đã gợi ý.regression problem, which is what Praveen was suggesting.

Bạn có một sự phân rã theo cấp số nhân tiêu chuẩn BOG đến trục y ở khoảng Y = 0,27. Do đó, phương trình của nó là

math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
6. Tôi có thể mô hình hóa lỗi Gaussian xung quanh các giá trị của hàm này và vẽ kết quả bằng cách sử dụng mã sau.

import matplotlib.pyplot as plt
from math import exp
from scipy.stats import norm


x = range(0, 16)
Y = [0.27*exp(-0.27*_) for _ in x]
error = norm.rvs(0, scale=0.05, size=9)
simulated_data = [max(0, y+e) for (y,e) in zip(Y[:9],error)]

plt.plot(x, Y, 'b-')
plt.plot(x[:9], simulated_data, 'r.')
plt.show()

print (x[:9])
print (simulated_data)

Đây là cốt truyện. Lưu ý rằng tôi lưu các giá trị đầu ra để sử dụng tiếp theo.

Bây giờ tôi có thể tính toán hồi quy phi tuyến của các giá trị phân rã theo cấp số nhân, bị nhiễm nhiễu, trên biến độc lập, đó là những gì

math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
7 làm.

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)

Phần thưởng là, không chỉ tính toán ước tính cho tham số - 0.207962159793 - mà còn đưa ra ước tính cho phương sai ước tính này - 0,00086071 - như một yếu tố của

math.exp(-45) :  2.8625185805493937e-20
math.exp(10.15) :  25591.102206689702
math.exp(100) :  2.6881171418161356e+43
math.exp(math.pi) :  23.140692632779267
9. Đây dường như là một giá trị khá nhỏ, với kích thước mẫu nhỏ.

Đây là cách tính phần dư. Lưu ý rằng mỗi phần dư là chênh lệch giữa giá trị dữ liệu và giá trị ước tính từ

from scipy.stats import expon

#generate random values from exponential distribution with rate=40 and sample size=10
expon.rvs(scale=40, size=10)

array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
        34.60922432,   2.68266663,  22.70459831,  97.66661811,
         6.64272914,  46.15547298])
0 bằng cách sử dụng ước tính tham số.

residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)

Nếu bạn muốn tiếp tục kiểm tra rằng chức năng của tôi thực sự đang đi qua các điểm dữ liệu 'thì tôi sẽ đề nghị tìm kiếm các mẫu trong phần dư. Nhưng các cuộc thảo luận như thế này có thể vượt ra ngoài những gì được hoan nghênh trên các lô Stackoverflow: Q-Q và P-P, các lô của phần dư so với

from scipy.stats import expon

#generate random values from exponential distribution with rate=40 and sample size=10
expon.rvs(scale=40, size=10)

array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
        34.60922432,   2.68266663,  22.70459831,  97.66661811,
         6.64272914,  46.15547298])
1 hoặc
from scipy.stats import expon

#generate random values from exponential distribution with rate=40 and sample size=10
expon.rvs(scale=40, size=10)

array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
        34.60922432,   2.68266663,  22.70459831,  97.66661811,
         6.64272914,  46.15547298])
0, v.v.

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọcnumpy.random.exponential() method, we can get the random samples from exponential distribution and returns the numpy array of random samples by using this method.

    Bàn luận

    Với sự trợ giúp của phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên từ phân phối theo cấp số nhân và trả về mảng vô dụng của các mẫu ngẫu nhiên bằng cách sử dụng phương pháp này.numpy.random.exponential(scale=1.0, size=None)

    Phân phối theo cấp số nhânReturn the random samples of numpy array.

    Cú pháp: numpy.random.exponential (tỷ lệ = 1.0, size = none)

    Trả về: Trả về các mẫu ngẫu nhiên của mảng numpy.numpy.random.exponential() method, we are able to get the random samples of exponential distribution and return the samples of numpy array.

    Python3

    Ví dụ 1 :

    Trong ví dụ này, chúng ta có thể thấy rằng bằng cách sử dụng phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên phân phối theo cấp số nhân và trả về các mẫu của mảng numpy.

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    3
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    4

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    3
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    6

    from scipy.stats import expon
    import matplotlib.pyplot as plt
    
    #generate exponential distribution with sample size 10000
    x = expon.rvs(scale=40, size=10000)
    
    #create plot of exponential distribution
    plt.hist(x, density=True, edgecolor='black')
    
    2

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    7
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    9
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    0
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    1
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    2
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3

    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    4
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    6
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    7
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    8
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    import matplotlib.pyplot as plt
    
    #generate exponential distribution with sample size 10000
    x = expon.rvs(scale=40, size=10000)
    
    #create plot of exponential distribution
    plt.hist(x, density=True, edgecolor='black')
    
    0
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3

    Đầu ra:

    Ví dụ 1 :

    Trong ví dụ này, chúng ta có thể thấy rằng bằng cách sử dụng phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên phân phối theo cấp số nhân và trả về các mẫu của mảng numpy.

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    3
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    4

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    3
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    6

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    7
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    9
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    0
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    1
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    2
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3

    from scipy.stats import expon
    import matplotlib.pyplot as plt
    
    #generate exponential distribution with sample size 10000
    x = expon.rvs(scale=40, size=10000)
    
    #create plot of exponential distribution
    plt.hist(x, density=True, edgecolor='black')
    
    2

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    7
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    9
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    0
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    1
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    2
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3


    from scipy.stats import expon #calculate probability that x is less than 50 when mean rate is 40 expon.cdf(x=50, scale=40) 0.7134952031398099 4from scipy.stats import expon #generate random values from exponential distribution with rate=40 and sample size=10 expon.rvs(scale=40, size=10) array([116.5368323 , 67.23514699, 12.00399043, 40.74580584, 34.60922432, 2.68266663, 22.70459831, 97.66661811, 6.64272914, 46.15547298]) 8 from scipy.stats import expon #calculate probability that x is less than 50 when mean rate is 40 expon.cdf(x=50, scale=40) 0.7134952031398099 6from scipy.stats import expon #calculate probability that x is less than 50 when mean rate is 40 expon.cdf(x=50, scale=40) 0.7134952031398099 7from scipy.stats import expon #calculate probability that x is less than 50 when mean rate is 40 expon.cdf(x=50, scale=40) 0.7134952031398099 8from scipy.stats import expon #generate random values from exponential distribution with rate=40 and sample size=10 expon.rvs(scale=40, size=10) array([116.5368323 , 67.23514699, 12.00399043, 40.74580584, 34.60922432, 2.68266663, 22.70459831, 97.66661811, 6.64272914, 46.15547298]) 8 from scipy.stats import expon import matplotlib.pyplot as plt #generate exponential distribution with sample size 10000 x = expon.rvs(scale=40, size=10000) #create plot of exponential distribution plt.hist(x, density=True, edgecolor='black') 0from scipy.stats import expon #calculate probability that x is less than 50 when mean rate is 40 expon.cdf(x=50, scale=40) 0.7134952031398099 3

    Đầu ra:numpy. random. exponential() method, we can get the random samples from exponential distribution and returns the numpy array of random samples by using this method.

    Ví dụ #2:

    Python3.

    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    7
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    9
    import matplotlib.pyplot as plt
    from math import exp
    from scipy.stats import norm
    
    
    x = range(0, 16)
    Y = [0.27*exp(-0.27*_) for _ in x]
    error = norm.rvs(0, scale=0.05, size=9)
    simulated_data = [max(0, y+e) for (y,e) in zip(Y[:9],error)]
    
    plt.plot(x, Y, 'b-')
    plt.plot(x[:9], simulated_data, 'r.')
    plt.show()
    
    print (x[:9])
    print (simulated_data)
    
    0
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    1
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    2
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3

    import matplotlib.pyplot as plt
    from math import exp
    from scipy.stats import norm
    
    
    x = range(0, 16)
    Y = [0.27*exp(-0.27*_) for _ in x]
    error = norm.rvs(0, scale=0.05, size=9)
    simulated_data = [max(0, y+e) for (y,e) in zip(Y[:9],error)]
    
    plt.plot(x, Y, 'b-')
    plt.plot(x[:9], simulated_data, 'r.')
    plt.show()
    
    print (x[:9])
    print (simulated_data)
    
    4
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    import matplotlib.pyplot as plt
    from math import exp
    from scipy.stats import norm
    
    
    x = range(0, 16)
    Y = [0.27*exp(-0.27*_) for _ in x]
    error = norm.rvs(0, scale=0.05, size=9)
    simulated_data = [max(0, y+e) for (y,e) in zip(Y[:9],error)]
    
    plt.plot(x, Y, 'b-')
    plt.plot(x[:9], simulated_data, 'r.')
    plt.show()
    
    print (x[:9])
    print (simulated_data)
    
    6
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    2
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3

    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    4
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    1
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    7
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    8
    from scipy.stats import expon
    
    #generate random values from exponential distribution with rate=40 and sample size=10
    expon.rvs(scale=40, size=10)
    
    array([116.5368323 ,  67.23514699,  12.00399043,  40.74580584,
            34.60922432,   2.68266663,  22.70459831,  97.66661811,
             6.64272914,  46.15547298])
    
    8
    from scipy.stats import expon
    import matplotlib.pyplot as plt
    
    #generate exponential distribution with sample size 10000
    x = expon.rvs(scale=40, size=10000)
    
    #create plot of exponential distribution
    plt.hist(x, density=True, edgecolor='black')
    
    0
    from scipy.stats import expon
    
    #calculate probability that x is less than 50 when mean rate is 40
    expon.cdf(x=50, scale=40)
    
    0.7134952031398099
    
    3

    Làm thế nào để bạn tạo ra một số ngẫu nhiên từ phân phối theo cấp số nhân trong Python?

    hàm mũ () trong python. Với sự trợ giúp của phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên từ phân phối theo cấp số nhân và trả về mảng vô dụng của các mẫu ngẫu nhiên bằng cách sử dụng phương pháp này.scale=1.0, size=None) Exponential distribution. Its probability density function is. for x > 0 and 0 elsewhere. is the scale parameter, which is the inverse of the rate parameter.

    Làm thế nào để bạn tạo ra một số ngẫu nhiên từ phân phối theo cấp số nhân?

    Vì vậy, một chiến lược chúng ta có thể sử dụng để tạo 1000 số sau phân phối theo cấp số nhân với giá trị trung bình là 5 là:.fit using an exponential function where `b` is constrained to 0 (or whatever value you know it to be). ```python def monoExpZeroB(x, m, t): return m * np. exp(-t * x) # perform the fit using the function where B is 0 p0 = (2000, . 1) # start with values near those we expect paramsB, cv = scipy.