lib/rumale/clustering/single_linkage.rb in rumale-0.13.8 vs lib/rumale/clustering/single_linkage.rb in rumale-0.14.0

- old
+ new

@@ -33,11 +33,11 @@ # @param n_clusters [Integer] The number of clusters. # @param metric [String] The metric to calculate the distances. # If metric is 'euclidean', Euclidean distance is calculated for distance between points. # If metric is 'precomputed', the fit and fit_transform methods expect to be given a distance matrix. def initialize(n_clusters: 2, metric: 'euclidean') - check_params_integer(n_clusters: n_clusters) + check_params_numeric(n_clusters: n_clusters) check_params_string(metric: metric) @params = {} @params[:n_clusters] = n_clusters @params[:metric] = metric == 'precomputed' ? 'precomputed' : 'euclidean' @labels = nil @@ -50,11 +50,11 @@ # # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for cluster analysis. # If the metric is 'precomputed', x must be a square distance matrix (shape: [n_samples, n_samples]). # @return [SingleLinkage] The learned cluster analyzer itself. def fit(x, _y = nil) - check_sample_array(x) + x = check_convert_sample_array(x) raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1] fit_predict(x) self end @@ -62,10 +62,10 @@ # # @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to be used for cluster analysis. # If the metric is 'precomputed', x must be a square distance matrix (shape: [n_samples, n_samples]). # @return [Numo::Int32] (shape: [n_samples]) Predicted cluster label per sample. def fit_predict(x) - check_sample_array(x) + x = check_convert_sample_array(x) raise ArgumentError, 'Expect the input distance matrix to be square.' if @params[:metric] == 'precomputed' && x.shape[0] != x.shape[1] distance_mat = @params[:metric] == 'precomputed' ? x : Rumale::PairwiseMetric.euclidean_distance(x) @labels = partial_fit(distance_mat) end