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

> Start creating your model.

# Register model

The SuperAlign model registry provides a centralized location for users to store their models and manage their lifecycle collaboratively. This makes it easier for stakeholders to manage models and promotes transparency in accessing models for tests, deployment, audit, and other purposes.

With SuperAlign, you can manage your models in the following ways:

* Create models to track and assess their relevance using generic model data.
* Automatically version models to efficiently organize model runs. SuperAlign logs model parameters, metrics, and other metadata that changes for each registered model.
* Fetch stored models and their metadata through our API.

By using the SuperAlign model registry, you can streamline your model management processes and facilitate collaboration among your team members. This allows for greater efficiency, transparency, and accuracy in managing your models.

### Creating Models

With the SuperAlign model module, you can perform a variety of actions related to creating and managing models. Here's an overview of the available methods:

Creating a Model To create a new model, import the pureml module and use the `model.init` method:

```python theme={null}
import pureml

pureml.model.init(label='FirstModel', readme='ReadME.md')
```

The name of the model to be created are required parameters. You can also provide an optional readme file path.

<Info>
  **label** parameter consists of model name in the following format:

  `_\<name>:\<version>_`

  For initializing a model, *version* is not required. So, we use *\<name>:* as the label.
</Info>

<Warning>
  **label** should not contain any spaces. Special characters other than "**-**"
  and "**\_**" are not allowed.
</Warning>

<Note>
  Created a model? No? [Create one
  now](/core-concepts/register-model#creating-models). Yes? Here's what you
  should do next.
</Note>

## Register Models

SuperAlign assists you with creating, training, and tracking all of your machine learning project information, including ML models and datasets, using semantic versioning and full artifact logging.

This short tutorial will show you how to register and track machine learning models using SuperAlign.

```bash theme={null}
pip install pureml
pip install xgboost
```

```python theme={null}
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import xgboost as xgb
import pandas as pd
import pureml
from pureml.decorators.model import model
```

## Train and Register your Model Version

We will train a `XGBClassifier` to predict the classes of samples from `Iris dataset` in this tutorial. This is a straightforward training function that returns the trained model and prints the `accuracy` of our model. We will utilize the `Iris` data from sklearn.

```python theme={null}
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
```

```python theme={null}
def train():
  xgb_model = xgb.XGBClassifier()
  xgb_model.fit(X_train, y_train)
  predictions = xgb_model.predict(X_test)

  acc = accuracy(y_test, predictions)
  print("accuracy: ", acc)

  return xgb_model

xgb_model = train()
```

## Now let's register our model to pureml

To register the model, add the `@model` decorator to the training function. SuperAlign will register the returned trained model to your SuperAlign project.

Let's also replace `print()` with `pureml.log()` to register obtained model metrics to the project.

```python theme={null}
@model('iris_classifier')
def train():
    xgb_model = xgb.XGBClassifier()
    xgb_model.fit(X_train, y_train)
    predictions = xgb_model.predict(X_test)

    acc = accuracy(y_test, predictions)

    pureml.log(metrics={'accuracy':acc})
    print("accuracy: ", acc)

    return xgb_model

xgb_model = train()
```

## Fetching a Model

Once you register your model to SuperAlign, you can load the model from SuperAlign using `model` module.

Let's look at how to load and generate predictions with your model:

```python theme={null}
import pureml

model = pureml.model.fetch('iris_clasifier')
X, y = load_iris(return_X_y=True)
preds = model.predict(X)
```

By default, `fetch` method fetches `latest` version of the model. A particular `version` of a model can be fetched by providing version parameter as the following.

```python theme={null}
model = pureml.model.fetch('iris_classifier:v3')
```

Here, we have fetched the version `v3` of the model `iris_classifier`.

```python theme={null}
print('Prediction: ', preds[0])
```

## Listing Models

To list all available models, use the `model.list` method:

```python theme={null}
import pureml

pureml.model.list()
```

These methods make it easy to create and manage the models in SuperAlign. By using them, you can streamline your model management workflows and improve collaboration among team members.
