# AgglomerativeClustering

### *class* cuml.cluster.AgglomerativeClustering(n_clusters=2, , metric='euclidean', connectivity='knn', linkage='single', c=15, compute_distances=False, verbose=False, output_type=None)

Agglomerative Clustering

Recursively merges the pair of clusters that minimally increases a
given linkage distance.

* **Parameters:**
  **n_clusters**
  : The number of clusters to find.

  **metric**
  : Metric used to compute the linkage. Can be “euclidean”, “l1”,
    “l2”, “manhattan”, or “cosine”. If connectivity is “knn” only
    “euclidean” is accepted.

  **connectivity**
  : The type of connectivity matrix to compute.
    : * ‘pairwise’ will compute the entire fully-connected graph of
        pairwise distances between each set of points. This is the
        fastest to compute and can be very fast for smaller datasets
        but requires O(n^2) space.
      * ‘knn’ will sparsify the fully-connected connectivity matrix to save
        memory and enable much larger inputs. You can use `c` to influence
        the number of neighbors used.

  **linkage**
  : Which linkage criterion to use. The linkage criterion determines
    which distance to use between sets of observations. The algorithm
    will merge the pairs of clusters that minimize this criterion.
    > * ‘single’ uses the minimum of the distances between all
    >   observations of the two sets.

  **c**
  : Indirectly influences the number of neighbors to use when
    `connectivity="knn"`, with `n_neighbors = log(n_samples) + c`. The
    default of 15 should suffice for most problems.

  **compute_distances**
  : Whether to also compute and store the distances between nodes as
    `distances_`.

  **verbose**
  : Sets logging level. It must be one of `cuml.common.logger.level_*`.
    See [Verbosity Levels](../../cuml/index.html.md#verbosity-levels) for more info.

  **output_type**
  : Return results and set estimator attributes to the indicated output
    type. If None, the output type set at the module level
    (`cuml.global_settings.output_type`) will be used. See
    [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration) for more info.
* **Attributes:**
  **n_clusters_**
  : The number of clusters found by the algorithm.

  **labels**
  : Cluster labels for each point.

  **n_leaves_**
  : Number of leaves in the hierarchical tree.

  **n_connected_components_**
  : The estimated number of connected components in the graph.

  **children_**
  : The children of each non-leave node.

  **distances_**
  : Distances between the corresponding nodes in `children_`. Only exists
    if `compute_distances=True`.

### Methods

| [`fit`](#cuml.cluster.AgglomerativeClustering.fit)(self, X[, y])         | Fit the hierarchical clustering from features.   |
|----------------------------------------------------------------------------|--------------------------------------------------|
| [`fit_predict`](#cuml.cluster.AgglomerativeClustering.fit_predict)(self, X[, y]) | Fit and return the assigned cluster labels.      |
<!-- !! processed by numpydoc !! -->

#### fit(self, X, y=None) → 'AgglomerativeClustering'[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/cluster/agglomerative.pyx#L148)

Fit the hierarchical clustering from features.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **y**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

<!-- !! processed by numpydoc !! -->

#### fit_predict(self, X, y=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/cluster/agglomerative.pyx#L234)

Fit and return the assigned cluster labels.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **y**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **preds**
  : Cluster indexes
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->
