Creating a Model

Create and then train a model in Anomaly Detection.

  • You can create the model in an existing project or create a project for it.

    1. Open the navigation menu and click Analytics & AI. Under AI Services, click Anomaly Detection.
    2. In the left-side navigation menu, click Projects.
    3. Select the compartment that contains the project that you want to use, or select the compartment that you want to create a project in.
    4. Perform one of the following actions:
      1. To use an existing project, click its name.
      2. To create a new project, click Create Project.
    5. On the project's details page, click Create and train model.
    6. Select an existing data asset if any exist or click Create a new data asset.
    7. Click Next.
    8. On the Train model page, select the compartment to create the model in, and then enter an optional name and description for the model. If you don't provide a name, one is automatically generated.
    9. For Target false alarm probability(FAP), specify a value 0 to 0.05.

      FAP indicates model performance. Lower FAP indicates better model performance.

    10. For Training fraction ratio, specify a value 0.5 to 0.8.

      Training fraction ratio indicates the split ratio between training data and validation data.

    11. (Optional) For Algorithm Hint, specify one of the hints to know what type of algorithm the model uses.
    12. Perform one of the following actions:
      1. To set the Window size, click Automatic window size, and then specify a value 1 to 100.
      2. Let the service set the window size, click Automatic window size.
    13. (Optional) Click Show advanced options to assign tags to the resource. Tags help you to easily find and track resources by selecting a tag namespace, and then entering the key and value.

      To add more than one tag, click Add tag.

      Tagging describes the various tags that you can use organize and find resources including cost-tracking tags.

    14. Click Next.
    15. Review the training data and model information. Use Previous to make any changes, and then return to the Review panel.
    16. Click Create and train.
      Training a model can take awhile. The page is automatically refreshed every 20 seconds.
    1. Download and configure OCI CLI or SDK as described in existing OCI documentation.
    2. As an authenticated user, upload a .csv or .json file with training data to Object Storage in a tenancy.
    3. Use the CLI or SDK create the train work request, with the path to the object store.
    4. As an authenticated user make the HTTP work request to train.
    5. Check the status of the training request by periodically querying the work request.

      When of the training request completes, the response contains the model detection endpoint.

    6. To use this trained model, create an HTTP POST request and make the request to the endpoint received in the previous step.
    7. Parse the HTTP response to get the results for use in applications.

    Example API Calls

    You can use the following Anomaly Detection service API calls to help you to create and train models.

    1. Create an AI project:

      Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/projects
       Method: POST
       Body:
           {
                   "displayName":"Test Anomaly Detection",
                   "compartmentId": "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrr…..jpbdfmcjmzdufz6sy52pra",
                   "description" : "PROJECT FOR ANOMALY DETECTION"
           }
    2. Create a data assets, which assumes that the data is already in OCI Object Storage:

      Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/dataAssets
          Method: POST
          Body:
              {
             "displayName" : "sample dataAsset",
             "compartmentId" : "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrrbl…..pbdfmcjmzdufz6sy52pra",
             "projectId" : "ocid1.aiproject.oc1.iad.amaaaaaaor7l3jiauulbiu5dtqga….eksq3ophqwxsiyuf4q",
             "description" : "oracle object storage data asset",
             "dataSourceDetails" :
                {
                   "dataSourceType" : "ORACLE_OBJECT_STORAGE",
                   "bucketName" : "mset_service_model_storage",
                   "namespace" : "namespace_bucket",
                   "objectName" : "ValidTrainingData.json"
                }
              }
    3. Train the model.

      • Univariate Model Example

        Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/models
         Method: POSTBody:{
            "compartmentId": "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrrb…..rcmjpbdfmcjmzdufz6sy52pra",
            "displayName": "ashburn_data_center",
            "description": "Ashburn Data center model",
            "projectId": "ocid1.aianomalydetectionproject.oc1.phx.amaaaaaaukxuveqahqmhksgwsdf5w7unr75nrk4cevclqitd6nkroltlr34q",
            "modelTrainingDetails":
            {
                "targetFap": 0.05,
                "trainingFraction": 0.7,
                "algorithmHint": "UNIVARIATE_OCSVM",
                "dataAssetIds":
                [
                    "ocid1.aianomalydetectiondataasset.oc1.phx.amaaaaaaukxuveqaun27l3qyrcdz5bofrezezf6sivlhk6kxhnj6dnkzqyea"
                ]
            }
        }
      • Multivariate Model Example

        Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/models
         Method: POST
         Body:{
            "compartmentId": "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrrb…..rcmjpbdfmcjmzdufz6sy52pra",
            "displayName": "ashburn_data_center",
            "description": "Ashburn Data center model",
            "projectId": "ocid1.aianomalydetectionproject.oc1.phx.amaaaaaaukxuveqahqmhksgwsdf5w7unr75nrk4cevclqitd6nkroltlr34q",
            "modelTrainingDetails":
            {
                "targetFap": 0.05,
                "trainingFraction": 0.7,
                "algorithmHint": "MULTIVARIATE_MSET",
                "dataAssetIds":
                [
                    "ocid1.aianomalydetectiondataasset.oc1.phx.amaaaaaaukxuveqaun27l3qyrcdz5bofrezezf6sivlhk6kxhnj6dnkzqyea"
                ]
            }
  • We recommend this approach to create and train anomaly detection models into existing applications to implement in production.

    1. Download and configure OCI CLI or SDK as described in existing OCI documentation.
    2. As an authenticated user, upload a .csv or .json file with training data to Object Storage in a tenancy.
    3. Use the CLI or SDK create the train work request, with the path to the object store.
    4. As an authenticated user make the HTTP work request to train.
    5. Check the status of the training request by periodically querying the work request.

      When of the training request completes, the response contains the model detection endpoint.

    6. To use this trained model, create an HTTP POST request and make the request to the endpoint received in the previous step.
    7. Parse the HTTP response to get the results for use in applications.

    Example API Calls

    You can use the following Anomaly Detection service API calls to help you to create and train models.

    1. Create an AI project:

      Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/projects
       Method: POST
       Body:
           {
                   "displayName":"Test Anomaly Detection",
                   "compartmentId": "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrr…..jpbdfmcjmzdufz6sy52pra",
                   "description" : "PROJECT FOR ANOMALY DETECTION"
           }
    2. Create a data assets, which assumes that the data is already in OCI Object Storage:

      Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/dataAssets
          Method: POST
          Body:
              {
             "displayName" : "sample dataAsset",
             "compartmentId" : "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrrbl…..pbdfmcjmzdufz6sy52pra",
             "projectId" : "ocid1.aiproject.oc1.iad.amaaaaaaor7l3jiauulbiu5dtqga….eksq3ophqwxsiyuf4q",
             "description" : "oracle object storage data asset",
             "dataSourceDetails" :
                {
                   "dataSourceType" : "ORACLE_OBJECT_STORAGE",
                   "bucketName" : "mset_service_model_storage",
                   "namespace" : "namespace_bucket",
                   "objectName" : "ValidTrainingData.json"
                }
              }
    3. Train the model.

      • Univariate Model Example

        Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/models
         Method: POSTBody:{
            "compartmentId": "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrrb…..rcmjpbdfmcjmzdufz6sy52pra",
            "displayName": "ashburn_data_center",
            "description": "Ashburn Data center model",
            "projectId": "ocid1.aianomalydetectionproject.oc1.phx.amaaaaaaukxuveqahqmhksgwsdf5w7unr75nrk4cevclqitd6nkroltlr34q",
            "modelTrainingDetails":
            {
                "targetFap": 0.05,
                "trainingFraction": 0.7,
                "algorithmHint": "UNIVARIATE_OCSVM",
                "dataAssetIds":
                [
                    "ocid1.aianomalydetectiondataasset.oc1.phx.amaaaaaaukxuveqaun27l3qyrcdz5bofrezezf6sivlhk6kxhnj6dnkzqyea"
                ]
            }
        }
      • Multivariate Model Example

        Endpoint: https://anomalydetection.aiservice.us-phoenix-1.oci.oraclecloud.com/20210101/models
         Method: POST
         Body:{
            "compartmentId": "ocid1.compartment.oc1..aaaaaaaaaqf4b7xq6kxrrb…..rcmjpbdfmcjmzdufz6sy52pra",
            "displayName": "ashburn_data_center",
            "description": "Ashburn Data center model",
            "projectId": "ocid1.aianomalydetectionproject.oc1.phx.amaaaaaaukxuveqahqmhksgwsdf5w7unr75nrk4cevclqitd6nkroltlr34q",
            "modelTrainingDetails":
            {
                "targetFap": 0.05,
                "trainingFraction": 0.7,
                "algorithmHint": "MULTIVARIATE_MSET",
                "dataAssetIds":
                [
                    "ocid1.aianomalydetectiondataasset.oc1.phx.amaaaaaaukxuveqaun27l3qyrcdz5bofrezezf6sivlhk6kxhnj6dnkzqyea"
                ]
            }