질문은 무의미한 많은 정보가 있지만 혼란 스러울 정도로 혼란 스럽습니다. 내가 할 수있는 최선의 방법을 시도해 보겠다.
당신이 생각하는 것은 다음과 같습니다 : 알 수없는 분포의 유한 샘플이 주어진다면 고정 된 값으로 새 샘플을 얻을 확률은 얼마입니까?
일반 답변이있는 것은 확실하지 않지만 어쨌든 통계 또는 수학 사람들에게 질문해야하는 질문이 될 수 있습니다. 내 생각 엔 당신이 배포판 자체에 대해 몇 가지 가정을해야 할 것입니다.
그러나 실제로는 샘플링 된 분포의 어느 bin에 새로운 값이 있는지 알아 내면 충분할 수 있습니다.
따라서 우리는 x
이라는 분포가 있다고 가정하고 이것을 bins
으로 나눕니다. numpy.histogram
을 사용하여 h
의 막대 그래프를 계산할 수 있습니다. 각 bin에서 값을 찾을 확률은 h/h.sum()
입니다.
값이 v=0.77
이고 분포에 따른 확률을 알고 싶다면이 값을 삽입해야하는 bin 배열의 인덱스 ind
을 찾아서 속할 빈을 찾을 수 있습니다 소트 된 배열. 이것은 numpy.searchsorted
을 사용하여 수행 할 수 있습니다.
import numpy as np; np.random.seed(0)
x = np.random.rayleigh(size=1000)
bins = np.linspace(0,4,41)
h, bins_ = np.histogram(x, bins=bins)
prob = h/float(h.sum())
ind = np.searchsorted(bins, 0.77, side="right")
print prob[ind] # which prints 0.058
따라서 빈에서 값을 0.77 정도 샘플링 할 확률은 5.8 %입니다.
다른 옵션은 확률을 찾기 위해 빈 센터간에 히스토그램을 보간하는 것입니다.
아래의 코드에서 우리는 질문의 그림에서와 유사한 분포를 그리고 두 방법 모두를 사용합니다. 첫 번째는 빈도 막대 그래프이고 두 번째는 누적 분포입니다. 누구 이건
import numpy as np; np.random.seed(0)
import matplotlib.pyplot as plt
x = np.random.rayleigh(size=1000)
y = np.random.normal(size=1000)
bins = np.linspace(0,4,41)
h, bins_ = np.histogram(x, bins=bins)
hcum = np.cumsum(h)/float(np.cumsum(h).max())
points = [[.77,-.55],[1.13,1.08],[2.15,-.3]]
markers = [ur'$\u2660$',ur'$\u2665$',ur'$\u263B$']
colors = ["k", "crimson" , "gold"]
labels = list("ABC")
kws = dict(height_ratios=[1,1,2], hspace=0.0)
fig, (axh, axc, ax) = plt.subplots(nrows=3, figsize=(6,6), gridspec_kw=kws, sharex=True)
cbins = np.zeros(len(bins)+1)
cbins[1:-1] = bins[1:]-np.diff(bins[:2])[0]/2.
cbins[-1] = bins[-1]
hcumc = np.linspace(0,1, len(cbins))
hcumc[1:-1] = hcum
axc.plot(cbins, hcumc, marker=".", markersize="2", mfc="k", mec="k")
axh.bar(bins[:-1], h, width=np.diff(bins[:2])[0], alpha=0.7, ec="C0", align="edge")
ax.scatter(x,y, s=10, alpha=0.7)
for p, m, l, c in zip(points, markers, labels, colors):
kw = dict(ls="", marker=m, color=c, label=l, markeredgewidth=0, ms=10)
# plot points in scatter distribution
ax.plot(p[0],p[1], **kw)
#plot points in bar histogram, find bin in which to plot point
# shift by half the bin width to plot it in the middle of bar
pix = np.searchsorted(bins, p[0], side="right")
axh.plot(bins[pix-1]+np.diff(bins[:2])[0]/2., h[pix-1]/2., **kw)
# plot in cumulative histogram, interpolate, such that point is on curve.
yi = np.interp(p[0], cbins, hcumc)
axc.plot(p[0],yi, **kw)
ax.legend()
plt.tight_layout()
plt.show()
는 그래서 내가 잘못하고있는 중이 야 무엇에 향상시킬 수있는 이유에 대해 자세히 설명 할 내 게시물을,을 downvoted? – DarthLazar