了解密度函数代码的2D估计器,Python初学者

我是Python初学者,我有一个任务是实现密度函数的2D估计器并将其可视化。基于一个教程和另一个堆栈溢出线程,我想出了类似的东西,但是我并没有真正理解某些行所做的事情。尤其是带有锐舞,vstack和重塑的线条,我不知道尺寸操纵会发生什么。你能帮忙吗?

df=pd.read_csv("file") #obvious,reading from file
x = df['A']#x is A column
y = df['B']#y is B column
xmin= x.min()
xmax= x.max()
ymin=y.min()
ymax=y.max()#setting limits for mgrid
xx,yy = np.mgrid[xmin:xmax:100j,ymin:ymax:100j] #I tried using meshgrid but didn't work
positions = np.vstack([xx.ravel(),yy.ravel()])
values = np.vstack([x,y])
kernel = sp.gaussian_kde(values) 
f = np.reshape(kernel(positions).T,xx.shape)
#except from kernel line I don't understand what's  
#going on with those dimension manipulations.
fig = pl.figure()
ax = fig.gca()#returns axises
ax.set_xlim(xmin,xmax)
ax.set_ylim(ymin,ymax) #setting limits for the axises
cfset = ax.contourf(xx,yy,f,cmap='coolwarm') #fills up the contours
cset = ax.contour(xx,colors='k') #draws the lines
ax.clabel(cset,inline=1,fontsize=10) #podpis konturów
ax.set_xlabel('A')
ax.set_ylabel('B')
pl.show()
love990311 回答:了解密度函数代码的2D估计器,Python初学者

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2576217.html

大家都在问