擅长:python、mysql、java
<p>你应该试试<a href="http://www.scipy.org/getting-started.html" rel="noreferrer">SciPy</a>。它有许多有用的科学程序,例如“数值计算积分、求解微分方程、优化和稀疏矩阵的程序”,它使用超高速优化的NumPy进行数字运算。安装请参见<a href="http://www.scipy.org/install.html" rel="noreferrer">here</a>。</p>
<p>请注意,space.distance.cosine计算的是<strong>距离</strong>,而不是相似度。因此,必须从1中减去该值,才能获得<strong>相似性。</p>
<pre><code>from scipy import spatial
dataSetI = [3, 45, 7, 2]
dataSetII = [2, 54, 13, 15]
result = 1 - spatial.distance.cosine(dataSetI, dataSetII)
</code></pre>