Once you have prepared the data and have been able to visualize it, you’re ready to take the next logical step: to analyze the data for both Artificial Intelligence and Business Intelligence.
This lab will help you develop analytical graphs and charts along with predictive analytics. You will dabble with the AI models used for the predictions.
This lab will show you how to set up an automated machine learning (AutoML) training job with the Azure Machine Learning Notebook. Automated ML picks an algorithm and hyperparameters for you and generates a model ready for deployment. This lab provides details of the various options that you can use to configure automated ML experiments.
The basic flow diagram for this lab is outlined below. It shows the activities we’ll be performing as part of this lab, starting with exporting the dataset required to train the models from Azure SQL Database, and then building an AI/ML model using Azure ML Studio.
Note: The AI ML models built in this lab are not ready for production; we’re only using 4 years of Chicago Crime data for the model training. Hence, the prediction is done using a python notebook.
Open your browser and navigate to https://portal.azure.com/
Sign in to Azure portal using your credentials.
3. You might see a prompt like the one pictured below, Click on Ask Later (Note- Whenever you find this prompt click on the Ask Later option)
4. Once you are signed in to azure portal, click on the Resourse groups tab, to select the required resourse.
5. Select the SaferaLab1 resourse group.
NOTE: The ID will be different for each user. For instance,
a) For user1, the resource group name will be SaferaLab1.
b) For user2, the resource group name will be SaferaLab2 and so on.
Below is the screenshot for User1:
Below is the screenshot for User2:
Below is the screenshot for User3:
Below is the screenshot for User4:
Below is the screenshot for User5:
Below is the screenshot for User6:
6. Once you’ve selected the SaferaLab1 Resource group, select the SaferaLabaml1 workspace from the list. If you’re having difficulty finding it you can type “workspace” into the “Filter for any field” input and you’ll only be shown workspace resources.
NOTE: Similar to the pointer mentioned in the previous step, the ID will be different for each user. For instance,
a) For user1, the studio workspace name will be SaferaLabaml1.
b) For user2, the studio workspace name will be SaferaLabaml2 and so on.
Below is the screenshot for User1:
Below is the screenshot for User2:
Below is the screenshot for User3:
Below is the screenshot for User4:
Below is the screenshot for User5:
Below is the screenshot for User6:
All the screenshots given below are with respect to the User1. Kindly select the respective resources and notebook folder for further steps.
7. Once you’re in the SaferaLabaml1 workspace, you can click on “Launch Studio” towards the bottom of the screen. It will open up a new tab in your browser.
8. Navigate to the left pane. Select Notebooks under the Authoring section.
For User2, the first folder name would be “safera_wlu_user2” instead of “safera_wlu_user1”.
For User3, it would be “safera_wlu_user3”.
For User4, it would be “safera_wlu_user4”.
For User5, it would be “safera_wlu_user5”.
For User6, it would be “safera_wlu_user6”.
2. Once you open the Notebook file, Click on the + button present at right side as shown in the image to create a compute instance.
3. Click on the Create button
4. It will take a few minutes(3-5) to create a compute instance.
5. Once the compute created, you can see the created compute instance in green colour.
(if asks for authentication permission, click on the Authenticate button)
6. Click on Authenticate button to enable use of Azure SDK.
7. Select the kernal as Python 3.8 – AzureML as shown in image.
8. So, Click on the “Restart kernal and run all cells” button. This will run all the cells in the notebook.
if you didn’t find that icon, then you can use this method to “Restart kernal and run all cells”
Instructions to run the individual cells. – Click on the cell that you want to run (You should always run it sequentically)
1. Shift+Enter : Runs the current cell and select the cell below it
or
2. Ctrl+Enter : Runs the current cell.
from above image
Data information
Weighted AUC-ROC & Accuracy are the accuracy metrics used for testing the model here.
here we will pass the input values for-
1. Date
2. Block
3. Description of the location
4. Arrest
5. Domestic
6. Beat
7. Ward
8. Community Area
9. Time of the Crime
10. Average Temperature of the location
11. conditions
And will do the predictions for
12. Primary Type (Target Column) : Type of crime ex. BATTERY,THEFT,PUBLIC PEACE VIOLATION,ASSAULT etc
we get the result for case 1 as ‘THEFT’
You can change the input to get the another predictions, lets do the predictions for case 2, with changed inputs.
we get the result for case 2 as ‘BATTERY’
A time series model is created to predict the frequency of crime that can happen in the future. The algorithm used to achieve the objective is Skforecast. Skforecast is a simple open-source Python package for time series forecasting. It provides a simple and intuitive API to create and fit forecasting models using machine learning algorithms such as ARIMA, SARIMA, exponential smoothing, and random forests.
Under the notebook section. Navigate to the “TimeseriesModel” folder inside your user.
Open the “SkforecastModel.ipynb” file.
Note: If the computing machine is already available and created in model 1, then please skip steps 3 and 5.
3. Click on the three dots as shown in the screenshot and create a new Azureml compute instance.
4. Click on the Create button
5. You can see a computing instance starting up. Wait till it turns in green colour.
6. Select the kernal as Python 3 (ipykernel) as shown in image.
7. Click on the “Restart kernal and run all cells” button. This will run all the cells in the notebook.
8. This saves the prediction values in a CSV and shows the trend as below:
NOTE: To run the individual cells, please click the cell that you want to run and then press shift+enter (Make sure you run all the cells above that cell as well).
Model Training:
Test Results:
Prediction: Please provide the future date to the date_val variable. The prediction will be saved till the given future date. For instance, in the given screenshot a prediction result is shown for 2 years (from July 23, 2022, to July 23, 2024) as date_val = “2024-07-23”.