vastorbit.machine_learning.vast.cluster.DBSCAN¶
- class vastorbit.machine_learning.vast.cluster.DBSCAN(name: str = None, overwrite_model: bool = False, eps: float = 0.5, min_samples: int = 5, p: int = 2)¶
[Beta Version] Creates a DBSCAN object by using the DBSCAN algorithm as defined by Martin Ester, Hans-Peter Kriegel, Jörg Sander, and Xiaowei Xu. This object uses pure SQL to compute the distances and neighbors, and uses Python to compute the cluster propagation (non-scalable phase).
Warning
This algorithm uses a CROSS JOIN during computation and is therefore computationally expensive at O(n * n), where n is the total number of elements. This algorithm indexes elements of the table in order to be optimal (the CROSS JOIN will happen only with IDs which are integers). Since DBSCAN uses the p-distance, it is highly sensitive to unnormalized data. However, DBSCAN is robust to outliers and can find non-linear clusters. It is a very powerful algorithm for outlier detection and clustering. A table is created at the end of the learning phase.
Important
This algorithm is not VAST Native and relies solely on SQL for attribute computation. While this model does not take advantage of the benefits provided by a model management system, including versioning and tracking, the SQL code it generates can still be used to create a pipeline.
- Parameters:
name (str, optional) – Name of the model. This is not a built-in model, so this name is used to build the final table.
overwrite_model (bool, optional) – If set to
True, training a model with the same name as an existing model overwrites the existing model.eps (float, optional) – The radius of a neighborhood with respect to some point.
min_samples (int, optional) – Minimum number of points required to form a dense region.
p (int, optional) – The p of the p-distance (distance metric used during the model computation).
- Variables:
created (Many attributes are)
phase. (during the fitting)
n_clusters_ (int) – Number of clusters.
p_ (int) – The
pof thep-distances.n_noise_ (int) – Number of outliers.
note:: (..) – All attributes can be accessed using the
get_attributes()method.
Examples
The following examples provide a basic understanding of usage. For more detailed examples, please refer to the Machine Learning or the Examples section on the website.
Load data for machine learning¶
We import
vastorbit:import vastorbit as vo
Hint
By assigning an alias to
vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions fromvastorbitare used as intended without interfering with functions from other libraries.For this example, we will create a small dataset.
data = vo.VastFrame({"col":[1.2, 1.1, 1.3, 1.5, 2, 2.2, 1.09, 0.9, 100, 102]})
Note
vastorbit offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the vastorbit environment.
Model Initialization¶
First we import the
DBSCANmodel:from vastorbit.machine_learning.vast import DBSCAN
Then we can create the model:
model = DBSCAN( eps = 0.5, min_samples = 2, p = 2, )
Important
As this model is not native, it solely relies on SQL statements to compute various attributes, storing them within the object. No data is saved in the database.
Model Training¶
We can now fit the model:
model.fit(data, X = ["col"])
Important
To train a model, you can directly use the
VastFrameor the name of the relation stored in the database.Hint
For clustering and anomaly detection, the use of predictors is optional. In such cases, all available predictors are considered, which can include solely numerical variables or a combination of numerical and categorical variables, depending on the model’s capabilities.
Important
As this model is not native, it solely relies on SQL statements to compute various attributes, storing them within the object. No data is saved in the database.
Prediction¶
Predicting or ranking the dataset is straight-forward:
model.predict()
123colDecimal(12, 2)123dbscan_clustersInteger1 0.9 0 2 1.09 0 3 2.0 1 4 2.2 1 5 1.5 0 6 1.2 0 7 1.3 0 8 1.1 0 9 100.0 -1 10 102.0 -1 Rows: 1-10 | Columns: 2As shown above, a new column has been created, containing the clusters.
Hint
The name of the new column is optional. If not provided, it is randomly assigned.
Parameter Modification¶
In order to see the parameters:
model.get_params()
And to manually change some of the parameters:
model.set_params({'min_samples': 5})
Model Register¶
As this model is not native, it does not support model management and versioning. However, it is possible to use the SQL code it generates for deployment.
- __init__(name: str = None, overwrite_model: bool = False, eps: float = 0.5, min_samples: int = 5, p: int = 2) None¶
Methods
__init__([name, overwrite_model, eps, ...])contour([nbins, chart])Draws the model's contour plot.
deploySQL([X])Returns the SQL code needed to deploy the model.
drop()Drops the model from the VAST DataBase.
export_models(name, path[, kind])Exports machine learning models.
fit(input_relation[, X, key_columns, index, ...])Trains the model.
get_attributes([attr_name])Returns the model attributes.
get_match_index(x, col_list[, str_check])Returns the matching index.
Returns the parameters of the model.
get_plotting_lib([class_name, chart, ...])Returns the first available library (Plotly, Matplotlib) to draw a specific graphic.
import_models(path[, schema, kind])Imports machine learning models.
plot([max_nb_points, chart])Draws the model.
predict()Creates a
VastFrameof the model.set_params([parameters])Sets the parameters of the model.
Summarizes the model.
to_binary(path)Exports the model to the VAST Binary format.
to_python([return_proba, ...])Returns the Python function needed for in-memory scoring without using built-in VAST functions.
to_sql([X, return_proba, ...])Returns the SQL code needed to deploy the model without using built-in VAST functions.
Attributes