BisectingKMeans¶
In [ ]:
BisectingKMeans(name: str,
n_cluster: int = 8,
bisection_iterations: int = 1,
split_method: str = 'sum_squares',
min_divisible_cluster_size: int = 2,
distance_method: str = "euclidean",
init: str = "kmeanspp",
max_iter: int = 300,
tol: float = 1e-4)
Creates a bisecting k-means object by using Vertica function BISECTING_KMEANS on the data. K-means clustering is a method of vector quantization, originally from signal processing, that aims to partition n observations into k clusters, where each observation belongs to the cluster with the nearest mean (cluster centers or cluster centroid), serving as a prototype of the cluster. This results in a partitioning of the dataspace into Voronoi cells. Bisecting k-means combines k-means and hierarchical clustering.
Parameters¶
| Name | Type | Optional | Description |
|---|---|---|---|
name | str | ❌ | Name of the model to be stored in the database. |
n_cluster | int | ✓ | Number of clusters |
bisection_iterations | int | ✓ | The number of iterations the bisecting k-means algorithm performs for each bisection step. This corresponds to how many times a standalone k-means algorithm runs in each bisection step. A value greater than 1 allows the algorithm to run and choose the best k-means run within each bisection step. Note that if you are using the kmeanspp function, the bisection_iterations value is always 1 because kmeanspp is more both more reliable and expensive, so it only needs to be run once. |
split_method | str | ✓ | The method used to choose a cluster to bisect/split.
|
min_divisible_cluster_size | int | ✓ | The minimum number of points of a divisible cluster. Must be greater than or equal to 2. |
distance_method | str | ✓ | The measure for distance between two data points. Only Euclidean distance is supported at this time. |
init | str / list | ✓ | The method to use to find the initial cluster centers.
|
max_iter | int | ✓ | The maximum number of iterations the algorithm performs. |
tol | float | ✓ | Determines whether the algorithm has converged. The algorithm is considered converged when no center has moved more than a distance of 'tol' from the previous iteration. |
Attributes¶
After the object is created, all parameters become attributes. Additional attributes will be created when fitting the model:
| Name | Type | Description |
|---|---|---|
cluster_centers_ | tablesample | Clusters result of the algorithm. |
metrics_ | tablesample | Metrics with which to evaluate the model. |
input_relation | str | The training relation. |
X | list | List of the predictors. |
Methods¶
| Name | Description |
|---|---|
| deploySQL | Returns the SQL code needed to deploy the model. |
| drop | Drops the model from the Vertica database. |
| fit | Trains the model. |
| get_attr | Returns the model attribute. |
| get_params | Returns the model parameters. |
| plot | Draws the k-means clusters. |
| plot_tree | Draws the input BKtree. |
| predict | Predicts using the input relation. |
| set_params | Sets the parameters of the model. |
| to_graphviz | Returns the code for a Graphviz tree. |
| to_memmodel | Converts a specified Vertica model to a memModel model. |
| to_python | Returns the Python code needed to deploy the model without using built-in Vertica functions. |
| to_sql | Returns the SQL code needed to deploy the model without using Vertica built-in functions. |
Example¶
In [24]:
from verticapy.learn.cluster import BisectingKMeans
model = BisectingKMeans(name = "public.bkmeans_iris",
n_cluster = 8,
init = "kmeanspp",
max_iter = 300,
tol = 1e-4)
display(model)
