<jupyter_start><jupyter_text>Parzen window<jupyter_code>k = np.zeros((61,61))
print(k)

for i in range(x.shape[0]):
  for j in range(x.shape[1]):
    k[i,j] = 0
    for n in range(N):
      if np.abs(X[n,0] - x[i,j]) < h/2 and np.abs(X[n,1]-y[i,j]) <h/2:
        k[i,j] = k[i,j] + 1

pxyp = k/(h**2*N)

pxyp.shape
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(x,y,pxyp, rstride=1, cstride=1, cmap='spring')

plt.show()<jupyter_output><empty_output><jupyter_text>Gaussian Kernel<jupyter_code>from typing import NamedTuple
txy = np.zeros((1, 2))
k = np.zeros((61, 61))
ksum = []

for i in range(x.shape[0]):
  for j in range(y.shape[1]):
    txy = np.array([x[i,j], y[i,j]]) #대괄호로 하나더 묶어 줘야 행렬이된다 안묵으면 그냥 리스트 나래비?
    ksum = []
    for n in range(N):
      ksum = np.append(ksum, np.exp(-(X[n,:]-txy) @ (X[n,:]-txy).T / (2*h**2)) / (2*np.pi))
    k[i,j] = sum(ksum)

ksum.shape
pxyg = k/(h**2*N)

fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(x,y,pxyg, rstride=1, cstride=1, cmap ='spring')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2236084452975048, 'fraction_numerical': 0.029750479846449136, 'mean_word_length': 3.966666666666667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '266353', 'license': 'Apache-2.0', 'n_tokens_mistral': 568, 'n_tokens_neox': 573, 'n_words': 97, 'path': 'codes/youngjaelee/3_2_3_density_estimation_using_Parzen_window_and_Gaussian_Kernel.ipynb', 'repo_name': 'SanghunOh/study_machinglearning', 'size': '1042'}