@thi.ng/k-means 0.6.25 → 0.6.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +31 -19
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -77,37 +77,47 @@ A selection:
|
|
|
77
77
|
|
|
78
78
|
[Generated API docs](https://docs.thi.ng/umbrella/k-means/)
|
|
79
79
|
|
|
80
|
-
Example usage:
|
|
80
|
+
Example usage: Clustering cities by lat/lon location
|
|
81
81
|
|
|
82
|
-
```ts
|
|
83
|
-
import { kmeans, meansLatLon } from "@thi.ng/k-means";
|
|
82
|
+
```ts tangle:export/readme.ts
|
|
84
83
|
import { HAVERSINE_LATLON } from "@thi.ng/distance";
|
|
84
|
+
import { kmeans, meansLatLon } from "@thi.ng/k-means";
|
|
85
85
|
|
|
86
|
-
// data from:
|
|
86
|
+
// data sourced from:
|
|
87
|
+
// https://github.com/OpenDataFormats/worldcities/blob/master/src/data/cities.json
|
|
87
88
|
const cities = [
|
|
88
|
-
{ id: "
|
|
89
|
-
{ id: "
|
|
90
|
-
{ id: "
|
|
91
|
-
{ id: "
|
|
92
|
-
{ id: "
|
|
93
|
-
{ id: "
|
|
94
|
-
{ id: "
|
|
95
|
-
{ id: "
|
|
96
|
-
{ id: "
|
|
97
|
-
{ id: "
|
|
98
|
-
{ id: "
|
|
89
|
+
{ id: "anchorage", latlon: [61.21806, -149.90028] },
|
|
90
|
+
{ id: "berlin", latlon: [52.52437, 13.41053] },
|
|
91
|
+
{ id: "boston", latlon: [42.35843, -71.05977] },
|
|
92
|
+
{ id: "calgary", latlon: [51.05011, -114.08529] },
|
|
93
|
+
{ id: "cape town", latlon: [-33.92584, 18.42322] },
|
|
94
|
+
{ id: "detroit", latlon: [42.33143, -83.04575] },
|
|
95
|
+
{ id: "harare", latlon: [-17.82772, 31.05337] },
|
|
96
|
+
{ id: "london", latlon: [51.50853, -0.12574] },
|
|
97
|
+
{ id: "manila", latlon: [14.6042, 120.9822] },
|
|
98
|
+
{ id: "nairobi", latlon: [-1.28333, 36.81667] },
|
|
99
|
+
{ id: "new york", latlon: [40.71427, -74.00597] },
|
|
100
|
+
{ id: "paris", latlon: [48.85341, 2.3488] },
|
|
101
|
+
{ id: "philadelphia", latlon: [39.95233, -75.16379] },
|
|
102
|
+
{ id: "portland", latlon: [45.52345, -122.67621] },
|
|
103
|
+
{ id: "seoul", latlon: [37.566, 126.9784] },
|
|
104
|
+
{ id: "shanghai", latlon: [31.22222, 121.45806] },
|
|
105
|
+
{ id: "tokyo", latlon: [35.6895, 139.69171] },
|
|
106
|
+
{ id: "vancouver", latlon: [49.24966, -123.11934] },
|
|
107
|
+
{ id: "vienna", latlon: [48.20849, 16.37208] },
|
|
108
|
+
{ id: "windhoek", latlon: [-22.55941, 17.08323] },
|
|
99
109
|
];
|
|
100
110
|
|
|
101
111
|
// cluster based on lat/lon
|
|
102
112
|
const clusters = kmeans(
|
|
103
|
-
|
|
113
|
+
5,
|
|
104
114
|
cities.map((x) => x.latlon),
|
|
105
115
|
{
|
|
106
116
|
// custom centroid calc for geo locations
|
|
107
117
|
// https://docs.thi.ng/umbrella/k-means/functions/meansLatLon.html
|
|
108
118
|
strategy: meansLatLon,
|
|
109
119
|
// custom distance function for geo location (default: DIST_SQ)
|
|
110
|
-
dist: HAVERSINE_LATLON
|
|
120
|
+
dist: HAVERSINE_LATLON,
|
|
111
121
|
}
|
|
112
122
|
);
|
|
113
123
|
|
|
@@ -116,9 +126,11 @@ for (let c of clusters) {
|
|
|
116
126
|
console.log(c.items.map((i) => cities[i].id));
|
|
117
127
|
}
|
|
118
128
|
|
|
119
|
-
// [ '
|
|
120
|
-
// [ 'kyoto', 'osaka', 'tokyo' ]
|
|
129
|
+
// [ 'manila', 'seoul', 'shanghai', 'tokyo' ]
|
|
121
130
|
// [ 'berlin', 'london', 'paris', 'vienna' ]
|
|
131
|
+
// [ 'boston', 'detroit', 'new york', 'philadelphia' ]
|
|
132
|
+
// [ 'cape town', 'harare', 'nairobi', 'windhoek' ]
|
|
133
|
+
// [ 'anchorage', 'calgary', 'portland', 'vancouver' ]
|
|
122
134
|
```
|
|
123
135
|
|
|
124
136
|
## Authors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/k-means",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.27",
|
|
4
4
|
"description": "Configurable k-means & k-medians (with k-means++ initialization) for n-D vectors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.9.
|
|
38
|
-
"@thi.ng/distance": "^2.4.
|
|
39
|
-
"@thi.ng/errors": "^2.3.
|
|
40
|
-
"@thi.ng/random": "^3.6.
|
|
41
|
-
"@thi.ng/vectors": "^7.7.
|
|
37
|
+
"@thi.ng/api": "^8.9.5",
|
|
38
|
+
"@thi.ng/distance": "^2.4.12",
|
|
39
|
+
"@thi.ng/errors": "^2.3.5",
|
|
40
|
+
"@thi.ng/random": "^3.6.3",
|
|
41
|
+
"@thi.ng/vectors": "^7.7.10"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@microsoft/api-extractor": "^7.36.4",
|
|
45
|
-
"@thi.ng/testament": "^0.3.
|
|
45
|
+
"@thi.ng/testament": "^0.3.23",
|
|
46
46
|
"rimraf": "^5.0.1",
|
|
47
47
|
"tools": "^0.0.1",
|
|
48
|
-
"typedoc": "^0.
|
|
49
|
-
"typescript": "^5.
|
|
48
|
+
"typedoc": "^0.25.0",
|
|
49
|
+
"typescript": "^5.2.2"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|
|
52
52
|
"cluster",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"status": "beta",
|
|
83
83
|
"year": 2021
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "5929dd20497668496af13415cdf784a4d6f69aa3\n"
|
|
86
86
|
}
|