Build a Model Using Logistic Regression

Introduction

This article describes how to build and test a recommendation model using the Logistic Regression algorithm in Fortanix Confidential AI.

Prerequisites

  • An S3 bucket with encrypted data already uploaded.
  • A user signed in to a Confidential AI account.
  • Prepare your S3 bucket for Confidential AI. 

For instructions on how to sign up and log in, refer to our User’s guide: Sign up for Confidential AI.

For instructions on how to prepare your S3 bucket, refer to the User’s Guide: Prepare your S3 Bucket.

Building the Model

Data Ingestion

  1. On the Data Ingestion page, click CREATE DATASET, and select CSV Dataset.
  2. Dataset name - Enter a name for your dataset. 
  3. Select the S3 URL option to bring your data by connecting to an S3 account.
  4. S3 bucket URL: Enter the URL of the S3 location, for example, s3://mybucket/some-dir/infile.csv.enc
    In the above URL:
    • mybucket is the bucket name and
    • some-dir/infile.csv.enc is the path
  5. Access Key ID and Secret Key: Enter the Access Key ID and the Secret Key for Confidential AI to be able to access the data on your S3 bucket.
  6. Encryption key (optional): Enter the encryption key that was used to encrypt the file on your S3 bucket (User’s Guide: Prepare your S3 Bucket).
  7. Click RETRIEVE to save the S3 details and retrieve your data.
  8. To track what the data is used for; you can optionally add Labels in the form of “Key:Value” pairs.
  9. Click CREATE DATASET to save the data.
  10. You will now see the saved dataset in the dataset table. CAI_LR_S3upload.png CAI_LR_S3upload1.pngFigure 1: S3 details

Data Preparation

In this phase, you can choose the column names as a set of features and a target for the tabular dataset. You can choose multiple combinations of features and targets (collectively called Variables).

  1. In the Data Preparation page, click ADD VARIABLES to select the features and target. CAI_LR_AddVariables.pngFigure 2: Add variables
  2. Select one or more features from the SET A FEATURE column and select one target from the SET A TARGET column.
  3. Click ADD to add the variables. CAI_LR_Addfeatures.pngCAI_LR_Addfeatures1.pngFigure 3: Select the features and target
  4. Click SAVE to save the variables and proceed to the next phase, that is, build a model. CAI_LR_SaveVariables.pngFigure 4: Variables added

Build Model

In the build a model stage, you can select the Logistic Regression algorithm to run on the dataset defined in the previous phases, to analyze and build AI models.

In the “Build a Model” form:

  1. Select the BUILD A MODEL tab and click BUILD MODEL to build a training model for the dataset created in the previous phase. 
  2. Enter the Training flow name, that is, the name of the model.
  3. In the Training Dataset field, select the training dataset on which you want to run the Logistic Regression algorithm and build a trained model.
  4. In the Algorithm field, select the Logistic Regression algorithm.
  5. Select ML variables that you created in the Data Preparation phase.
  6. In the Model name field, enter the name of the output dataset. This is the output model that will be used in the data inference phase.
  7. Click BUILD MODEL to run the selected algorithm on the training data and build the model for inference. CAI_LR_BuildModel.pngFigure 5: Build a model
  8. After the training model is built, you will see the model created under the Training flows. To run the training model, click the RUN button below the model.
    CAI_LR_RunModel.pngFigure 6: Run training model
  9. If the model was executed successfully, you would see the status of the execution under the Execution Log. Click the Execution log link to view the log details. CAI_LR_BuildSuccess.pngFigure 7: Model training success
  10. Click the download report icon to download the execution log report. CAI_LR_BuildLog1.pngFigure 8: Execution log
  11. After the execution is completed successfully, the model is now trained and ready for inference where it will be passed through a machine learning model for output data prediction.

Data Inference

In this stage, the data is passed through a machine learning model to identify and predict the output from the data.

  1. In the INFERENCE tab, click BUILD INFERENCE to predict the data output.
  2. In the Build Inference form, enter the Inference flow name, that is, the name of the inference model.
  3. In the Input dataset field, select the training dataset that you created in the first stage that you want to pass through a machine learning model.
  4. In the Algorithm field, select the prediction algorithm.
  5. In the Model field, select the trained model that was built in the “build a model” stage.
  6. In the Output Configuration field, enter the name of the output dataset that will contain the predicted output.
  7. The output dataset will be encrypted; hence Encrypt Dataset is enabled to add an extra layer of protection to the output data. Copy or download the encryption key to decrypt the output data for viewing.
  8. Click CREATE INFERENCE FLOW to pass the data through a machine learning model and predict the output. CAI_LR_BuildInference.pngFigure 9: Build inference
  9. The inference is successfully created. Click RUN below the inference workflow to run the model and predict the output. CAI_LR_RunInference.pngFigure 10: Run inference
  10. If the model was executed successfully, you would see the status of the execution under the Execution Log. Click the Execution Log link to view the log details. CAI_LR_InferenceSuccess.pngFigure 11: Inference success
  11. After the execution is completed successfully, the output is now predicted and ready to be viewed. To view the output, click the DOWNLOAD button. CAI_LR_InferenceOutput.pngFigure 12: Download output
  12. In the DOWNLOAD dialog box, enter the Encryption key to decrypt the output. CAI_DecryptionKey.pngFigure 13: Decrypt output
  13. A *.tar.gz file is downloaded to your local machine. Extract the contents of the file. A snapshot of the output appears as shown below.
    Output.png
    Figure 14: Sample output

Comments

Please sign in to leave a comment.

Was this article helpful?
0 out of 0 found this helpful