Use case: You want to perform unsupervised machine learning by using a clustering algorithm to classify data.
Unsupervised machine learning is a popular analytical task, often manifested as clustering analysis. This use case illustrates an example of determining clusters in a series of observations . In particular, there are groups of observations on planar coordinates, and this example implements K-Means clustering classification within each group to determine clusters of these observations on the basis of physical proximity. By examining observations in groups, data are partitioned and the example takes advantage of the architectural Database parallelism to scale processing of the operation.
For this task, assume:
- The input data reside in a table "clustData" in the Primary Cluster Database Engine 20.
- The clustering analysis algorithm is in a Python script "clustering.py" stored on the client. The Python script accepts a command line argument that specifies the number of clusters to create from the input data.
Prerequisite steps:
- Connect from the client to a target VantageCloud Lake system where the scoring task is to be performed.
- Specify necessary library imports.
from teradatasqlalchemy.types import VARCHAR
- Specify the path where the script is kept on the client.
path_to_files = '/Users/JaneDoe/OpeanAFexamples/scripts/'
- Create a teradataml DataFrame of the input data table.
clusData = DataFrame.from_table("clustData") - Request a sample of the input data to see each observation has its own identification number (the ObsID column), coordinates X and Y, and belongs to a specific observation group, as shown by the ObsGroup column.
clustData.head(n=5)
Out:
ObsID X Y ObsGroup 3 0.4980191 0.6658911 1 5 0.6932271 0.6899421 1 4 0.7327191 0.2605531 1 2 0.5134201 0.5437281 1 1 0.6621491 0.6830561 1