Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once __DIR__ . '/vendor/autoload.php';
- use Phpml\Clustering\KMeans;
- $locations = file('results.csv');
- foreach ($locations as &$line) {
- $row = explode(',', $line);
- $line = [(float) $row[0], (float) $row[1]];
- }
- $clusterer = new KMeans(18);
- $clusters = $clusterer->cluster($locations);
- $lines = [];
- foreach ($clusters as $key => $cluster) {
- foreach ($cluster as $sample) {
- $lines[] = sprintf('%s;%s;%s', $key, $sample[0], $sample[1]);
- }
- }
- file_put_contents('results-clusters.csv', implode(PHP_EOL, $lines));
Add Comment
Please, Sign In to add comment