---
title: Machine Learning Models
slug: oz_G-machine-learning-models
docTags: 
createdAt: Thu Mar 13 2025 12:58:26 GMT+0000 (Coordinated Universal Time)
updatedAt: Fri Apr 10 2026 21:22:13 GMT+0000 (Coordinated Universal Time)
---

OcientML™ functionality enables you to create a machine learning model, rename the model, export the syntax for the model creation, retrain the model, execute a query against the model, and drop the model.

# CREATE MLMODEL

Train a new machine learning model of type `<model type>` on the result set returned by the SQL SELECT statement. After the database creates the model, `<model name>` becomes a callable function in SQL SELECT statements. 

**Syntax**

```sql
CREATE [ OR REPLACE ] MLMODEL <model_name> TYPE <model_type> 
    ON( <SQL SELECT statement> ) [options(<option_list>)]
```

### model\_name

| **Parameter** | **Data** **Type** | **Description**                  |
| ------------- | ----------------- | -------------------------------- |
| `model name`  | `VARCHAR`         | The name of the model to create. |

### model\_type

| **Parameter** | **Data** **Type** | **Description**                                |
| ------------- | ----------------- | ---------------------------------------------- |
| `model type`  | `VARCHAR`         | The type of machine learning model to create.  |

These models are supported. You can find full descriptions of each model in [Regression Models](<././Machine Learning Model Functions/Regression Models.md>), [Classification Models](<././Machine Learning Model Functions/Classification Models.md>), [Clustering and Dimension Reduction Models](<././Machine Learning Model Functions/Clustering and Dimension Reduction Models.md>), [Ensemble Models](<././Machine Learning Model Functions/Ensemble Models.md>), or [Other Models](<././Machine Learning Model Functions/Other Models.md>).&#x20;

- `SIMPLE LINEAR REGRESSION`
- `MULTIPLE LINEAR REGRESSION`
- `POLYNOMIAL REGRESSION`
- `LINEAR COMBINATION REGRESSION`
- `VECTOR AUTOREGRESSION`
- `KMEANS`
- `KNN (K Nearest Neighbors)`
- `LOGISTIC REGRESSION`
- `NAIVE BAYES`
- `NONLINEAR REGRESSION`
- `FEEDFORWARD NETWORK`
- `PRINCIPAL COMPONENT ANALYSIS`
- `LINEAR DISCRIMINANT ANALYSIS`
- `SUPPORT VECTOR MACHINE`
- `DECISION TREE`
- `GAUSSIAN MIXTURE MODEL`
- `ASSOCIATION RULES`
- `GRADIENT BOOSTED TREES`
- `REGRESSION TREE`
- `BAGGING`
- `BOOSTING`&#x20;
- `STACKING`

### option\_list

| **Parameter** | **Data** **Type** | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------- | ----------------- |   |
| `option_list` | `VARCHAR`         | The options for the specified machine learning model that is specified as a comma-separated list in the format: `<option name 1> -> <value 1>, <option name 2> -> <value 2>`, and so on. Names and values must be all enclosed in single quotes and are case sensitive with the exception that Boolean values can be `true`, `false`, `TRUE`, or `FALSE`. Refer to the respective model for the full options list. <br />Example options list:&#xA;`options(`<br />`  'yIntercept' -> '10',`<br />`  'metrics' -> 'true'`<br />`)` |

The SQL SELECT statement that serves as the basis for the model must return rows that fit the specified requirements of the model. For example, in multiple linear regression, the first N columns are the independent variables, and the last column is the dependent variable.

:::hint{type="info"}
You cannot create a machine learning model with an existing schema and name combination.
:::

**Example**

Assume you created the `mldata` table that contains the data for the model. Then, you can create the `my_model` machine learning model based on that data.

```sql
CREATE MLMODEL my_model
TYPE SIMPLE LINEAR REGRESSION ON (
  SELECT
    x1,
    y
  FROM mldata
)
options(
  'yIntercept' -> '10',
  'metrics' -> 'true'
);
```

# ALTER MLMODEL RENAME

Rename a machine learning model. Use the `IF EXISTS` clause to ignore any models that do not exist.

**Required Privileges**

To rename a view, you must have the `ALTER MLMODEL` privilege for the model.

The Ocient® System requires these privileges if this statement includes a change to the schema:

- `VIEW` privilege on the current schema of the model
- `VIEW MLMODEL` and `CREATE MLMODEL` privileges on the target schema (if the schema already exists)
- `CREATE MLMODEL` privilege on the database (if the schema does not exist)

**Syntax**

```sql
ALTER MLMODEL [IF EXISTS] <model name> RENAME TO <new model name>
```

| **Parameter**    | **Data** **Type** | **Description**                  |
| ---------------- | ----------------- | -------------------------------- |
| `model name`     | `VARCHAR`         | The name of the model to rename. |
| `new model name` | `VARCHAR`         | The new name of the model.       |

**Example**

```sql
ALTER MLMODEL my_model RENAME TO my_model_slr;
```

# DROP MLMODEL

Drop a machine learning model. Use the `IF EXISTS` clause to ignore any models that do not exist.

**Syntax**

```sql
DROP MLMODEL [IF EXISTS] model_name [, ...]
```

| **Parameter** | **Data** **Type** | **Description**                                                                                                                   |
| ------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `model name`  | `VARCHAR`         | The name of the model to drop.<br />You can drop multiple models by specifying additional names and separating each with commas.  |

**Example**

Drop the machine learning model `my_model`.

```sql
DROP MLMODEL my_model;
```

Drop multiple machine learning models.

```sql
DROP MLMODEL my_model1, my_model2;
```

# EXPORT MLMODEL

Return the SQL statement that can recreate the machine learning model.

**Syntax**

```sql
EXPORT MLMODEL <model name>
```

| **Parameter** | **Data** **Type** | **Description**                  |
| ------------- | ----------------- | -------------------------------- |
| `model name`  | `VARCHAR`         | The name of the model to create. |

**Example**

```sql
EXPORT MLMODEL my_model;
```

*Output*

```sql
export                                       
---------------------------------------------
CREATE MLMODEL "my_schema"."my_model" TYPE simple linear regression ON(select x, y from mldemo.slr) OPTIONS('metrics' -> 'false'); 

Fetched 1 row
```

The output SQL statement includes the schema explicitly.

# REFRESH MLMODEL

Retrain a machine learning model without changing any model options.

**Syntax**

```sql
REFRESH MLMODEL <model name>
```

| **Parameter** | **Data** **Type** | **Description**                   |
| ------------- | ----------------- | --------------------------------- |
| `model name`  | `VARCHAR`         | The name of the model to retrain. |

**Example**

```sql
REFRESH MLMODEL my_model;
```

# Related Links

[Machine Learning in Ocient](<./././Analysis in Ocient/Machine Learning in Ocient.md>)&#x20;

[Machine Learning Model Functions](<././Machine Learning Model Functions.md>)&#x20;

[Regression Models](<././Machine Learning Model Functions/Regression Models.md>)&#x20;

[Classification Models](<././Machine Learning Model Functions/Classification Models.md>)&#x20;

[Clustering and Dimension Reduction Models](<././Machine Learning Model Functions/Clustering and Dimension Reduction Models.md>)&#x20;

[Other Models](<././Machine Learning Model Functions/Other Models.md>)&#x20;

