> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ocient.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Machine Learning Model Functions

export const OcientML = "OcientML™";

{OcientML} functionality supports these SQL functions for machine learning models.

<Info>
  The scope of a machine learning model is the schema.
</Info>

## Supported Machine Learning Models

Supported machine learning models and reference material are divided into these categories.

<Info>
  For functions to help organize data before training a model, see [Data Preparation](/data-preparation).
</Info>

#### Regression Models

* [Simple Linear Regression](/regression-models#simple-linear-regression)
* [Multiple Linear Regression](/regression-models#multiple-linear-regression)
* [Vector Autoregression](/regression-models#vector-autoregression)
* [Polynomial Regression](/regression-models#polynomial-regression)
* [Linear Combination Regression](/regression-models#linear-combination-regression)
* [Nonlinear Regression](/regression-models#nonlinear-regression)
* [Gradient Boosted Trees](/regression-models#gradient-boosted-trees)
* [Regression Tree](/regression-models#regression-tree)

#### Classification Models

* [K Nearest Neighbor Classification](/classification-models#k-nearest-neighbors-classification)
* [Naive Bayes Classification](/classification-models#naive-bayes-classification)
* [Decision Tree](/classification-models#decision-tree)
* [Random Forest](/classification-models#random-forest)
* [Logistic Regression](/classification-models#logistic-regression)
* [Support Vector Machine](/classification-models#support-vector-machine)
* [Gradient Boosted Trees](/classification-models#execute-the-model-6)

#### Clustering and Dimension Reduction Models

* [Principal Component Analysis](/clustering-and-dimension-reduction-models#principal-component-analysis)
* [K-Means Clustering](/clustering-and-dimension-reduction-models#k-means-clustering)
* [Gaussian Mixture](/clustering-and-dimension-reduction-models#gaussian-mixture)
* [Linear Discriminant Analysis](/clustering-and-dimension-reduction-models#linear-discriminant-analysis)

#### Ensemble Models

* [Bagging](/ensemble-models#bagging)
* [Boosting](/ensemble-models#boosting)
* [Stacking](/ensemble-models#stacking)

#### Other Models

* [Association Rules](/other-models#association-rules)
* [Feedforward Neural Network](/other-models#feedforward-neural-network)

For a view of the full list of model options, see [Machine Learning Model Options](/machine-learning-model-options).

## Execute a Query Using a Machine Learning Model

To create a machine learning model and manage the model, see [Machine Learning Models](/machine-learning-models) for the corresponding syntax. After you create the model, you can execute a query using the model with this syntax.

**Syntax**

```sql SQL theme={null}
SELECT model_name ( expression [, ... ] ) FROM table_reference
```

| **Parameter**     | **Data Type**                             | **Description**                                                                                                                                                                                                                                                                                                                                   |
| ----------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model_name`      | identifier                                | The name of a machine learning model created using a `CREATE MODEL` SQL statement. The model name must be a valid identifier and reference an existing trained model.                                                                                                                                                                             |
| `expression`      | identifier<br />string<br />numeric<br /> | One or more expressions that serve as input features for the machine learning model evaluation. These expressions must match the expected input schema the model was trained on. <br /><br />Expressions can be any combination of literal values, column names, arithmetic expressions, and function invocations, with parentheses for grouping. |
| `table_reference` | identifier                                | The name of a table, view, or subquery that provides the data for model evaluation. The table must contain columns or computed expressions that match the expected input features of the model.                                                                                                                                                   |

**Example**

Create a table with data for the model.

```sql SQL theme={null}
CREATE TABLE mldemo.mlr AS (SELECT a.c1 AS x1, b.c1 AS x2, 1 + 2*a.c1 + 3*b.c1 AS y
    FROM sys.dummy10 a, sys.dummy10 b);
Modified 100 rows
```

Create a multiple linear regression model based on the data.

```sql SQL theme={null}
CREATE MLMODEL mlr_model TYPE MULTIPLE LINEAR REGRESSION ON (SELECT * FROM mldemo.mlr)
options('metrics' -> 'true');
Modified 0 rows
```

Execute a `SELECT` query against the multiple linear regression to see the actual and predicted values. Limit the result set to 10 rows.

```sql SQL theme={null}
SELECT x1, x2, y AS actual, mlr_model(x1, x2) AS predicted
    FROM mldemo.mlr
    LIMIT 10;
```

*Output*

```none Text theme={null}
x1         x2         actual              predicted
----------------------------------------------------------------
6          1          16                  15.999999999999975
6          2          19                  18.999999999999975
6          3          22                  21.999999999999975
6          4          25                  24.999999999999975
6          5          28                  27.999999999999975
6          6          31                  30.999999999999975
6          7          34                  33.99999999999997
6          8          37                  36.99999999999997
6          9          40                  39.99999999999997
6          10         43                  42.99999999999997

Fetched 10 rows
```

## Related Links

[Machine Learning in Ocient](/machine-learning-in-ocient)

[Machine Learning Models](/machine-learning-models)
