简体   繁体   中英

Probability Density Function using Python

I have a data set which has values in the range of 1e-2 and 1e-3. I have the following code to obtain the values and plot the distribution.

def get_pdf(data):
    a = np.array(data)
    ex = st.gaussian_kde(a)
    x = np.linspace(0, max(data), max(data))
    y = ag(ex)
    return x, y

data_list = dataset.iloc[:, 2].tolist()
data = [i * 10000 for i in data_list]
x_pdf, y_pdf = get_pdf(data)

plt.figure()
plt.plot(x_pdf, y_pdf, label='PDF of values')
plt.legend()
plt.xlabel('Value')
plt.ylabel('Probability')
output_image = "ex.png"
plt.savefig(output_image)
plt.close()

However, this code does not work unless each value in the data set is multiplied by 10,000 . I want to use the values in my data set as it is without multiplying. I would really appreciate some help. Thanks.

您应该尝试: x = np.linspace(min(data), max(data), len(data))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM