Computation of Kullback-Leibler (KL) distance between text-documents using numpy
问题 My goal is to compute the KL distance between the following text documents: 1)The boy is having a lad relationship 2)The boy is having a boy relationship 3)It is a lovely day in NY I first of all vectorised the documents in order to easily apply numpy 1)[1,1,1,1,1,1,1] 2)[1,2,1,1,1,2,1] 3)[1,1,1,1,1,1,1] I then applied the following code for computing KL distance between the texts: import numpy as np import math from math import log v=[[1,1,1,1,1,1,1],[1,2,1,1,1,2,1],[1,1,1,1,1,1,1]] c=v[0]