[英]Sampling from a Computed Multivariate kernel density estimation
假設我在地圖上有X和Y坐標以及“熱區”的非參數分布(例如位於X和Y坐標的地理地圖上的污染程度)。 我的輸入數據是熱圖。
我想訓練一個學習“熱區”看起來像什么的機器學習模型,但我沒有很多帶標簽的例子。 所有“熱區”看起來非常相似,但可能位於標准化XY坐標圖的不同部分。
我可以計算多變量KDE並相應地繪制密度圖。 為了生成合成標記數據,我可以“反轉”KDE並隨機生成新的圖像文件,其中的觀察結果屬於我KDE的“密集”范圍嗎?
有沒有辦法在python中這樣做?
python至少有3種高質量的內核密度估計實現:
我的個人排名是statsmodels> scikit-learn> scipy(從最好到最差),但這取決於你的用例。
一些隨機評論:
kde.sample(N)
) 還有更多的差異,其中一些在Jake VanderPlas的這篇非常好的博客文章中進行了分析。 下表摘自這篇文章:
from sklearn.datasets import make_blobs
from sklearn.neighbors import KernelDensity
from sklearn.model_selection import GridSearchCV
import matplotlib.pyplot as plt
import numpy as np
# Create test-data
data_x, data_y = make_blobs(n_samples=100, n_features=2, centers=7, cluster_std=0.5, random_state=0)
# Fit KDE (cross-validation used!)
params = {'bandwidth': np.logspace(-1, 2, 30)}
grid = GridSearchCV(KernelDensity(), params)
grid.fit(data_x)
kde = grid.best_estimator_
bandwidth = grid.best_params_['bandwidth']
# Resample
N_POINTS_RESAMPLE = 1000
resampled = kde.sample(N_POINTS_RESAMPLE)
# Plot original data vs. resampled
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
for i in range(100):
axs[0,0].scatter(*data_x[i])
axs[0,1].hexbin(data_x[:, 0], data_x[:, 1], gridsize=20)
for i in range(N_POINTS_RESAMPLE):
axs[1,0].scatter(*resampled[i])
axs[1,1].hexbin(resampled[:, 0], resampled[:, 1], gridsize=20)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.