openGauss DB4AI
Tags: opengauss
Published: 2023-03-09 07:42:50

The current version of openGauss supports the native DB4AI capability. By introducing native AI operators, openGauss simplifies the operation process and fully utilizes the optimization and execution capabilities of the database optimizer and executor to obtain the high-performance model training capability in the database. With a simpler model training and prediction process and higher performance, developers can focus on model tuning and data analysis in a shorter period of time, avoiding fragmented technology stacks and redundant code implementation.

DB4AI of the current version supports logistic regression (binary classification tasks), linear regression, and vector machine algorithms (classification tasks) based on the SGD operator, as well as the K-Means clustering algorithm based on the K-Means operator.

Usage Guide
You can run the CREATE MODEL statement to create and train a model.

Taking dataset kmeans_2d as an example, the data content of the table is as follows:

""
openGauss=# select * from kmeans_2d;
 id |              position
----+-------------------------------------
  1 | {74.5268815685995,88.2141939294524}
  2 | {70.9565760521218,98.8114827475511}
  3 | {76.2756086327136,23.8387574302033}
  4 | {17.8495847294107,81.8449544720352}
  5 | {81.2175785354339,57.1677675866522}
  6 | {53.97752255667,49.3158342130482}
  7 | {93.2475341879763,86.934042100329}
  8 | {72.7659293473698,19.7020415100269}
  9 | {16.5800288529135,75.7475957670249}
 10 | {81.8520747194998,40.3476078575477}
 11 | {76.796671198681,86.3827232690528}
 12 | {59.9231450678781,90.9907738864422}
 13 | {70.161884885747,19.7427458665334}
 14 | {11.1269539105706,70.9988166182302}
 15 | {80.5005071521737,65.2822235273197}
 16 | {54.7030725912191,52.151339428965}
 17 | {103.059707058128,80.8419883321039}
 18 | {85.3574452036992,14.9910179991275}
 19 | {28.6501615960151,76.6922890325077}
 20 | {69.7285806713626,49.5416352967732}
(20 rows)
The data type of the position field in this table is double precision[].

Specify position as a feature column in the kmeans_2d training set, and use the K-Means algorithm to create and save the point_kmeans model.

""
openGauss=# CREATE MODEL point_kmeans USING kmeans FEATURES position FROM kmeans_2d WITH num_centroids=3;
NOTICE:  Hyperparameter max_iterations takes value DEFAULT (10)
NOTICE:  Hyperparameter num_centroids takes value 3
NOTICE:  Hyperparameter tolerance takes value DEFAULT (0.000010)
NOTICE:  Hyperparameter batch_size takes value DEFAULT (10)
NOTICE:  Hyperparameter num_features takes value DEFAULT (2)
NOTICE:  Hyperparameter distance_function takes value DEFAULT (L2_Squared)
NOTICE:  Hyperparameter seeding_function takes value DEFAULT (Random++)
NOTICE:  Hyperparameter verbose takes value DEFAULT (0)
NOTICE:  Hyperparameter seed takes value DEFAULT (0)
MODEL CREATED. PROCESSED 1
In the preceding command:

The CREATE MODEL statement is used to train and save a model.

USING specifies the algorithm name.

FEATURES specifies the features of the training model and needs to be added based on the column name of the training data table.

TARGET specifies the training target of the model. It can be the column name of the data table required for training or an expression, for example, price > 10000.

WITH specifies the hyperparameters used for model training. When the hyperparameters are not set by the user, the framework uses the default value.