​
Showing posts with label AzureML. Show all posts
Showing posts with label AzureML. Show all posts

Wednesday, January 17, 2018

Operationalize models from AML workbench into Azure - Part 1

Hi All,

One of the primary tasks for any machine learning practitioner or data scientist is to operationalize machine learning models into a serving environment. This first blog post would be showing how to operationalize models using Azure Machine Learning (AML) workbench in a step to deploy models as realtime webservices into Azure.

First, Once you have your model ready to be operationlized, you need to create and set the right execution environment for your model to be deployed to in Azure.

A) Creating a machine learning model management service using CLI in Azure

First, You need to know that to provision a ml model management service in azure that acts as a serving environment for your models. You can create a new one using azure portal or by executing this command in CLI from your computer:

az ml account modelmanagement create --location westcentralus -n mymodelmanagement -g myresourcegroup

-n: where you can specify the name of the service when it is provisioned in azure.
-g: the resource group name that you would like this account model management services assigned to.

Checkpoint #1: You need to make sure to provision a ML model management account is created in azure before going forward with the rest of this article.

B) Configure the execution environment using Azure Machine Learning Workbench using CLI

Once you have a model management account, you would not be able deploy models from your workbench tool into azure using docker container images unless you provision an environment. In the below steps, we will walk through how to accomplish this.


Follow the below steps:

1) From AML workbench, open the command line window from File --> Open Command prompt.
2) You need to login to your azure account, type the following command:

     az login

3) Follow the screen instructions by logging into your azure subscription.
4) Make sure that you are using the right subscription, The below first command list all subscriptions you have, the second line set the intended subscription you would like to use.

      az account list -o table
      az account set -s <subscriptionId>

5) Verify that your current account is set correctly by exeucting the following command:

       az account show

6) To create an environment which creates set of cloud assets containing blob storage, container registry and other assets in a resource group to host docker images for your models into the cloud:

      az ml env setup -n mymldevenv --location westcentralus

Please note that we created an environment on the same location of the model management services in west central us.

7) Set the model management account

     az ml account modelmanagment set -n mymldevenv -g mymldevenvrg

 Please note that when we created an environment in step #6, it has created a resource group for this environment with the same name with rg suffix, which we used in this step to set our model management service we created in step A with this environment.

Checkpoint #2: An AML workbench environment and a model management service were provisioned before moving forward to the rest of this article.

8) Now, we are going to set the correct execution environment in CLI to connect to the provisioned environment and therefore the model management service in azure.

    a) To see available environments, run:
   
         az ml env list

    b) In my case, i do have few of these for different project. To set an active environment, run:

         az ml env set -n mymodelmanagement  -g myresourcegroup

     c) Once you run this command, you should see this confirmation message in the console window

         Compute set to mymldevenv .

9) Every time you re-open AML workbench, you need to make sure to set the right environment before deploying models as webservices into azure model management service.


In the second part, I will take the next step of publishing models into real-time web services in azure model management service in azure.


Enjoy ML :-)

- Mostafa


Tuesday, October 31, 2017

Load datasets from azure blob storage into Pandas dataframe

Hi,

In this post, I am sharing how to work and load data sets that are stored in Azure blob storage into Pandas data frame.

I have the full code posted in Azure notebooks. This code snippet is useful to use in any Jupyter notebook while working on your data pipeline while developing Machine Learning models.

I have exported a data set into a csv file and stored it into an Azure blob storage so i can use it into my notebooks.



Python code snippet:

import pandas as pd
import time
# import azure sdk packages
from azure.storage.blob import BlobService

def readBlobIntoDF(storageAccountName, storageAccountKey, containerName, blobName, localFileName):    
    # get an instance of blob service 
    blob_service = BlobService(account_name=storageAccountName, account_key= storageAccountKey)
    # save file content into local file name
    blob_service.get_blob_to_path(CONTAINERNAME,blobName,localFileName)
    # load local csv file into a dataframe    
    dataframe_blobdata = pd.read_csv(localFileName, header=0)
    
    return dataframe_blobdata

STORAGEACCOUNTNAME= 'STORAGE_ACCOUNT_NAME'
STORAGEACCOUNTKEY= 'STORAGE_KEY'    
CONTAINERNAME= 'CONTAINER_NAME'
BLOBNAME= 'BLOB_NAME.csv'
LOCALFILENAME = 'FILE_NAME-csv-local'

# load blob file into pandas dataframe
tmp = readBlobIntoDF(STORAGEACCOUNTNAME,STORAGEACCOUNTKEY,CONTAINERNAME,BLOBNAME, LOCALFILENAME)
tmp.head()


The full code snippet is posted in Azure Notebook here.

Enjoy!

Friday, August 26, 2016

Study notes for exam 70-475: Designing and Implementing Big Data Analytics Solutions

Hi All,

Today I passed the "Designing and Implementing Big Data Analytics Solutions" Microsoft exam.

I have been preparing for this exam (70-475) for a couple of months and I have been using Hadoop ecosystem tools and platforms for awhile.

I wanted to master building big data analytics solutions using HDInsight clusters using Hadoop ecosystem which contains: Storm, Spark, HBase, Hive and HDFS. I worked to cover any gap in understanding I had in Azure Data Lake, ML, Python & R programming and Azure Machine Learning.

This exam covers the following primarily four main technologies (from most covered to least):

1) Hadoop ecosystem: Working with HDFS, HBase, Hive, Storm, Spark and understanding Lambda Architecture. If you want to know more about Lambda Architecture, read my blog post explaining it here.

2) Azure Machine Learning: building/training models, predictive models, classification vs regression vs clustering, recommender algorithms. building custom models, Executing code in R and Python. Ingesting data from Azure Event Hub & transformation in Stream analytics.

3) Azure Data Lake: building pipeline, activities, linked services, move, transform and analyze data, working with storage options in Azure (blob vs block) & tools to transform data.

4) SQL Server and Azure SQL: Security in transit and at rest, SQL Data Warehouse. Working with R in Sql Server 2016/Azure SQL.


My study notes while preparing to pass this test:

1) To protect data at rest as well as querying in Azure SQL Database: Use "Always Encrypted" to make sure data in transit is encrypted. Use "Transparent Data Encryption" to make sure that data at rest is encrypted. Read more about TDE here. Read more about Always Encrypted feature here.

2) When running an Azure ML experiment and you are getting "Out of memory error" here is how to fix it:
   a) Increase the memory settings for the map and reduce operations in the import module.
   b) Use Hive query to limit the amount of data being processed in the import module.

3) The easiest way to manage Hadoop clusters in Azure is to assign every HDInsight cluster to a resource group and to apply tags to all related resources.

4) In Hadoop, When the data is row-based, self-describing with schema and provide compact binary data serialization: it is recommended to use Avro.

5) Which Hadoop cluster type for query and analysis batch jobs:
     a) Spark: A cluster for In-memory processing, interactive queries, and micro-batch stream processing.
     b) Storm: A real-time event processing.
     c) HBase: NoSQL data storage for big data systems.

6) Importing data using Pyhon in Azure ML tips:
    a) Missing values are converted into NA for processing. NA will be converted back to missing values when converted back to datasets.
    b) Azure Dataset are converted to data frames in Pandas. Pandas module is used to work with data in Python.
    c) Number names columns are not ignored. str() function is applied to those.
    d) Duplicate column names are not ignored. The duplicate column names are modified to make sure they have unique names.

7) The only platform that supports ACID transaction in Hadoop file storage options is Apache Orc.

8) You have three utilities you can use to move data from local storage to managed cluster blob storage. These tools are: Azure CLI, PowerShell & AzCopy.

9) How to improve Hive queries using static vs dynamic partitioning, read more here.

10) Understand when to use Filter based Feature Selection in Azure ML.

11) AzureML requires Python to store visualizations as PNG Files. To configure MatPlotLib in AzureML, you should configure it to use AGG backend for rendering and you should save charts as PNG files.

12) To detect potential SQL injection attempts on Azure SQL database in ADL cluster: Enable Threat Detection.

13) To create synthetic samples of dataset for classes that are under represented: use SMOTE module in AzureML.

14) D14 V2 Virtual Machines in Azure supports 100GB in memory processing.

15) You can add multiple contributors to AzureML workspace as users.

16) Understand the minimum requirements for each cluster type in HDInsight;
       a) At least 1 data node for Hadoop cluster type.
       b) At least 1 region server for HBase cluster type.
       c) Two Nimbus nodes for Storm cluster type.
       d) At least 1 worker role for Spark cluster type.

17) If you want to store a file with a file size is greater than 1 TB, you need to use Azure Data Lake Store.

18) In Azure Data Factory (ADF), you can train, score and publish experiments to AzureML using:
      a) AzureML Batch execution: to train and score.
      b) AzureML Update resource activity: to update AzureML web services.

19) In Azure Data Factory (ADF), A pipeline is used to configure several activities, including the sequence and timing activities in a pipeline can be managed as a unit.

20) Working with R models in SQL Server 2016/AzureSQL: read more here.

21) Apache Spark in HDInsight can read files from Azure blob storage (WASB) but not SQL Server.

22) Always Encrypted protects data in transit and at rest will be encrypted. Also this feature allows you to store encryption keys on premise.

23) Transparent Data encryption (TDE) : secure data at rest, it will not protect data in transit and the keys are stored in the cloud.


24) Distcp is a Hadoop tool to copy data to and from HDInsight clusters storage blob into Azure Data lake store.

25) Adlcopy: is a command line utility to copy data from azure blob storage into azure data lake storage account.

26) AzCopy: A tool to copy data from and to Azure blob storage.

27) While working with large binary files and you would like to optimize the speed of AzureML experiment, you can do the following:
      a) Developers should write data as block blob.
      b) The blob format should be in CSV or TSV.
      c) You should NOT turn off the cached results option.
      d) You can NOT filter data using SQL but R language.


28) SQL DB contributor role allows monitoring and auditing of SQL databases without granting permissions to modify security or audit policies.

29) To process data in HDInsight clusters in Azure Data Factory (ADF):
      a) Add a new item to the pipeline in the solution explorer.
      b) Select Hive Transformation.
      c) Construct JSON to process the cluster data in an activity.

30) Understanding Tumbling vs Hopping vs Sliding Windows in Azure Stream Analytics. (link)

Hope this helps you get ready to pass the test, and good luck everyone!
Let's get all certified ya'll data wranglers :-)


-- ME


References:
1) Microsot Exam 70-475 details, skills measured and more:
https://www.microsoft.com/en-us/learning/exam-70-475.aspx


Friday, May 13, 2016

Data Science essentials in Azure ML

Hi All

I have the opportunity today to speak at RevolutionConf at Virginia Beach.

RevolutionConf is a one-day, platform and language agnostic, software development conference being held on May 13, 2016 in Virginia Beach, VA.

I had so much fun with chatting and speaking with speakers and attendees. The schedule has variety of topics, technologies and platforms talks. I am impressed and loved to be here with the crowd.

I'm glad to be a speaker at the first time RevolutionConf event and looking forward to the upcoming event next year.

Special thanks for organizers, volunteers and attendees to have such an amazing event.

Here is my presentation and talk details:

Topic: Data Science Essentials in AzureML
Description:
In this session i am covering data science principals such as: Regression, Clustering, Classification, Recommendation and how to build programmable components in Azure Machine Learning experiments using data science programming languages. The session shows and illustrate how to implement these concepts using Azure ML studio.



Data science essentials in azure ml from Mostafa Elzoghbi

References:
** Free e-book “Azure Machine Learning”
https://mva.microsoft.com/ebooks#9780735698178

** Azure Machine Learning documentation
https://azure.microsoft.com/en-us/documentation/services/machine-learning/

** Data Science and Machine Learning Essentials
www.edx.org


Thanks all and hope this helps.

Monday, December 21, 2015

Learn R for Data Science Applications and Machine Learning

Hi All,

I am writing this blog post to highlight cool resources to learn programming in R. R language is a widely used programming language for data scientists and engineers who build programmable components in big data solutions.

Here are the resources to get started:

1) Quick-R: the easiest and fastest way to learn R
http://www.statmethods.net/ 

2) Official CRAN (Comprehensive R Archive Network) resource:
https://cran.r-project.org/manuals.html 

3) Introduction to R Programming: Free Course (On-Demand)
https://www.edx.org/course/introduction-r-programming-microsoft-dat204x-0 


Hope this helps.

Tuesday, December 15, 2015

Data Science and Machine Learning Training Course for Free

Hi All,

To get started to learn data science and Machine Learning principals i would strongly recommend to try this free course from Microsoft Virtual Academy (MVA) course:

Some key points from the course:
  • Data science is about using data to make decisions that drive actions.
  • Data science involves:
  1. Finding data
  1. Acquiring data
  1. Cleaning and transforming data
  1. Understanding relationships in data
  1. Delivering value from data
  • Predictive analytics is about using past data to predict future values.
  • Prescriptive analytics is about using those predictions to drive decisions.


Learn more in this course:

https://mva.microsoft.com/en-US/training-courses/data-science-and-machine-learning-essentials-14100?l=UyhoTxWdB_3505050723

Enjoy! 

Tuesday, October 13, 2015

DC Startups join Microsoft Ventures - Join our Equity free program $25k & $500k Azure Credits

Hi All,

I am calling all DC startups who are looking for getting mentorship, grow, get funded and get a great working environment and to join Microsoft Accelerator program.


Microsoft Ventures is a global initiative empowering entrepreneurs around the world on their journey to build great companies. We’re focused on building partnerships with venture funds, angel investors, incubators, accelerators, corporate executives, and at the core startups, as well as run its own accelerators around the world. Our goal and objective is to help scale and grow startups by giving them a great working environment, access to mentors and service providers, free technological tools and connecting them to Microsoft’s customers and business partners. 

The next batch of the program opens on Feb 2016 and it’s going to be themed around Machine Learning and Data Science. We will be targeting startups that are a more mature than previous batches – such that raised $1M-$1.5M, with an existing product and maybe even initial traction.


Having said that, startups that choose to use Azure will enjoy the help of the ML product group in architecting their solutions to the right size and using the cutting edge services Azure ML offers. 
• Access to the Microsoft distribution channels – Microsoft Ventures is committed to help startups who have relevant products to our customers and partners get connected to them through our massive distribution channels. In addition, startups will receive assistance in getting set up on the Azure Marketplace allowing the Microsoft sales reps to sell their solutions with higher incentives. 
• Free of Microsoft Azure – startups in the program will be automatically enrolled to BizSpark Plus program and be credited for $500K of cloud usage (storage and compute) for 3 years, to be used in their own pace. This allows the startup to focus on the crucial business aspects of their company.


Meet us in person, learn more about the program and benefits. Besides these locations we are evaluating a few more venues so please check out for more details at microsoftventures.com/seattle


Meet us in person on November 4th, 2015 at 1776:



Let me know if you have any questions or would like to get an invite to attend.


Tuesday, July 28, 2015

Get started with Azure Machine learning for free

If you would like to start building Azure machine learning experiments on Micosoft Azure, You will be able to start getting started with Microsoft free offer for Azure feature-sepcific offer where you can work on Azure ML without a need for Azure subscriptions.

All what you need is a Microsoft account to login, once you got that, visit below link to start experimenting Azure ML.

If you don't have a Microsoft account (Live, Hotmail, Outlook), here you can sign up for free:

Update: Due to a recent update in Azure ML site,You will be able to use Azure Studio as a guest and you don't need to login or create a Microsoft account.
We recommend you to create a Microsoft account to store all your experiments under you account to be available everywhere.


Enjoy Azure ML!