Понимание 2D оценки для кода функции плотности, Python новичок - PullRequest
0 голосов
/ 26 марта 2020

Я новичок 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, yy, f, 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()
...