Tutorial: Create a time series anomaly prediction experiment
Tutorial: Create a time series anomaly prediction experiment This tutorial guides you through using AutoAI and sample data to train a time series experiment to detect if daily electricity usage values are normal or anomalies (outliers). When you set up the sample experiment, you load data that analyzes daily electricity usage from Industry A to determine whether a value is normal or an anomaly. Then, the experiment generates pipelines that use algorithms to label these predicted values as normal or an anomaly. After generating the pipelines, AutoAI chooses the best performers, and presents them in a leaderboard for you to review. Tech preview This is a technology preview and is not yet supported for use in production environments. Data set overview This tutorial uses the Electricity usage anomalies sample data set from the Watson Studio Gallery. This data set describes the annual electricity usages for Industry A. The first column indicates the electricity usages and the second column indicates the date, which is in a day-by-day format. ![A preview of the Electricity usage anomalies sample data](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/autoai-ts-ad-dataset-preview.png) Tasks overview In this tutorial, follow these steps to create an anomaly prediction experiment: 1. [Create an AutoAI experiment](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/autoai-ts-ap-tutorial.html?context=cdpaas&locale=enstep1) 2. [View the experiment](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/autoai-ts-ap-tutorial.html?context=cdpaas&locale=enstep2) 3. [Review experiment results](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/autoai-ts-ap-tutorial.html?context=cdpaas&locale=enstep3) 4. [Deploy the trained model](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/autoai-ts-ap-tutorial.html?context=cdpaas&locale=enstep4) 5. [Test the deployed model](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/autoai-ts-ap-tutorial.html?context=cdpaas&locale=enstep5) Create an AutoAI experiment Create an AutoAI experiment and add sample data to your experiment. 1. From the navigation menu ![Navigation menu](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/images/navigation-menu.svg), click Projects > View all projects. 2. Open an existing project or [create a new project](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/projects.html) to store the anomaly prediction experiment. 3. On the Assets tab from within your project, click New asset > Build machine learning models automatically. 4. Click Samples > Electricity usage anomalies sample data, then select Next. The AutoAI experiment name and description are pre-populated by the sample data. 5. If prompted, associate a Watson Machine Learning instance with your AutoAI experiment. 1. Click Associate a Machine Learning service instance and select an instance of Watson Machine Learning. 2. Click Reload to confirm your configuration. 6. Click Create. View the experiment details AutoAI pre-populates the details fields for the sample experiment: ![Anomaly prediction pre-populated detail fields](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/autoai-ts-ad-details.png) * Type series analysis type: Anomaly prediction predicts whether future values in a series are anomalies (outliers). A prediction of 1 indicates a normal value and a prediction of -1 indicates an anomaly. * Feature column: industry_a_usage is the predicted value and indicates how much electricity Industry A consumes. * Date/Time column: date indicates the time increments for the experiment. For this experiment, there is one prediction value per day. * This experiment is optimized for the model performance metric: Average Precision. Average precision evaluates the performance of object detection and segmentation systems. Click Run experiment to train the model. The experiment takes several minutes to complete. Review the experiment results The relationship map shows the transformations that are used to create pipelines. Follow these steps to review experiment results and save the pipeline with the best performance. ![Anomaly prediction relationship map and pipeline leaderboard](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/autoai-ts-ad-pipeline-map.png) 1. The leaderboard lists and saves the three best performing pipelines. Click the pipeline name with Rank 1 to review the details of the pipeline. For details on anomaly prediction metrics, see [Creating a time series anomaly prediction experiment](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/autoai-ts-ap.html). 2. Select the pipeline with Rank 1 and Save the pipeline as a model. The model name is pre-populated with the default name. 3. Click Create to confirm your pipeline selection. Deploy the trained model Before the trained model can make predictions on external values, you must deploy the model. Follow these steps to promote your trained model to a deployment space. 1. Deploy the model from the Model details page. To access the Model details page, choose one of these options: * From the notification displayed when you save the model, click View in project. * From the project's Assets, select the model’s name in Models. 2. From the Model details page, click Promote to Deployment Space. Then, select or create a deployment space to deploy the model. 3. Select Go to the model in the space after promoting it and click Promote to promote the model. Testing the model After promoting the model to the deployment space, you are ready to test your trained model with new data values. 1. Select New Deployment and create a new deployment with the following fields: 1. Deployment type: Online 2. Name: Electricity usage online deployment 2. Click Create and wait for the status to update to Deployed. 3. After the deployment initializes, click the deployment. Use Test input to manually enter and evaluate values or use JSON input to attach a data set. ![Anomaly prediction sample input data](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/autoai-ts-ad-sample-cases.png) 4. Click Predict to see whether there are any anomalies in the values. Note:-1 indicates an anomaly; 1 indicates a normal value. ![Anomaly