def perform_kde(data, params): grid = GridSearchCV(KernelDensity(), params) grid.fit(data) kde = grid.best_estimator_ new_data = kde.sample(1, random_state=0) quasar_plots.plot_spectrum(wavelengths, new_data[0]) plt.title('KDE of qso spectrum')
def perform_kde_with_pca(data, params, num_comps): pca = PCA(n_components=num_comps, whiten=False) data = pca.fit_transform(data) grid = GridSearchCV(KernelDensity(), params) grid.fit(data) kde = grid.best_estimator_ new_data = kde.sample(1, random_state=0) new_data = pca.inverse_transform(new_data) quasar_plots.plot_spectrum(wavelengths, new_data[0]) plt.title('KDE with PCA')