Class: Rumale::Clustering::DBSCAN
- Inherits:
-
Object
- Object
- Rumale::Clustering::DBSCAN
- Includes:
- Base::BaseEstimator, Base::ClusterAnalyzer
- Defined in:
- lib/rumale/clustering/dbscan.rb
Overview
DBSCAN is a class that implements DBSCAN cluster analysis.
Reference
-
Ester, H-P. Kriegel, J. Sander, and X. Xu, “A density-based algorithm for discovering clusters in large spatial databases with noise,” Proc. KDD’ 96, pp. 266–231, 1996.
-
Direct Known Subclasses
Instance Attribute Summary collapse
-
#core_sample_ids ⇒ Numo::Int32
readonly
Return the core sample indices.
-
#labels ⇒ Numo::Int32
readonly
Return the cluster labels.
Attributes included from Base::BaseEstimator
Instance Method Summary collapse
-
#fit(x) ⇒ DBSCAN
Analysis clusters with given training data.
-
#fit_predict(x) ⇒ Numo::Int32
Analysis clusters and assign samples to clusters.
-
#initialize(eps: 0.5, min_samples: 5, metric: 'euclidean') ⇒ DBSCAN
constructor
Create a new cluster analyzer with DBSCAN method.
-
#marshal_dump ⇒ Hash
Dump marshal data.
-
#marshal_load(obj) ⇒ nil
Load marshal data.
Methods included from Base::ClusterAnalyzer
Constructor Details
#initialize(eps: 0.5, min_samples: 5, metric: 'euclidean') ⇒ DBSCAN
Create a new cluster analyzer with DBSCAN method.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rumale/clustering/dbscan.rb', line 36 def initialize(eps: 0.5, min_samples: 5, metric: 'euclidean') check_params_float(eps: eps) check_params_integer(min_samples: min_samples) check_params_string(metric: metric) @params = {} @params[:eps] = eps @params[:min_samples] = min_samples @params[:metric] = metric == 'precomputed' ? 'precomputed' : 'euclidean' @core_sample_ids = nil @labels = nil end |
Instance Attribute Details
#core_sample_ids ⇒ Numo::Int32 (readonly)
Return the core sample indices.
23 24 25 |
# File 'lib/rumale/clustering/dbscan.rb', line 23 def core_sample_ids @core_sample_ids end |
#labels ⇒ Numo::Int32 (readonly)
Return the cluster labels. The negative cluster label indicates that the point is noise.
27 28 29 |
# File 'lib/rumale/clustering/dbscan.rb', line 27 def labels @labels end |
Instance Method Details
#fit(x) ⇒ DBSCAN
Analysis clusters with given training data.
55 56 57 58 59 60 |
# File 'lib/rumale/clustering/dbscan.rb', line 55 def fit(x, _y = nil) check_sample_array(x) raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1] partial_fit(x) self end |
#fit_predict(x) ⇒ Numo::Int32
Analysis clusters and assign samples to clusters.
67 68 69 70 71 72 |
# File 'lib/rumale/clustering/dbscan.rb', line 67 def fit_predict(x) check_sample_array(x) raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1] partial_fit(x) labels end |
#marshal_dump ⇒ Hash
Dump marshal data.
76 77 78 79 80 |
# File 'lib/rumale/clustering/dbscan.rb', line 76 def marshal_dump { params: @params, core_sample_ids: @core_sample_ids, labels: @labels } end |
#marshal_load(obj) ⇒ nil
Load marshal data.
84 85 86 87 88 89 |
# File 'lib/rumale/clustering/dbscan.rb', line 84 def marshal_load(obj) @params = obj[:params] @core_sample_ids = obj[:core_sample_ids] @labels = obj[:labels] nil end |