0% found this document useful (0 votes)
63 views41 pages

AI Unit 1

The document outlines a skill enhancement course on Artificial Intelligence, focusing on Azure AI Fundamentals (AI-900) and Data Analyst Associate (DA-100). It includes a detailed syllabus with practical applications, advantages, disadvantages, and various applications of AI across different industries. The course aims to equip students with knowledge and skills in AI technologies, particularly using Microsoft's Azure platform.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views41 pages

AI Unit 1

The document outlines a skill enhancement course on Artificial Intelligence, focusing on Azure AI Fundamentals (AI-900) and Data Analyst Associate (DA-100). It includes a detailed syllabus with practical applications, advantages, disadvantages, and various applications of AI across different industries. The course aims to equip students with knowledge and skills in AI technologies, particularly using Microsoft's Azure platform.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

ARTIFICIAL INTELLIGENCE

Skill Enhancement Course

SUPRITA KAGAWADE
DEPARTMENT OF COMPUTER SCIENCE
Government Ramnarayan Chellaram College of Commerce and Management Bengaluru
SYLLABUS
Course – 1 - Azure AI Fundamentals (AI-900)
AI-900 pathway consists of 5 courses and 2 reading material:
i. Introduction to AI on Azure
ii. Use visual tools to create machine learning models with Azure Machine Learning
iii. Explore computer vision in Microsoft Azure
iv. Explore natural language processing
v. Explore conversational AI
vi. Tune Model Hyperparameters - Azure Machine Learning (Reading)
vii. Neural Network Regression: Module Reference - Azure Machine Learning (Reading)

Practical
1. Prepare the data
2. Model the data
3. Visualize the data
4. Analyse the data
5. Deploy and maintain deliverables

Course – 2 - Data Analyst Associate (DA-100)


DA-100 pathway consists of 5 courses and 2 reading material:
1. Get started with Microsoft data analytics
2. Prepare data for analysis
3. Model data in Power BI
4. Visualize data in Power BI
5. Data analysis in Power BI
6. Manage workspaces and datasets in Power BI
7. Key Influencers Visualizations Tutorial - Power BI
8. Smart Narratives Tutorial - Power BI | Microsoft Docs

Practical
1. Describe Artificial Intelligence workloads and considerations
2. Describe fundamental principles of machine learning on Azure
3. Describe features of computer vision workloads on Azure
4. Describe features of Natural Language Processing (NLP) workloads on Azure

References:
1. The learning resources made available for the course titled “Azure AI Fundamentals (AI-900) and Data
Analyst Associate (DA-100).” on Future Skills Prime Platform of NASSCOM.
2. Dr. Ashoka S.B, Ms. Kamakshi Katti, Mr. Hanamant Jakaraddi “Artificial Intelligence” edition 2023.
3. Dr. Vivek I. Sarikar, Suman M, R. Sreenivas Rao. “Artificial Intelligence”.
MARKS:
Theory Marks :30
Internals Marks:20
Total Marks:50

TEMPLATE FOR INTERNAL ASSESSMENT TEST


Course Code:4.4 Name of the Course: Artificial Intelligence
Duration: 1 Hour Total Marks: 20
SECTION-A
(Based on the Remembering)
I. Answer Any Two of the following questions. Each carries Two Marks. (2 x 2= 4)
1.
2.
3.

SECTION- B
(Understanding and Applying)
II. Answer Any Two of the following questions. Each carries Eight marks. (2 x8= 16)
4.
5.
6.

SEMESTER END EXAMINATION-TEMPLATE


Course Code:4.4 Name of the Course: Artificial Intelligence
Duration: 1 Hour Total Marks: 30
SECTION-A
I. Answer Any Five of the following questions. Each carries Two Marks. (5 x 2= 10)
1.
2.
3.
4.
5.
6.
7.
8.

SECTION- B
I. Answer Any Four of the following questions. Each carries Five marks. (4x5= 20)
9.
10.
11.
12.
13.
14.
ARTIFICIAL INTELLIGENCE (AI)
• The term Artificial Intelligence (AI) was first invented in the early 1950, and the idea of artificial
intelligence was initially begun by the great computer scientist John McCarthy from 1943 to 1956.
• In today's world, technology is growing very fast, and we are getting in touch with different new
technologies day by day.
• Here, one of the booming technologies of computer science is Artificial Intelligence which is ready to
create a new revolution in the world by making intelligent machines. The Artificial Intelligence is now
all around us. It is currently working with a variety of subfields, ranging from general to specific, such
as self-driving cars, playing chess, proving theorems, playing music, Painting, etc.
• AI is one of the fascinating and universal fields of Computer science which has a great scope in future.
AI holds a tendency to cause a machine to work as a human.

• Artificial Intelligence is composed of two words Artificial and Intelligence, where Artificial
defines "man-made," and intelligence defines "thinking power", hence AI means "a man-made
thinking power."
• AI can be defined as "It is a branch of computer science by which we can create intelligent
machines which can behave like a human, think like humans, and able to make decisions."
▪ Artificial Intelligence exists when a machine can have human based skills such as learning,
reasoning, and solving problems.
▪ With Artificial Intelligence you do not need to preprogram a machine to do some work, despite
that you can create a machine with programmed algorithms which can work with own intelligence,
and that is the awesomeness of AI.
IMPORTANCE OF AI:
▪ With the help of AI, you can create such software or devices which can solve real-world problems
very easily and with accuracy such as health issues, marketing, traffic issues, etc.
▪ With the help of AI, you can create your personal virtual Assistant, such as Cortana, Google
Assistant, Siri, etc.
▪ With the help of AI, you can build such Robots which can work in an environment where survival
of humans can be at risk.
▪ AI opens a path for other new technologies, new devices, and new Opportunities.
ADVANTAGES OF ARTIFICIAL INTELLIGENCE:
Following are some main advantages of Artificial Intelligence:
▪ High Accuracy with less errors: AI machines or systems are prone to less errors and high accuracy as
it takes decisions as per pre-experience or information.
▪ High-Speed: AI systems can be of very high-speed and fast-decision making, because of that AI systems
can beat a chess champion in the Chess game.
▪ High reliability: AI machines are highly reliable and can perform the same action multiple times with
high accuracy.
▪ Useful for risky areas: AI machines can be helpful in situations such as defusing a bomb, exploring
the ocean floor, where to employ a human can be risky.
▪ Digital Assistant: AI can be very useful to provide digital assistant to the users such as AI technology is
currently used by various E-commerce websites to show the products as per customer requirement.
▪ Useful as a public utility: AI can be very useful for public utilities such as a self-driving car which can
make our journey safer and hassle-free, facial recognition for security purpose, Natural language
processing to communicate with the human in human-language, etc.

DISADVANTAGES OF ARTIFICIAL INTELLIGENCE:


Every technology has some disadvantages, and the same goes for Artificial intelligence. Being so
advantageous technology still, it has some disadvantages which we need to keep in our mind while creating
an AI system. Following are the disadvantages of AI:
▪ High Cost: The hardware and software requirement of AI is very costly as it requires lots of
maintenance to meet current world requirements.
▪ Can't think out of the box: Even we are making smarter machines with AI, but still they cannot work
out of the box, as the robot will only do that work for which they are trained, or programmed.
▪ No feelings and emotions: AI machines can be an outstanding performer, but still it does not have
the feeling so it cannot make any kind of emotional attachment with human, and may sometime be
harmful for users if the proper care is not taken.
▪ Increase dependency on machines: With the increment of technology, people are getting more
dependent on devices and hence they are losing their mental capabilities.
▪ No Original Creativity: As humans are so creative and can imagine some new ideas but still AI
machines cannot beat this power of human intelligence and cannot be creative and imaginative.

APPLICATIONS OF AI:
1. AI in Astronomy: Artificial Intelligence can be very useful to solve complex universe problems. AI
technology can be helpful for understanding the universe such as how it works, origin, etc.
2. AI in Healthcare: Healthcare Industries are applying AI to make a better and faster diagnosis than humans.
AI can help doctors with diagnoses and can inform when patients are worsening so that medical help can
reach to the patient before hospitalization.
3. AI in Gaming: AI can be used for gaming purpose. The AI machines can play strategic games like chess,
where the machine needs to think of a large number of possible places.
4. AI in Finance: AI and finance industries are the best matches for each other. The finance industry is
implementing automation, chatbot, adaptive intelligence, algorithm trading, and machine learning into
financial processes.

5. AI in Data Security: The security of data is crucial for every company and cyber-attacks are growing very
rapidly in the digital world. AI can be used to make your data more safe and secure. Some examples such
as AEG bot, AI2 Platform, are used to determine software bug and cyber-attacks in a better way.
6. AI in Social Media: Social Media sites such as Facebook, Twitter, and Snapchat contain billions of user
profiles, which need to be stored and managed in a very efficient way. AI can organize and manage massive
amounts of data. AI can analyze lots of data to identify the latest trends, hashtag, and requirement of
different users.
7. AI in Travel & Transport: AI is becoming highly demanding for travel industries. AI is capable of doing
various travel related works such as from making travel arrangement to suggesting the hotels, flights, and
best routes to the customers. Travel industries are using AI-powered chatbots which can make human-like
interaction with customers for better and fast response.
8. AI in Automotive Industry: Various Industries are currently working for developing self-driven cars
which can make your journey more safe and secure.
9. AI in Robotics: Humanoid Robots are best examples for AI in robotics, recently the intelligent Humanoid
robot named as Erica and Sophia has been developed which can talk and behave like humans.
10. AI in Entertainment: We are currently using some AI based applications in our daily life with some
entertainment services such as Netflix or Amazon. With the help of ML/AI algorithms, these services show
the recommendations for programs or shows.
11. AI in Agriculture: Agriculture is an area which requires various resources, labour, money, and time for
best result. Now a day's agriculture is becoming digital, and AI is emerging in this field. Agriculture is
applying AI as agriculture robotics, solid and crop monitoring, predictive analysis. AI in agriculture can be
very helpful for farmers.
12. AI in E-commerce: AI is providing a competitive edge to the e-commerce industry, and it is becoming
more demanding in the e-commerce business. AI is helping shoppers to discover associated products with
recommended size, color, or even brand.
13. AI in education: AI can automate grading so that the tutor can have more time to teach. AI chatbot can
communicate with students as a teaching assistant.AI in the future can be work as a personal virtual tutor
for students, which will be accessible easily at any time and any place.
UNIT 1: AZURE AI FUNDAMENTALS (AI-900)

CHAPTER 1: INTRODUCTION TO AI ON AZURE

INTRODUCTION TO AI
What is AI?
Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a software think
intelligently, in the similar manner the intelligent humans think.
What is Azure?
Azure is a cloud computing platform and an online portal that allows you to access and manage cloud
services and resources provided by Microsoft.
https://www.microsoft.com/en-us/videoplayer/embed/RE4vyDl?postJsllMsg=true
FIVE KEY WORKLOADS OF AI:
1. Machine-Learning: We "teach" a computer-model to make prediction and draw conclusions from data.
2. Anomaly-Detection: The capability of software to automatically detect errors or unusual activity in a
system.
3. Computer-Vision: The capability of software to interpret the world visually through cameras, video and
images.
4. Natural Language Processing: The capability of software to interpret written or spoken language, and
respond in kind.
5. Knowledge Mining: The capability of software to extract information from large volumes of unstructured-
data. The extracted-information is used to create a searchable-knowledge-store.

UNDERSTAND MACHINE-LEARNING(ML):
Machine learning: Machine learning is a branch of Artificial Intelligence and computer science which
focuses on the use of data and algorithms to imitate the way that humans learn, gradually improving its
accuracy.
https://www.microsoft.com/en-us/videoplayer/embed/RE4voJG?postJsllMsg=true
How Machine-Learning works?
▪ The machines learn from data.
▪ In today's world, huge volumes of data is created.
Example: Text messages, emails, social media posts, photographs and videos.
▪ Data is also created by millions of sensors in homes, cars, cities and factories.
▪ Data-scientists can use the data to train ML-models.
▪ The models can make predictions and inferences based on the relationships in the data.
Example: suppose an environmental conservation organization wants volunteers to identify and catalog
different species of wildflower using a phone app.
The below procedure is followed:
1. A team of botanists and scientists collect data on wildflower samples.
2. The team labels the samples with the correct species.
3. The labeled data is processed using an algorithm that finds relationships between the features of the
samples and the labeled species.
4. The results of the algorithm are encapsulated in a model.
5. When new samples are found by volunteers, the model can identify the correct species label.

AZURE
WHAT IS AZURE AI?
Azure is a cloud computing platform and an online portal that allows you to access and manage cloud
services and resources provided by Microsoft.
WHY AZURE FOR A1?
✓ Build on your terms Access frameworks, tools, and capabilities for developers and data scientists of any
skill level.
✓ Deploy mission-critical AI solutions. Use the same proven Al services that power Al capabilities in Xbox,
HoloLens, and Microsoft Teams.
✓ Apply AI responsibly Get tools, services, and guidelines to help you use Al responsibly, while also
preserving data privacy, transparency, and trust.
1. Azure Applied AI Service
Specialized Al services for specific business scenarios
✓ Modernize business processes with task-specific AI to solve for common scenarios
✓ Accelerate development with built-in business logic that enables you to launch solutions in days-not
months.
✓ Run responsibly anywhere with security that extends from the cloud to intelligent edge
2. Azure Cognitive Services
Comprehensive family of customizable cognitive APIs for vision, speech, language, and decision making
✓ Easily access sophisticated Al models, including OpenAl models, with the most comprehensive portfolio
of Al capabilities on the market
✓ Build confidently with the first Al services to achieve human parity in computer vision, speech, and
language
✓ Deploy anywhere from the cloud to the edge with containers.
✓ Get started quickly and customize solutions to meet your own unique requirements
3. Azure Machine Learning
An end-to-end platform for building, training, and deploying machine learning models
✓ Develop with your choice of tools with Jupyter Notebook, drag-and-drop designer, and automated
machine learning
✓ Create and deploy models at scale using automated and reproducible machine learning workflows.
✓ Innovate responsibly with a rich set of built-in responsible capabilities to help you understand, protect, and
control data, models and processes.
✓ Build your way with best-in-class support for open-source frameworks and languages including MLflow,
Kubeflow, ONNX, PyTorch, TensorFlow, Python, and R.

CHAPTER 2: USE VISUAL TOOLS TO CREATE MACHINE LEARNING


MODELS WITH AZURE MACHINE LEARNING

INTRODUCTION
✓ Machine Learning is the foundation for most artificial intelligence solutions. Creating an intelligent
solution often begins with the use of machine learning to train predictive models using historic data
that you have collected.
✓ Azure Machine Learning is a cloud service that you can use to train and manage machine learning
models.
WHAT IS MACHINE-LEARNING?
✓ Machine learning is a branch of Artificial Intelligence and computer science which focuses on
the use of data and algorithms to imitate the way that humans learn, gradually improving its
accuracy.
✓ ML uses mathematics & statistics to create a model that can predict unknown values.
a) Mathematically, machine-learning is a function (f): The function (f) operates on one or more features
(x) to calculate a predicted-label (y).
i.e., f(x) = y
b) The function (f) depends on a no. of factors including
i. Type of model
ii. Algorithm used to train the model

TYPES OF MACHINE-LEARNING
a) There are 2 general approaches to machine-learning.
1) Supervised ML
2) Unsupervised ML
b) In both approaches, you train a model to make predictions.
1) Supervised Machine-Learning:
▪ Supervised learning is a machine learning approach in which a data scientist acts like a tutor and trains the
AI system by feeding basic rules and labeled datasets. The datasets will include labeled input data and
expected output results. In this machine learning method, the system is explicitly told what to look for in the
input data.
▪ You to start with a dataset with known label-values.
Two types of tasks are:
i. Regression: Regression is used to predict a continuous value; like a price or a sales total.
ii. Classification: Classification is used to determine a class-label. For example,
• Binary class-label can classify whether a patient has diabetes or not
• Multi-class-labels can classify text as positive, negative, or neutral
2) Unsupervised Machine-Learning:
▪ Unsupervised learning is a machine learning technique in which the data scientist lets the AI system learn
by observing. The training dataset will contain only the input data and no corresponding output data.
▪ When compared to supervised learning, this machine learning method requires massive amounts of
unlabeled data to observe, find patterns, and learn. Unsupervised learning could be a goal in itself, for
example, discovering hidden patterns in datasets or a method for feature learning.
▪ You to start with a dataset without known label-values.
One type of task is:
i. Clustering: Clustering used to determine labels by grouping similar information into label-groups.
• For example, grouping different shapes.

MACHINE-LEARNING IN MICROSOFT-AZURE
▪ Microsoft-Azure provides the Machine-Learning (ML) service.
▪ ML-service is a cloud-based platform for creating, managing, and publishing ML-models.
FEATURE CAPABILITY
Automated machine learning This feature enables non-experts to quickly create an
effective machine learning model from data.
Azure Machine Learning designer A graphical interface enabling no-code
development of machine learning solutions.

Data and compute management Cloud-based data storage and compute resources that
professional data scientists can use to run data experiment
code at scale.
Pipelines Data scientists, software engineers, and IT operations
professionals can define pipelines to orchestrate model
training, deployment, and management tasks.

TOOLS TO CREATE MACHINE LEARNING IN MICROSOFT AZURE


There are several tools available in Microsoft Azure for creating machine learning models
Here are some of the key tools:
1. Azure Machine Learning Studio: This is a visual drag-and-drop tool that allows you to create,
train, and deploy machine leaming models without writing any code. It also provides a range of pre-
built templates and algorithms for common use cases.
2. Azure Machine Learning SDK for Python: This is a set of Python packages that allow you to
create, train, and deploy machine learning models using your own Python code. It also provides
integration with popular Python tools and frameworks like TensorFlow, PyTorch, and scikit-learn.
3. Azure Databricks: This is a fast, easy, and collaborative Apache Spark-based analytics platform
that provides powerful tools for data engineering, data science, and machine learning. It supports a
range of languages, including Python, R, and SQL, and offers built-in Integrations with Azure
services.
4. Azure Cognitive Services: This is a suite of pre-built AI and machine learning APIs that enable
developers to easily add intelligent features to their applications without needing deep AI expertise.
The APIs include language APIs, vision APIs, speech APIs, decision APIs, and search APIs.
5. Azure Stream Analytics: This is a real-time data streaming and analytics service that enables
developers to build and deploy event-driven applications that incorporate machine learning
capabilities.
6. Azure Synapse Analytics: This is an analytics service that provides a unified experience for big data
processing and analytics. It includes built-in machine learning capabilities for data preparation,
model training, and model deployment.

WHAT IS AZURE MACHINE-LEARNING STUDIO?


▪ Training and deploying an effective machine learning model involves a lot of work, much of it time-
consuming and resource-intensive. Azure Machine Learning is a cloud-based service that helps
simplify some of the tasks it takes to prepare data, train a model, and deploy a predictive service.
▪ Azure Machine Learning studio is a web portal for machine learning solutions in Azure. It includes a
wide range of features and capabilities that help data scientists prepare data, train models, publish
predictive services, and monitor their usage. To begin using the web portal, you need to assign the
workspace you created in the Azure portal to Azure Machine Learning studio.
WHAT ARE THE DIFFERENT TYPES OF AZURE MACHINE-LEARNING COMPUTE RESOURSE?
▪ Azure Machine Learning is a service for training and managing machine learning models, for which
you need compute on which to run the training process.
▪ Compute targets are cloud-based resources on which you can run model training and data exploration
processes.
There are four kinds of compute resource you can create:
1. Compute instances: Development workstations that data-scientists can use to work with data and
models.
2. Compute clusters: Scalable clusters of virtual-machines for on- demand processing of experiment
code.
3. Inference clusters: Deployment targets for predictive-services that use your trained models.
4. Attached compute: Links to existing Azure compute-resources such as Virtual-machines.

WHAT IS AZURE AUTOMATED MACHINE-LEARNING (AAML)?


▪ Azure Machine Learning includes an automated machine learning capability that automatically tries
multiple pre-processing techniques and model-training algorithms in parallel. These automated
capabilities use the power of cloud compute to find the best performing supervised machine learning
model for your data.
▪ Automated machine learning allows you to train models without extensive data science or programming
knowledge. For people with a data science and programming background, it provides a way to save
time and resources by automating algorithm selection and hyper-parameter tuning.
▪ You can create an automated machine learning job in Azure Machine Learning studio.

▪ In Azure Machine Learning, operations that you run are called jobs. You can configure multiple
settings for your job before starting an automated machine learning run. The run configuration provides
the information needed to specify your training script, compute target, and Azure ML environment in
your run configuration and run a training job.
UNDERSTAND THE AUTOML PROCESS
The steps in a machine-learning process is as follows:
1. PREPARE DATA
▪ Identify the features and label in a dataset. Pre-process, or clean and transform, the data as needed.
▪ Machine learning models must be trained with existing data. Data scientists expend a lot of effort
exploring and pre-processing data, and trying various types of model-training algorithms to produce
accurate models, which is time consuming, and often makes inefficient use of expensive compute
hardware.
▪ In Azure Machine Learning, data for model training and other operations is usually encapsulated in
an object called a dataset. You can create your own dataset in Azure Machine Learning studio.
2. TRAIN MODEL
▪ Split the data into two groups, a training and a validation set. Train a machine learning model using the training
data set. Test the machine learning model for performance using the validation data set.
▪ The automated machine learning capability in Azure Machine Learning supports supervised
machine learning models - in other words, models for which the training data includes known label
values. You can use automated machine learning to train models for:
• Classification (predicting categories or classes)
• Regression (predicting numeric values)
• Time series forecasting (predicting numeric values at a future point in time) In Automated
Machine Learning you can select from several types of tasks:

▪ In Automated Machine Learning, you can select configurations for the primary metric, type of model used
for training, exit criteria, and concurrency limits.

▪ Importantly, AutoML will split data into a training set and a validation set. You can configure the
details in the settings before you run the job.
3. EVALUATE PERFORMANCE:
▪ Compare how close the model's predictions are to the known labels.
▪ After the job has finished you can review the best performing model. In this case, you used exit
criteria to stop the job. Thus the "best" model the job generated might not be the best possible model,
just the best one found within the time allowed for this exercise.

4. DEPLOY A PREDICTIVE SERVICE:


▪ After you train a machine learning model, you can deploy the model as an application on a server or
device so that others can use it.

CHAPTER 3: EXPLORE COMPUTER VISION IN MICROSOFT AZURE

WHAT IS COMPUTER VISION?


▪ Computer vision is an area of artificial intelligence (AI) in which software systems are designed to
perceive the world visually, through cameras, images, and video.
• Computer-vision enables AI applications to "see" the world and make sense of it.
• Computers are capable of processing images; either
o From a live camera feed or
o From digital photographs or videos.
• Image processing is the key to creating software that can emulate human visual perception.

APPLICATIONS OF COMPUTER-VISION
1. Content Organization: Identify people or objects in photos and organize them based on the identification.
2. Photo Recognition: Applications like this are commonly used in photo storage and social media applications.
3. Text Extraction: Analyse images and PDF documents that contain text and extract the text into a structured
format.
4. Spatial Analysis: Identify people or objects, such as cars, in a space and map or understand their movement
within that space.
COMPUTER-VISION SERVICE (CVS)
▪ To an AI application, an image is just an array of pixel values.
▪ These numeric values can be used as features to train models.
▪ Then, the models make predictions about the image and its contents.
▪ CVS gives you access to pre-trained computer-vision capabilities.

GET STARTED WITH IMAGE ANALYSIS ON AZURE


▪ CVS provides pre-built computer-vision capabilities.
▪ The service can analyse images, and return detailed information about the image.
Azure Resources for Computer-Vision
▪ To use the CVS, you need to create a resource for it in your Azure subscription.
You can use either of the following resource types:
o Computer-vision: A specific resource for the CVS.
o Cognitive Services: A general resource that includes CVS and Cognitive services such as
Text Analytics, Translator Text etc.
The resources provide 2 pieces of information:
▪ A key that is used to authenticate client applications
▪ An endpoint that provides the HTTP address at which your resource can be accessed.

ANALYSING IMAGES WITH CVS:


You can submit images to the CVS to perform a wide range of analytical tasks.
Tasks of computer vision:
1. Describing an Image
▪ Computer-vision has the ability to Analyse an image, Evaluate the objects that are detected and Generate a
human-readable phrases that describes objects in the image.
▪ Consider the following image of the building in New York.
▪ The returned phrases are listed below in the order of confidence.

o A black and white photo of a city.


o A black and white photo of a large city.
o A large white building in a city.
2. Tagging Visual Features:
▪ The image descriptions can be used to suggest tags for the image. The tags can be associated with the
image as metadata that summarizes attributes of the image.
▪ These tags can be associated with the image as metadata that summarizes attributes of the image; and
can be particularly useful if you want to index an image along with a set of key terms that might be
used to search for images with specific attributes or contents.
Example:

3. Detecting Objects:
▪ The object detection capability is similar to tagging, in that the service can identify common objects;
but rather than tagging, or providing tags for the recognized objects only, this service can also return
what is known as bounding box coordinates.
▪ Not only will you get the type of object, but you will also receive a set of coordinates that indicate the
top, left, width, and height of the object detected, which you can use to identify the location of the
object in the image.
Example:

4. Detecting Brands:
▪ This feature provides the ability to identify commercial brands. The service has an existing database of
thousands of globally recognized logos from commercial brands of products.
▪ When you call the service and pass it an image, it performs a detection task and determine if any of
the identified objects in the image are recognized brands. The service compares the brands against its
database of popular brands spanning clothing, consumer electronics, and many more categories.
▪ If a known brand is detected, the service returns a response that contains the brand name, a
confidence score (from 0 to 1 indicating how positive the identification is), and a bounding box
(coordinates) for where in the image the detected brand was found.
For example: In the following image, a laptop has a Microsoft logo on its lid, which is identified and
located by the Computer Vision service.

5. Detecting Faces:
▪ The Computer Vision service can detect and analyze human faces in an image, including the ability
to determine age and a bounding box rectangle for the location of the face(s).
Example: In The following example shows an image of a person with their face detected and
approximate age estimated.

6. Categorizing an Image:
▪ Computer Vision can categorize images based on their contents. The service uses a parent/child
hierarchy with a "current" limited set of categories. When analyzing an image, detected objects are
compared to the existing categories to determine the best way to provide the categorization.
Examples:

one of the parent categories is people_. This image of a person on a roof


is assigned a category of people_.

A slightly different categorization is returned for the


following image, which is assigned to the category people
group because there are multiple people in the image:
7. Detecting Domain-Specific Content:
When categorizing an image, the Computer Vision service supports two specialized domain models:
• Celebrities - The service includes a model that has been trained to identify thousands of well-
known celebrities from the worlds of sports, entertainment, and business.
• Landmarks - The service can identify famous landmarks, such as the Taj Mahal and the Statue of
Liberty.
Example: In the following example shows an image of Mysore palace.

8. Optical Character Recognition (OCR):


▪ This service can use OCR capabilities to detect printed and handwritten text in images.
Example:

CHAPTER 4: EXPLORE NATURAL LANGUAGE PROCESSING (NLP)

What is NLP?
▪ NLP stands for Natural Language Processing. It is the branch of Artificial Intelligence that deals
with creating software that understand written or spoken language.
Working of Natural Language Processing (NLP)
▪ Working in natural language processing (NLP) typically involves using computational techniques to
analyze and understand human language. This can include tasks such as language understanding,
language generation, and language interaction.
The field is divided into three different parts:
1. Speech Recognition: The translation of spoken language into text.
2. Natural Language Understanding (NLU): The computer’s ability to understand about what do the
user say?, their intention?, Meaning?.
3. Natural Language Generation (NLG): The generation of natural language by a computer about What
should we say to user?, It should be Intelligent and Conversational, Deal with structured data,
Text/sentence planning.

Applications of Natural Language Processing


1. Sentiment Analysis: Analyzing the emotional tone of written text or spoken Language to understand
whether it is positive, negative, or neutral.
Example: People express their opinions and feelings on various social media platforms such as Twitter,
Facebook, Instagram, etc. Social Media Sentiment Analysis can help organizations or marketers to understand
how people perceive or feel about their brand, products, services.

2. Language Translation: Converting text or speech from one language to another.


Examples:

Fig: Text or speech Language

Fig: Text Language

Fig: Speech Language


3. Text Summarization: Creating a condensed version of a longer text, while preserving its key
information.
Example:

4. Named Entity Recognition: Identifying and categorizing entities in a text, such as people,
organizations and locations.
Example:

5. Chatbots: Using NLP to interact with a computer program or device, such as a virtual assistant or
messaging app.
Example:

TEXT ANALYTICS TECHNIQUES


• Statistical analysis: statistical analysis of terms used in the text.
Example: Removing common "stop words" (words like "the" or "a", which reveal little semantic
information about the text) and performing frequency analysis of the remaining words (counting how often
each word appears) can provide clues about the main subject of the text.
• Applying stemming or lemmatization algorithms: to normalize words before counting them. (It is a
technique used to extract the base form of the word by removing affixes from them)
Example: so that words like "power", "powered", and "powerful" are interpreted as being the same word.
• Applying linguistic structure: rules to analyze sentences.
Example: breaking down sentences into tree-like structures such as a noun phrase, which itself contains
nouns, verbs, adjectives, and so on.
• Creating vectorized models that capture semantic relationships between words by assigning them to
locations in n-dimensional space.
Example: assign values to the words "flower" and "plant" that locate them close to one another, while
"skateboard" might be given a value that positions it much further away.

TEXT ANALYTICS CAPABILITIES IN THE LANGUAGE SERVICE


Different capabilities of language services are:
1. Language detection
▪ Use the language detection capability of the Language service to identify the language in which text
is written. You can submit multiple documents at a time for analysis. For each document submitted
to it, the service will detect.
o The language name (for example "English").
o The ISO 6391 language code (for example, "en").
o A score indicating a level of confidence in the language detection.
For example: consider a scenario where you own and operate a restaurant where customers can complete
surveys and provide feedback on the food, the service, staff, and so on. Suppose you have received the
following reviews from customers.
• Review 1: "A fantastic place for lunch. The soup was delicious."
• Review 2: "Comida maravillosa y gran servicio."
• Review 3: "The croque monsieur avec frites was terrific. Bon appetit!"

Document Language ISO 6391 Score


Name Code
Review 1 English En 1.0
Review 2 Spanish Es 1.0
Review 3 English En 0.9

2. Key phrase extraction


▪ Key phrase extraction is the concept of evaluating the text of a document, or documents, and then
identifying the main talking points of the document(s). Consider the restaurant scenario discussed
previously. Depending on the volume of surveys that you have collected, it can take a long time to read
through the reviews. Instead, you can use the key phrase extraction capabilities of the Language
service to summarize the main points.
▪ We had dinner here for a birthday celebration and had a fantastic experience. We were greeted by a
friendly hostess and taken to our table right away. The ambiance was relaxed, the food was amazing,
and service was terrific. If you like great food and attentive service, you should try this place.
▪ Key phrase extraction can provide some context to this review by extracting the following phrases:
• Attentive service
• Great food
• Birthday celebration
• Fantastic experience
• Table
• Friendly hostess
• Dinner
• Ambiance
• Place

3. Entity recognition
▪ You can provide the Language service with unstructured text and it will return a list of entities in the
text that it recognizes.
Example: suppose you use the Language service to detect entities in the following restaurant review extract:
"I ate at the restaurant in Seattle last week."

Entity Type SubType Wikipedia URL


Seattle Location https://en.wikipedia.org/wiki/Seattle
last week DateTime DateRange

NATURAL LANGUAGE PROCESSING IN MICROSOFT-AZURE


1) Azure Cognitive Services Language APIs: This is a suite of pre-built NLP APIs that enable developers to
easily add intelligent features to their applications. These APIs include text analysis, sentiment analysis,
language detection, and entity recognition.
2) Azure Text Analytics: This is a service that provides text analysis capabilities, including sentiment
analysis, key phrase extraction, and language detection, it can be used for a variety of applications, such as
social media monitoring, customer feedback analysis, and market research.
3) Azure Translator: This is a service that provides real-time translation capabilities for text and speech in
over 60 languages. It can be used for applications such as multilingual customer support, global
collaboration, and international e-commerce.
4) Azure Language Understanding (LUIS): This is a service that enables developers to create conversational
Al applications, such as chatbotsE, by understanding user intents and entities. It uses machine learning to
understand natural language and can be easily integrated with other Azure services.
5) Azure Speech Services: This is a service that provides speech recognition and text-to- speech capabilities.
It can be used for applications such as voice assistants, Interactive voice response systems, and audio
transcription.
CHAPTER 5: EXPLORE CONVERSATIONAL AI

WHAT IS CONVERSATIONAL AI?


▪ Conversational AI is a type of artificial intelligence (AI) that can simulate human conversation.
▪ It is made possible by natural language processing (NLP), a field of AI that allows computers to
understand and process human language. NLP is used to analyze the meaning of text and speech,
and to generate responses that are appropriate and relevant to the conversation.

WORKING OF CONVERSATIONAL AI
▪ Conversational AI works by using a combination of natural language processing (NLP)
and machine learning (ML).
▪ Conversational AI systems are trained on large amounts of data, such as text and speech. This data
is used to teach the system how to understand and process human language. The system then uses
this knowledge to interact with humans in a natural way. It’s constantly learning from its interactions
and improving its response quality over time.

BENEFITS OF CONVERSATIONAL AI:


▪ Reduce costs, and increase productivity and operational efficiency through automation.
For example: conversational AI can automate tasks that are currently performed by humans and thereby
reduce human errors and cut costs.
▪ Deliver better customer experience, achieve higher customer engagement and satisfaction.
For example: conversational AI can provide a more personalized and engaging experience by
remembering customer preferences and helping customers 24/7 when no human agents are around.

Examples of conversational AI
To give a few application examples of the constantly evolving conversational AI technology:
1. Chatbots: often used in customer service applications to answer questions and provide support.
2. Assistants: often voice-activated and can be
used on mobile devices and smart speakers.
3. Text-to-speech software: used to create audiobooks, or generate spoken directions.
4. Speech recognition software: used to transcribe lectures, create transcripts of phone calls, or generate
automatic captions for videos.

BOT
▪ A bot is an application with a conversational interface.
Some common features of bots include:
• Users interact with a bot by initiating activities in turns.
• Activities are events, such as a user joining a conversation or sending a message.
• Messages can be text, speech, or visual interface elements.
• A flow of activities can form a dialog, in which state is maintained to manage a multi-turn
conversation.
• Activities are exchanged across channels, such as web chat, email, Microsoft Teams, and
others.
• We except organizations to engage with us individually, and to be able to answer complex questions
at a personal level
• Many organizations publish support information that answer through a web browser or a
dedicated app.

Responsible ai guidelies for bots


• Be transparent about what the bot can (and can’t) do.
• Make it clear that the user is communicating with bot.
• Enable the bot to seamlessly hand-off to a human if necessary
• Ensure the bot respects cultural norms.
• Ensure the bot is reliable.
• Respect user privacy.
• Handle data securely.
• Ensure the bot meets accessibility standards.
• Assume accountability for bots actions.

BOT SOLUTIONS ON MICROSOFT AZURE ARE SUPPORTED BY THE FOLLOWING


TECHNOLOGIES:
1. Azure Bot Service: A cloud service that enables bot delivery through one or more channels, and
integration with other services.
2. Bot Framework Service: A component of Azure Bot Service that provides a REST API for
handling bot activities.
3. Bot Framework SDK. A set of tools and libraries for end-to-end bot development enabling
bot development in a range of programming languages.
4. Bot templates: The easiest way to get started with the Bot Framework SDK is to base your new bot
on one the templates it provides:
5. Empty Bot - a basic bot skeleton
6. Echo Bot - a simple "hello world" sample in which the bot responds to messages by echoing the
message text back to the user.
7. Core Bot - a more comprehensive bot that includes common bot functionality, such as
integration with the Language Understanding service.

COMPONENTS OF CONVERSATIONAL ARTIFICIAL INTELLIGENCE


1. Natural language processing NLP is the ability of a computer to understand human language and
respond in a way that is natural for humans. This involves understanding the meaning of words
and the structure of sentences, as well as being able to handle idiomatic expressions and slang.
NLP is used to train computers to understand language.
2. Machine learning Machine learning is a field of artificial intelligence that enables computers to learn
from data without being explicitly programmed. Machine learning is used to train computers to
understand language, as well as to recognize patterns in data. It is also used to create models of
how different things work, including the human brain.
3. Text analysis Text analysis is the process of extracting information from text data. This involves
identifying the different parts of a sentence, such as the subject, verb, and object, different types
of words in a sentence, such as nouns, verbs, and adjectives. Text analysis is used to understand
the meaning of a sentence, as well as the relationships between different words. It is also used to
identify the topic of a text, as well as the sentiment (positive or negative) of the text.
4. Computer vision Computer vision is the ability of a computer to interpret and understand digital
images. This involves identifying the different objects in an image, as well as the location and
orientation of those objects Computer vision is used to identify the contents of an image, as well
as the relationships between different objects in the image. It is also used to interpret the emotions
of people in photos, and to understand the context of a photo.
5. Speech recognition Speech recognition is the ability of a computer to understand human
speech. This involves recognizing the different sounds in a spoken sentence, as well as the
grammar and syntax of the sentence. Speech recognition is used to convert spoken words
into text, and to understand the meaning of the words.

HOW TO CREATE CONVERSATIONAL AI?


1. Start by understanding the use cases and requirements: The first step in creating
conversational AI understands the organization’s specific needs and use cases. What are you
trying to achieve with your chatbot? What type of conversations do you want it to be able to
have?
2. Choose the right platform and toolkit: There are a number of different platforms and toolkits
that you can use to create conversational AI. Each platform has its own strengths and weaknesses,
so choose the platform that best suits your needs. Some popular platforms include Microsoft Bot
Framework, Amazon Lex, Google Dialog flow, and IBM Watson.
3. Build a prototype: Once the requirements have been defined and chosen a platform, it’s time to
start building the prototype. Building a prototype will help to test the chatbot and iron out any kinks
before deploying it to the users.
4. Deploy and test your chatbot Once the prototype is finished, it’s time to deploy and test the chatbot.
Make sure to test it with a small group of users first to get feedback and make any necessary
adjustments.
5. Optimize and improve your chatbot: The final step is to continually optimize and improve
the chatbot. This can be done by tweaking the algorithms, adding new features, and
collecting user feedback.

CHAPTER 6: TUNE MODEL HYPERPARAMETERS- AZURE MACHINE


LEARNING(READING)

WHAT IS TUNE MODEL HYPERPARAMETERS?


▪ The Parameters are the configuration model, which are internal to the model. Hyper parameters are
the explicitly specified parameters that control the training process. Parameters are essential for
making predictions. Hyper parameters are essential for optimizing the model
▪ The process of finding the optimal configuration is sometimes called tuning.
▪ The component supports the following method for finding the optimum settings for a model:
integrated train and tune.

HOW TO CONFIGURE TUNE MODEL HYPERPARAMETERS


• Train a model by using a parameter sweep
This section describes how to perform a basic parameter sweep, which trains a model by using the Tune
Model Hyper parameters component.
1. Add the Tune Model Hyper parameters component to your pipeline in the designer.
2. Connect an untrained model to the leftmost input.
3. Add the dataset that you want to use for training, and connect it to the middle input of Tune Model
Hyper parameters.
o Optionally, if you have a tagged dataset, you can connect it to the rightmost input port
(Optional validation dataset). This lets you measure accuracy while training and tuning.
4. In the right panel of Tune Model Hyper parameters, choose a value for Parameter sweeping mode. This
option controls how the parameters are selected.
o Entire grid: When you select this option, the component loops over a grid predefined by the
system, to try different combinations and identify the best learner. This option is useful
when you don't know what the best parameter settings might be and want to try all possible
combinations of values.
o Random sweep: When you select this option, the component will randomly select
parameter values over a system-defined range. You must specify the maximum number of
runs that you want the component to execute. This option is useful when you want to
increase model performance by using the metrics of your choice but still conserve
computing resources.
5. For Label column, open the column selector to choose a single label column.
6. Choose the number of runs:
o Maximum number of runs on random sweep: If you choose a random sweep, you can
specify how many times the model should be trained, by using a random combination of
parameter values.
7. For Ranking, choose a single metric to use for ranking the models.
o When you run a parameter sweep, the component calculates all applicable metrics for the
model type and returns them in the Sweep results report. The component uses separate
metrics for regression and classification models.
o However, the metric that you choose determines how the models are ranked. Only the top
model, as ranked by the chosen metric, is output as a trained model to use for scoring.
8. For Random seed, enter an integer number as a pseudo random number generator state used for
randomly selecting parameter values over a pre-defined range. This parameter is only effective if
Parameter sweeping mode is Random sweep.
9. Submit the pipeline.

RESULTS OF HYPER PARAMETER TUNING


When training is complete:
o To view the sweep results, you could either right-click the component, and then select Visualize, or
right-click left output port of the component to visualize.
The Sweep results includes all parameter sweep and accuracy metrics that apply to the
model type, and the metric that you selected for ranking determines which model is
considered "best."
o To save a snapshot of the trained model, select the Outputs+logs tab in the right panel of the
Train model component. Select the Register dataset icon to save the model as a reusable
component.

CHAPTER 7: NEURAL NETWORK REGRESSION: MODULE


REFERENCE - AZURE MACHINE LEARNING (READING)

WHAT IS NEURAL NETWORK REGRESSION?


▪ Neural network regression is a supervised learning method, and therefore requires a tagged dataset, which
includes a label column. Because a regression model predicts a numerical value, the label column must be a
numerical data type.
▪ You can train the model by providing the model and the tagged dataset as an input to Train Model. The
trained model can then be used to predict values for the new input examples.
CONFIGURE NEURAL NETWORK REGRESSION
Neural networks can be extensively customized. This section describes how to create a model using two
methods:
I. Create a neural network model using the default architecture
o If you accept the default neural network architecture, use the Properties pane to set
parameters that control the behavior of the neural network, such as the number of nodes
in the hidden layer, learning rate, and normalization.
o Start here if you are new to neural networks. The component supports many
customizations, as well as model tuning, without deep knowledge of neural networks.
II. Define a custom architecture for a neural network
o Use this option if you want to add extra hidden layers, or fully customize the network
architecture, its connections, and activation functions.
o This option is best if you are already somewhat familiar with neural networks. You use the
Net# language to define the network architecture.
Create a neural network model using the default architecture
1. Add the Neural Network Regression component to your pipeline in the designer. You can find
this component under Machine Learning, Initialize, in the Regression category.
2. Indicate how you want the model to be trained, by setting the Create trainer mode option.
o Single Parameter: Choose this option if you already know how you want to configure the
model.
o Parameter Range: Select this option if you are not sure of the best parameters, and want to
run a parameter sweep. Select a range of values to iterate over, and the Tune Model Hyper
parameters iterates over all possible combinations of the settings you provided to determine
the hyper parameters that produce the optimal results.
3. In Hidden layer specification, select fully connected case. This option creates a model using the
default neural network architecture, which for a neural network regression model, has these
attributes:
o The network has exactly one hidden layer.
o The output layer is fully connected to the hidden layer and the hidden layer is fully
connected to the input layer.
o The number of nodes in the hidden layer can be set by the user (default value is 100).
i. Because the number of nodes in the input layer is determined by the number of
features in the training data, in a regression model there can be only one node
in the output layer.
4. For Number of hidden nodes, type the number of hidden nodes. The default is one hidden layer
with 100 nodes. (This option is not available if you define a custom architecture using Net#.)
5. For learning rate, type a value that defines the step taken at each iteration, before correction.
A larger value for learning rate can cause the model to converge faster, but it can overshoot
local minima.
6. For Number of learning iterations, specify the maximum number of times the algorithm
processes the training cases.
7. For The momentum, type a value to apply during learning as a weight on nodes from previous
iterations.
8. Select the option, Shuffle examples, to change the order of cases between iterations. If you
deselect this option, cases are processed in exactly the same order each time you run the
pipeline.
9. For Random number seed, you can optionally type a value to use as the seed. Specifying a seed
value is useful when you want to ensure repeatability across runs of the same pipeline.
10. Connect a training dataset and train the model:
a. If you set Create trainer mode to Single Parameter, connect a tagged dataset and the
Train Model component.
b. If you set Create trainer mode to Parameter Range, connect a tagged dataset and
train the model by using Tune Model Hyper parameters.
11. Submit the pipeline.

RESULTS
After training is complete:
o To save a snapshot of the trained model, select the Outputs tab in the right panel of the Train
model component. Select the Register dataset icon to save the model as a reusable component.
PRACTICAL
1. Prepare the data
2. Model the data
3. Visualize the data
4. Analyse the data
5. Deploy and maintain deliverables
Solutions:
Problem: Polynomial Logistic Regression on Iris Flowers Dataset for Classification
Problem Description: The Iris flowers dataset basically contains 150 instances of flowers. Each flower has 4
attributes: sepal length, sepal width, petal length and petal width (each in cm) and 3 possible classes it might
belong to: setosa, vermicolor, and virginica.
Our objective is to develop a classifier that can accurately classify a flower as one of the 3 classes based on the
4 features.
There are basically 5 stages involved-
1. Obtain a proper dataset for the task.
2. Analyze and visualize the dataset, and try to gain an intuition about the model you should use.
3. Convert the data into an usable form, and then preprocess it.
4. Build the model, and evaluate it.
5. Check where the model is falling short, and keep improving it.
Algorithm: We used Logistic Regression which is one of the simplest algorithms which on also made to work
relatively well on this dataset-Logistic Regression. In case if you have just begun Machine Learning and do not
know what it is, check this set of lectures out from the popular machine Learning course by Andrew NG. They
are perfect way to get started. Also check out the next series of lectures, i.e. 7, if you aren't familiar with
regularization.
If you are well-versed in linear algebra, univariate and multivariate calculus, probability as well as statistics
already, and would like a deeper mathematical understanding then check out this video from Stanford Online-

A Scatter Plot of 2D Dataset


Figure alongside shows admission scores of students in 2 exams, and whether or not they are admitted to the
school/college based on their scores. What Logistic Regression does is it tries to find a linear decision boundary
that separates the classes the best.
Logistic Regression Decision Boundary
As we can see, LR does a pretty nice job separating the two classes. But what if there are more than two classes,
as in our case? In that situation, we train n classifiers for each of the n classes and have each classifier try to
separate one class from the rest. This technique is rightly known as the "one-vs-all classification'. In the end,
for prediction on an instance, we pick the classifier which detects it's class the strongest, and assign that class
as the predicted class. The decision boundary here is a bit harder to visualize but here is an illustration from
Sklearn-

Getting Started with the Code


Alright, enough with the requisites, now let's get started with the code. We'll be using Python of course,
along with the following modules: Numpy, Matplotlib, Seaborn and Sklearn. In case if like work locally on
your computer like me, make sure you have these modules installed. To install them, simply fire up your
Command Line/Terminal and enter the command “pip install <module-name >”.To check what modules are
installed, Enter "python" then "help(‘modules’)” to generate list of all installed modules.

1. Data Analysis and Visualization


First, we need to get an idea of the distribution of data in the dataset. Let's import the matplotlib and seaborn
modules for this purpose and load the iris dataset contained in the seaborn module.
import matplotlib.pyplot as plt
import seaborn as sns
iris=sns.load_dataset(‘iris’)
This will load the dataset into the dataframe ‘iris’, which will make visualization much easier. Since the
dataset has 4 features we can't visualize it directly but we can gain some intuition through seaborn’s powerful
pairplot. What pairplot does is it makes a scatter plot between each of the pairs of variables in the dataset, as
well as the distribution of values of each variable (along the diagonal graphs). This can be used to analyze
which features are a better separator of the data, which features are closely related, as well as data distribution.
sns.pairplot(iris, hue=’species’) #hue parameter colors distinct species
plt.show()
Seaborn Pairplot on Iris Dataset
Another powerful tool in Seaborn is the heatmap of correlations. Correlation is a statistical measure of how
much two variables are dependent on each other. If an increase in one variable causes a rough increase in a
another variable and vice versa, then they are said to be positively correlated. If an increase in a variable causes
a decrease in another and vice versa, they are negatively correlated and if there is no such dependence between
them, they have zero correlation.
This is how we plot correlations using Seaborn-
sns.heatmap(iris.corr(), annot=True, cmap='coolwarm')
plt.show()
iris.corr() generates a 4*4 matrix with each entry (i,j) representing correlations between the ith and jth
variables. Obviously the matrix is symmetric, since the dependence between i and j is same as that
between j and i (wish this were true for humans too). And the diagonal elements are 1, since a variable
is obviously completely dependent on itself. The annot parameter decides whether to display the
correlation values on top of the heatmap and colormap is set to coolwarm, which means blue for low
values and red for high values.

Correlation Heatmap on Iris Dataset


2. Data Preparation and Preprocessing
Now that we have an intuition about the data, let's load the data into numpy arrays and preprocess it.
Preprocessing is a crucial step and can enhance the performance of your algorithms by a huge margin. We
import the required modules, load the dataset from sklearn's iris datasets class in the form of a dictionary, get
the features and targets into numpy arrays X and Y, respectively and the names of the classes into names. Since
the targets specified in the datasets are 0,1 and 2 representing the 3 classes of species, we would like a mapping
from those integers to the name of the class they represent. To do this, we create a dictionary mapping from the
integers 0,1,2 to the flower names.
import numpy as np
from sklearn.datasets import load_iris
dataset = load_iris()
X, Y, names = dataset['data'], dataset['target'], dataset['target_names']
target = dict(zip(np.array([0, 1, 2]), names))
Let's move forward to the preprocessing step. We divide the data into train and test sets using train_test_split
from sklearn using test set size of 25%, then use the Standard Scaler class from sklearn. What Standard Scaler
does is it computes the mean and standard deviation of each of the features in our dataset, then subtracts off the
mean and divides by the standard deviation each example in our dataset. This brings all of the features to having
zero mean and unit standard deviation/variance. Bringing all of the features in the same range is also known as
feature normalization, and it helps optimization algorithms like gradient descent to work properly and converge
faster.
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.25)
scaler = StandardScaler() #create object of StandardScaler class
scaler.fit(X_train) #fit it to the training set
X_train_pr = scaler.transform(X_train) #apply normalization to the training set
3. Building the Model and Evaluation
It's time for the real deal. It is now that you feel really indebted to sklearn for making your life simple. We
create an object of the Logistic Regression class named model, and fit our training dataset to it, all using 3 lines
of code -
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train_pr, Y_train)
Now, to make predictions we first normalize the test set using the Standard Scaler. Note that the
transformation is the same as applied to the training set (to which we had fit the scaler to). This is important as
we have to normalize our test set as per the mean and standard deviation of our training set, and not the test set.
We then use the predict function to generate the 1D array of predictions both on the training and test set. There
are many metrics available in the metrics class of sklearn but we'll use the 3 most relevant - accuracy,
classification report and confusion matrix.
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
X_test_pr = scaler.transform(X_test)
Y_train_pred, Y_test_pred = model.predict(X_train_pr), model.predict(X_test_pr)
print(accuracy_score(Y_train, Y_train_pred))
print(accuracy_score(Y_test, Y_test_pred)) print(classification_report(Y_test, Y_test_pred))
print(confusion_matrix(Y_test, Y_test_pred))
The dataset is very small, and hence, you might very different results each time you train your model. This
is the output I get

In case if you don't understand any of the metrics you see, feel free to search them they are pretty much
basic and easy to understand. Training set accuracy is approx 95.5% and test set accuracy approx 94.7%. A
weighted average of F1-score of all different classes in the test set is 0.95 and 2 examples from the test set are
classified incorrectly. An accuracy of 94.7% on the training set at first go is really good, but we can do better.

4. Improving the Model


Let's introduce polynomial logistic regression. It turns out that we can build a better model by introducing
polynomial features into the model, like x12, X1X2, X22 to produce a non-linear decision boundary to better
separate the classes. This kind of model is more practical. For example, let us look at this dataset below

A Scatter Plot of 2D Dataset


This dataset looks a little more practical, doesn't it? It shows scores achieved by tests on different
microchips and the classes they belong to. There is clearly no linear decision boundary that can satisfactorily
separate the data. Using polynomial logistic regression, we can get a decision boundary as shown below, which
does a far better job.
Polynomial Logistic Regression Decision Boundary
The lambda=1 in the figure refers to the regularization parameter. Regularization become pretty
important when dealing with non-linear models since you don't want to overfit to your training set and have
your model not perform well on new examples it hasn't seen.
To add polynomial features into your dataset, we use the Polynomial Features class from sklearn. This
will go into your preprocessing as an added step, similar to the feature normalization step. We add 5th power
degree terms, you can try changing it and see the effect it has on your accuracy. It turns out the model starts
overfitting for higher degree terms and we don't want that.
sklearn.preprocessing import Polynomial Features
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.25)
poly = Polynomial Features(degree = 5)
poly.fit(X_train)
X_train_pr=poly.transform(X_train) scaler = StandardScaler()
scaler.fit(X_train_pr)
X_train_pr = scaler.transform(X_train_pr)
Then continue the same steps as discussed above to fit the model. To make predictions, don't forget to
transform the test set using poly first.
X_test_pr = poly.transform(X_test)
X_test_pr = scaler.transform(X_test_pr)
Y_train_pred, Y_test_pred = model.predict(X_train_pr), model.predict(X_test_pr)

Then evaluate the model, using the metrics discussed above. Again, the results will differ with each
time the model is trained. Here is my output

Evaluation of Improved Model


Pretty good results! A training set accuracy of approx 98.2% and a test set accuracy of approx 97.4%
are great using a simple algorithm like logistic regression. Weighted F1-score on test set has improved to 0.97
and the model incorrectly classifies only 1 example from the test set.

5. Generating Predictions
It's time to use the model to generate predictions. We'll give it an array of 4 numbers representing the 4
features of a flower, and it will tell us which species it thinks that it belongs to. We randomly pick 20 examples
from the dataset, preprocess them and get the predicted classes.
indices = np.random.randint(150, size=20)
X_pred, Y_true = X[indices],
Y[indices] X_pred_pr = poly.transform(X_pred)
X_pred_pr = scaler.transform(X_pred_pr)
Y_pred = model.predict(X_pred_pr)
Note that Y_true represents the true class of the example and Y_pred is the predicted class. They are
both integers as the model works with numeric data. We will now create 2 lists, storing the true names and
predicted names of the species of each example, using the dictionary mapping we already created named target.
target_true, target_pred = [], []
for i in range(len(Y_true)):
target_true.append(target[Y_true[i]])
target_pred.append(target[Y_pred[i]])
print(X_pred)
print(target_true)
print(target_pred)

OUTPUT:

Predictions on 20 Random Examples


Due to the high accuracy of our model, all the 20 predictions generated are correct! Here is the complete
code of the final model we created -
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_iris
from sklearn.preprocessing import Polynomial Features, StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
from sklearn.linear_model import LogisticRegression
dataset = load_iris()
X, Y, names = dataset['data'], dataset['target'], dataset['target_names'] target = dict(zip(np.array([0, 1,
2]), names))
iris = sns.load_dataset('iris')
sns.pairplot(iris, hue='species')
sns.heatmap(iris.corr(), annot=True, cmap='coolwarm')
plt.show()
plt.show()
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.25)
poly = Polynomial Features(degree = 5)
poly.fit(X_train)
X_train_pr = poly.transform(X_train)
scaler = StandardScaler()
scaler.fit(X_train_pr)
X_train_pr scaler.transform(X_train_pr)
model = LogisticRegression()
model.fit(X_train_pr, Y_train)
X_test_pr poly.transform(X_test)
X_test_pr=scaler.transform(X_test_pr)
Y_train_pred, Y_test_pred = model.predict(X_train_pr), model.predict(X_test_pr)
print(accuracy_score(Y_train, Y_train_pred))
print(accuracy_score(Y_test, Y_test_pred))
print(classification_report(Y_test, Y_test_pred))
print(confusion_matrix(Y_test, Y_test_pred))
indices np.random.randint(150, size=20)
X_pred, Y_true X[indices], Y[indices]
X_pred_pr poly.transform(X_pred)
X_pred_pr = scaler.transform(X_pred_pr)
Y_pred model.predict(X_pred_pr)
target_true, target_pred = [], []
for i in range(len(Y_true)):
target_true.append(target[Y_true[i]])
target_pred.append(target[Y_pred[i]])
print(X_pred)
print(target_true)
print(target_pred)
ASSIGNMENT QUESTIONS
2 Marks questions
1. What is AI? or Define AI.
2. Who is father of Artificial Intelligence.
3. What is the goal of Artificial Intelligence?
4. What are examples of AI used in your daily life.
5. Mention different Techniques of AI.
6. What is Azure?
7. What is Azure Machine Learning studio?
8. What is Azure Automated Machine Learning?
9. Define Machine Learning
10. What is supervised ML and unsupervised ML?
11. Name the features provided by Microsoft Azure in ML
12. Mention the tools used to create machine learning in Microsoft azure.
13. Define Computer Vision.
14. Name the applications of computer vision.
15. Expand OCR. What is the use of OCR in Computer Vision.
16. Name any four computer task vision.
17. In college office daily attendance through biometric machine is by the technology?
18. Expand NLP. Define NLP.
19. Write the applications of NLP
20. Define Speech Recognition.
21. Define text analytics.
22. Mention the services used in NLP in Microsoft Azure.
23. What is Conversational AI?
24. Write the different examples of Conversational AI.
25. Define BOT.
26. What is Chatbot?
27. Mention the components of conversational AI.
28. What is Tune Model Hyperparameters?
29. What is Neural Network Regression?

5Marks questions
1. Explain Applications of AI.
2. Explain Advantages and Disadvantages of AI
3. Explain 5 key workloads of AI
4. Mention the services provided by Azure.
5. Explain the types of Machine Learning?
6. What are the different types of Azure Machine Learning Compute Resource?
7. What are the steps to be followed to understand the AutoML process?
8. Explain tasks for analyzing images with the Computer Vision service.
9. Write a short note on NLP.
10. Explain the Text Analytics Techniques.
11. Explain different capabilities of language services.
12. How Does Conversational AI Work?
13. Mention the steps to create Conversational AI.
14. Explain the Components of Conversational AI.
15. Differentiate between Human Intelligence and Machine Intelligence.

You might also like