python对数正态分布函数_将对数正态分布的拟合PDF缩放到python中的histrogram

本文介绍了如何在Python中利用numpy和scipy库对对数正态分布的样本进行拟合,并展示了如何在matplotlib直方图上绘制预期的直方图。通过计算累积分布函数(CDF)的差值得到每个区间的预期样本数,并用这个信息绘制预期的直方图。此外,还提供了使用PDF进行相同操作的替代方法。
摘要由CSDN通过智能技术生成

您要求的是预期直方图的图表 .

假设[a,b]是直方图的x个区间之一 . 对于大小为n的随机样本,间隔中的预期样本数为

(cdf(b) - cdf(a))*n

其中cdf(x)是累积分布函数 . 要绘制预期的直方图,您将计算每个bin的值 .

下面的脚本显示了在matplotlib直方图上绘制预期直方图的一种方法 . 它生成这个图:

import numpy as np

import scipy.stats

import matplotlib.pyplot as plt

# Generate log-normal distributed set of samples

np.random.seed(1234)

samples = np.random.lognormal(mean=1., sigma=.4, size=10000)

# Make a fit to the samples.

shape, loc, scale = scipy.stats.lognorm.fit(samples, floc=0)

# Create the histogram plot using matplotlib. The first two values in

# the tuple returned by hist are the number of samples in each bin and

# the values of the histogram's bin edges. counts has length num_bins,

# and edges has length num_bins + 1.

<
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值