Class: Rumale::Clustering::SingleLinkage
- Inherits:
-
Base::Estimator
- Object
- Base::Estimator
- Rumale::Clustering::SingleLinkage
- Includes:
- Base::ClusterAnalyzer
- Defined in:
- rumale-clustering/lib/rumale/clustering/single_linkage.rb
Overview
SingleLinkage is a class that implements hierarchical cluster analysis with single linakge method. This class is used internally for HDBSCAN.
Reference
-
Mullner, D., “Modern hierarchical, agglomerative clustering algorithms,” arXiv:1109.2378, 2011.
Instance Attribute Summary collapse
-
#hierarchy ⇒ Array<SingleLinkage::Node>
readonly
Return the hierarchical structure.
-
#labels ⇒ Numo::Int32
readonly
Return the cluster labels.
Attributes inherited from Base::Estimator
Instance Method Summary collapse
-
#fit(x) ⇒ SingleLinkage
Analysis clusters with given training data.
-
#fit_predict(x) ⇒ Numo::Int32
Analysis clusters and assign samples to clusters.
-
#initialize(n_clusters: 2, metric: 'euclidean') ⇒ SingleLinkage
constructor
Create a new cluster analyzer with single linkage algorithm.
Methods included from Base::ClusterAnalyzer
Constructor Details
#initialize(n_clusters: 2, metric: 'euclidean') ⇒ SingleLinkage
Create a new cluster analyzer with single linkage algorithm.
38 39 40 41 42 43 44 |
# File 'rumale-clustering/lib/rumale/clustering/single_linkage.rb', line 38 def initialize(n_clusters: 2, metric: 'euclidean') super() @params = { n_clusters: n_clusters, metric: (metric == 'precomputed' ? 'precomputed' : 'euclidean') } end |
Instance Attribute Details
#hierarchy ⇒ Array<SingleLinkage::Node> (readonly)
Return the hierarchical structure.
30 31 32 |
# File 'rumale-clustering/lib/rumale/clustering/single_linkage.rb', line 30 def hierarchy @hierarchy end |
#labels ⇒ Numo::Int32 (readonly)
Return the cluster labels.
26 27 28 |
# File 'rumale-clustering/lib/rumale/clustering/single_linkage.rb', line 26 def labels @labels end |
Instance Method Details
#fit(x) ⇒ SingleLinkage
Analysis clusters with given training data.
52 53 54 55 56 57 58 |
# File 'rumale-clustering/lib/rumale/clustering/single_linkage.rb', line 52 def fit(x, _y = nil) x = ::Rumale::Validation.check_convert_sample_array(x) raise ArgumentError, 'the input distance matrix should be square' if check_invalid_array_shape(x) fit_predict(x) self end |
#fit_predict(x) ⇒ Numo::Int32
Analysis clusters and assign samples to clusters.
65 66 67 68 69 70 71 |
# File 'rumale-clustering/lib/rumale/clustering/single_linkage.rb', line 65 def fit_predict(x) x = ::Rumale::Validation.check_convert_sample_array(x) raise ArgumentError, 'the input distance matrix should be square' if check_invalid_array_shape(x) distance_mat = @params[:metric] == 'precomputed' ? x : ::Rumale::PairwiseMetric.euclidean_distance(x) @labels = partial_fit(distance_mat) end |