Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 查找我的数据中拟合的beta分布的参数值_Python_R_Beta Distribution - Fatal编程技术网

Python 查找我的数据中拟合的beta分布的参数值

Python 查找我的数据中拟合的beta分布的参数值,python,r,beta-distribution,Python,R,Beta Distribution,我试图找到适合我的数据(我的数据直方图)的最佳贝塔分布参数值。不知何故,我开始使用R来实现这一点,但我是一个初学者,因此,任何乐于使用Python分享任何代码或想法的人都将不胜感激。 下面是我找到的一个示例代码 # Example Data x = sample(-100:100, 50) print(x) #Normalized Data normalized = (x-min(x))/(max(x)-min(x)) print(normalized) # Histogram of exa

我试图找到适合我的数据(我的数据直方图)的最佳贝塔分布参数值。不知何故,我开始使用R来实现这一点,但我是一个初学者,因此,任何乐于使用Python分享任何代码或想法的人都将不胜感激。 下面是我找到的一个示例代码

# Example Data
x = sample(-100:100, 50)
print(x)

#Normalized Data
normalized = (x-min(x))/(max(x)-min(x))
print(normalized)

# Histogram of example data and normalized data
par(mfrow=c(1,2))
hist(x,          breaks=10, xlab="Data",            col="lightblue", main="")
hist(normalized, breaks=10, xlab="Normalized Data", col="lightblue", main="")
在这里,我想规范化从0到1的数据,因为beta分布的范围是从0到1。我在互联网上找到了下面的代码示例,但这段代码已经设置了beta分布的两个参数值

set.seed(3)
x <- rgamma(1e5, 2, .2)
plot(density(x))
 
# normalize the gamma so it's between 0 & 1
# .0001 added because having exactly 1 causes fail
xt <- x / ( max( x ) + .0001 )
 
# fit a beta distribution to xt
library( MASS )
fit.beta <- fitdistr( xt, "beta", start = list( shape1=2, shape2=5 ) )
 
x.beta <- rbeta(1e5,fit.beta$estimate[[1]],fit.beta$estimate[[2]])
 
## plot the pdfs on top of each other
plot(density(xt))
lines(density(x.beta), col="red" )
 
## plot the qqplots
qqplot(xt, x.beta)
set.seed(3)
x