蟒蛇分布的距离和差异。
dictances的Python项目详细描述
python 3.6中实现的字典之间的距离和差异。
<>在复杂符号中,^ {< CD1>}是^ {< CD2>},^ {< CD3>}是^ {< CD4>}。示例是由test utilities here生成的字典。
我怎么得到它?
只需输入终端:
pip install dictances
基本示例
对于每个度量,在the folder examples中都有一个示例。这里有一个基本的例子,对于那些懒得点击链接的人(比如我)。
importrandomfromdictancesimportcosine,euclidean,canberrarandom.seed(42)# for reproducibility# Simple function to generate the example dictionariesdefgenerate_example_dict(n=1000):return{random.randint(0,1000):random.uniform(0,1000)foriinrange(n)}a,b=generate_example_dict(),generate_example_dict()print(cosine(a,b))# >>> 0.52336690346601print(euclidean(a,b))# >>> 15119.400349404095print(canberra(a,b))# >>> 624.9088876554047
度量表
Metric name | Usage example | Average time on sample | Complexity |
---|---|---|---|
Euclidean distance | euclidean | 90.4 µs ± 2.5 µs | |
Squared variation | squared_variation | 90.8 µs ± 1.43 | |
Total variation | total_variation | 92.3 µs ± 1.28 µs | |
Nth variation | nth_variation | 91.1 µs ± 1.2 µs | |
Manhattan distance | manhattan | 92.7 µs ± 1.43 µs | |
Mean absolute error | mae | 92.3 µs ± 1.28 µs | |
Mean squared error | mse | 91.1 µs ± 1.2 µs | |
Chebyshev distance | chebyshev | 101 µs ± 2.14 µs | |
Minkowski distance | minkowsky | 91.1 µs ± 2.05 µs | |
Canberra distance | canberra | 71.8 µs ± 1.95 µs | |
Cosine distance | cosine | 61.3 µs ± 835 ns | |
Pearson distance | pearson | 46.9 µs ± 1.23 µs | |
Hamming distance | hamming | 28.7 µs ± 784 ns | |
Normalized Total Variation | normal_total_variation | 34.6 µs ± 543 ns | |
Kullback Leibler divergence | kullback_leibler | 24 µs ± 587 ns | |
Jensen Shannon divergence | jensen_shannon | 38.2 µs ± 1.18 µs | |
Bhattacharyya distance | bhattacharyya | 32.7 µs ± 655 ns | |
Hellinger distance | hellinger | 42 µs ± 467 ns |
测试计算机规格
在其上计时的度量值具有以下规格的计算机:
Computer specifications | |
---|---|
Model Name | MacBook Pro |
Processor Name | Intel Core i7 |
Processor Speed | 2.3 GHz |
Number of Processors | 1 |
Total Number of Cores | 4 |
L2 Cache (per Core) | 256 KB |
L3 Cache | 6 MB |
Memory | 16 GB |