-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
30 lines (28 loc) · 869 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const kmeans = require('node-kmeans');
const tracks = require('./trackdata');
const vectors = tracks.map((track) => {
const dimensions = new Array(
//track.audio_features.danceability,
//track.audio_features.loudness,
track.audio_features.speechiness,
//track.audio_features.acousticness,
track.audio_features.instrumentalness
//track.audio_features.valence,
//track.audio_features.energy
//track.audio_features.tempo
//track.audio_features.duration_ms
);
return dimensions;
});
kmeans.clusterize(vectors, {k: 3}, (err, res) => {
if (err) console.error(err);
else {
res.map((cluster, clusterIdx) => {
console.log('\nCluster', clusterIdx);
cluster.clusterInd.map((trackIdx) => {
const track = tracks[trackIdx];
console.log(track.artists[0].name, '-', track.name);
});
});
}
});