<jupyter_start><jupyter_text>カーネル密度推定によるノンパラメトリックな確率密度の推定<jupyter_code>import numpy as np
import scipy.stats as stats
import pandas as pd
import math
import matplotlib.pyplot as plt
import statsmodels.datasets as ds
from mpl_toolkits.basemap import Basemap
%matplotlib inline
data_frame = pd.read_csv("./Allstorms.ibtracs_wmo.v03r05.csv")
data_frame.tail()
grp_by_id = data_frame.groupby("Serial_Num")
pos = grp_by_id[['Longitude', 'Latitude']].mean()
pos.head()<jupyter_output><empty_output><jupyter_text>世界地図を表示Basemap(表示方法，緯度下限，緯度上限，経度下限，経度上限)<jupyter_code>map_data = Basemap(projection="mill", llcrnrlat=-55, urcrnrlat=55, llcrnrlon=-180, urcrnrlon=180)
x0, y0 = map_data(-180, -85)
x1, y1 = map_data(180, 85)
map_data.drawcoastlines()
map_data.fillcontinents(color="#dbf8b2")
map_data.plot
x, y = pos.values.T
x_map, y_map = map_data(x, y)
map_data.drawcoastlines()
map_data.fillcontinents(color="#dbf8b2")
map_data.plot(x_map, y_map, '.r', alpha=0.05)<jupyter_output><empty_output><jupyter_text>Kernel密度関数を返す処理を実行する．Kernel密度関数を推定する処理は$$\hat{f}_h(x) = \frac{1}{nh}\sum_{i=1}^nK(\frac{x - x_i}{h})$$で与えられ，$K(x)$がKernel関数と呼ばれる．Gauss関数etc.ここではGauss関数を用いることにする<jupyter_code>h = np.vstack((x_map, y_map))
kde = stats.gaussian_kde<jupyter_output><empty_output><jupyter_text>マップの格子データを生成する<jupyter_code>k = 50
tx, ty = np.meshgrid(np.linspace(x0, x1, k), np.linspace(y0, y1,2*k))
v = kde(h)(np.vstack((tx.ravel(), ty.ravel()))).reshape((2*k, k))
map_data.drawcoastlines()
map_data.fillcontinents(color="#dbf8b2")
map_data.imshow(v, origin="lower", extent=[x0, x1, y0, y1], cmap=plt.get_cmap("Reds"))
map_data.drawcoastlines()
map_data.fillcontinents(color="#dbf8b2")
map_data.plot(x_map, y_map, '.r', alpha=0.05)
map_data.imshow(v, origin="lower", cmap=plt.get_cmap("Blues"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16805324459234608, 'fraction_numerical': 0.03105934553521908, 'mean_word_length': 9.549707602339181, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '604419', 'license': 'MIT', 'n_tokens_mistral': 914, 'n_tokens_neox': 888, 'n_words': 102, 'path': 'chapter7/recipe7.6.ipynb', 'repo_name': 'tom-mats/ipython_test', 'size': '1803'}