I'd like to compare two distributions using Jensen-Shannon Divergence metric. To do this, I need two probability vectors to plug into distance.jensenshannon(p, q)
. From the scipy.spatial documentation.
scipy.spatial.distance.jensenshannon(p, q, base=None)[source]
Parameters:
p(N,) array_like left probability vector
q(N,) array_like right probability vector
Question
How can I calculate probability vectors from sample data?
Example:
from scipy.spatial import distance
import numpy as np
x1 = np.random.normal(size=100)
x2 = np.random.normal(size=100)
p =
q =
jsd_metric = distance.jensenshannon(p, q)
Can I accomplish this using scipy.stats.norm.pdf()
?
p = scipy.stats.norm.pdf(x1)
q = scipy.stats.norm.pdf(x2)