Created
May 17, 2019 14:17
-
-
Save admond1994/d6db58dd00cf28c472df1bef924cfd53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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