simple_cluster 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

simple_cluster #

Simple clustering library implemented in Dart.

Getting Started #

In your Dart (or Flutter) project pubspec.yaml add the dependency:

dependencies:
  ...
  simple_cluster: ^0.2.0

Usage #

DBSCAN #

Density-based spatial clustering of applications with noise (DBSCAN) Check Wiki.

Parameter:

  • epsilon: Minimum distance for two point to be considered as cluster
  • minPoints: Minimum points in a single cluster
  • distanceMeasure: Distance masure between 2 points

Example in dart.

import 'package:simple_cluster/src/dbscan.dart';

void main() {
  List<List<double>> dataset = [
    [1, 2], [2, 2], [2, 3], [8, 7], [8, 8], [25, 80]
  ];

  List<List<double>> dataset2 = [
    [1,1],[0,1],[1,0],
    [10,10],[10,13],[13,13],
    [54,54],[55,55],[89,89],[57,55]
  ];

  DBSCAN dbscan = DBSCAN(
    epsilon: 3,
    minPoints: 2,
  );

  List<List<int>> clusterOutput = dbscan.run(dataset);
  print("===== 1 =====");
  print("Clusters output");
  print(clusterOutput);//or dbscan.cluster
  print("Noise");
  print(dbscan.noise);
  print("Cluster label for points");
  print(dbscan.label);

  List<List<int>> clusterOutput2 = dbscan.run(dataset2);
  print("===== 2 =====");
  print("Clusters output");
  print(clusterOutput2);//or dbscan.cluster
  print("Noise");
  print(dbscan.noise);
  print("Cluster label for points");
  print(dbscan.label);
}

// Output
// ===== 1 =====
// Clusters output
// [[0, 1, 2], [3, 4]]
// Noise
// [5]
// Cluster label for points
// [0, 0, 0, 1, 1, -1]
// ===== 2 =====
// Clusters output
// [[0, 1, 2], [3, 4, 5], [6, 7, 9]]
// Noise
// [8]
// Cluster label for points
// [0, 0, 0, 1, 1, 1, 2, 2, -1, 2]

Hierarchical #

Hierarchical clustering Check Wiki.

Parameter:

  • maxLinkage: Terminate clustering process based on linkage
  • minCluster: Terminate clustering process based number of cluster
  • distanceMeasure: Distance masure between 2 points
  • linkage: Use existing linkage method
  • linkageMeasure: Use custom linkage method

Example in dart.

  List<List<double>> colors = [
    [20, 20, 80],
    [22, 22, 90],
    [250, 255, 253],
    [100, 54, 255]
  ];

  List<List<double>> singles = [[7], [10], [20], [28], [35]];

  Hierarchical hierarchical = Hierarchical(
    minCluster: 2, //stop at 2 cluster
    linkage: LINKAGE.SINGLE
  );

  List<List<int>> clusterList = hierarchical.run(colors);

  print("===== 1 =====");
  print("Clusters output");
  print(clusterList);//or hierarchical.cluster
  print("Noise");
  print(hierarchical.noise);
  print("Cluster label for points");
  print(hierarchical.label);

  List<List<int>> clusterList2 = hierarchical.run(singles);

  print("===== 2 =====");
  print("Clusters output");
  print(clusterList2);//or hierarchical.cluster
  print("Noise");
  print(hierarchical.noise);
  print("Cluster label for points");
  print(hierarchical.label);

  // Output:
  // ===== 1 =====
  // Clusters output
  // [[2], [3, 1, 0]]
  // Noise
  // [2]
  // Cluster label for points
  // [0, 0, -1, 0]
  // ===== 2 =====
  // Clusters output
  // [[1, 0], [4, 3, 2]]
  // Noise
  // []
  // Cluster label for points
  // [0, 0, 1, 1, 1]

Remarks #

This library is inspired by:

[0.2.1] #

  • Fixed hierarchical labeling

[0.2.0+1] #

  • Added missing export

[0.2.0] #

  • Added Hierarchical clustering
  • Moved euclidDistance to common file

[0.1.2] #

  • Updated License

[0.1.1] #

  • Updated multiple location for pub.dev health

[0.1.0] - Initial Release #

  • Added DBSCAN clustering

example/README.md

Usage #

Make sure you have dart (from dart-sdk) in your environment.

Run dart dbscan_sample.dart Run dart hierarchical_sample.dart

For Flutter developer #

Dart SDK binaries in Flutter usually located in <flutter-sdk-path>\bin\cache\dart-sdk\bin.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  simple_cluster: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:simple_cluster/simple_cluster.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Mar 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/dbscan.dart. (-0.50 points)

Analysis of lib/src/dbscan.dart reported 1 hint:

line 55 col 13: Unnecessary new keyword.

Format lib/simple_cluster.dart.

Run dartfmt to format lib/simple_cluster.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0