Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Created February 26, 2024 16:20
Show Gist options
  • Save ThomasParistech/51aca92d7039a278c1389f340248ff57 to your computer and use it in GitHub Desktop.
Save ThomasParistech/51aca92d7039a278c1389f340248ff57 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.stats import norm
def weighted_kde(x_data: np.ndarray, x_prediction: np.ndarray) -> np.ndarray:
h = silverman_bandwidth(x_data) # Required to evaluate CDF
area_values = norm.cdf(1.0, x_prediction, h) - norm.cdf(0.0, x_prediction, h)
basic_densities = basic_kde(x_data, x_prediction, h)
return basic_densities / area_values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment