Skip to content

Instantly share code, notes, and snippets.

@admond1994
Created May 17, 2019 14:17
Show Gist options
  • Select an option

  • Save admond1994/d6db58dd00cf28c472df1bef924cfd53 to your computer and use it in GitHub Desktop.

Select an option

Save admond1994/d6db58dd00cf28c472df1bef924cfd53 to your computer and use it in GitHub Desktop.
def get_probability(start_value, end_value, eval_points, kd):
# Number of evaluation points
N = eval_points
step = (end_value - start_value) / (N - 1) # Step size
x = np.linspace(start_value, end_value, N)[:, np.newaxis] # Generate values in the range
kd_vals = np.exp(kd.score_samples(x)) # Get PDF values for each x
probability = np.sum(kd_vals * step) # Approximate the integral of the PDF
return probability.round(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment