0% found this document useful (0 votes)
38 views68 pages

ch-1 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views68 pages

ch-1 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

Class – X

ARTIFICIAL
INTELLIGENCE

Chapter-1
(Introduction to AI)

What is Intelligence?: Intelligence is the ‘ability to perceive or infer information, and to retain it as
knowledge to be applied towards adaptive behavior within an environment or context.’
Intelligence includes the following abilities:
 Ability to learning from experience
 Identifying and solving new problem s
 Planning and making decisions
 Ability to deal with unexpected problems, uncertainties.

Types of Intelligence:
There are nine types of intelligence defined as:
1. Mathematical Logical Reasoning:Ability to understand mathematical logics, theories, formulae and
expressions
2. Linguistic Intelligence: Language skills-reading, writing, listening and speaking
3. Spatial Visual Intelligence: Perceiving the visual world around us and the relationship between
different objects and things.
4. Kinesthetic Intelligence: Awareness of the position and movement of body parts by means of sensory
organs
5. Musical Intelligence: Ability to create, identify and understand musical notes, rhymes and patterns
6. Intrapersonal Intelligence: Ability of self-awareness and knowing about one's own self-skills, abilities,
weaknesses, etc.
7. Existential Intelligence: Awareness of spiritual and ontology-related areas
8. Naturalist Intelligence: Processing information around the environment and nature
9. Interpersonal Intelligence: Communicating with others with an understanding of how they feel and
perceive

What is Artificial Intelligence?: Artificial Intelligence or AI refers to software technologies that make a
robot or computer act and think like a human. Artificial Intelligence (AI) is the simulation of human intelligence
process by machines, especially computer system. Speech recognition, decision making, language translation are
some features of human intelligence that artificial may possess.

How Machines Become Artificially Intelligent?:Machines become intelligent once they are
trained with some information which helps them achieve their tasks. Al machines also keep updating their
knowledge to optimize their output.

How We Make Decisions: Our brain makes decisions based on past experiences and availability of
information which includes self-awareness, intuition and knowledge. It also uses the nine intelligence skills and
abilities.

Applications of AI around us:

1. Pocket Assistants: Pocket assistants uses AI technologies such as Natural Language Processing and
Machine Learning to understand what the user is saying, and can do a lot of tasks at just one command.
Alexa, Google Assistant, Cortana, Siri are some very common examples of the voice assistants which are a
major part of our digital devices.
2. Autonomous Vehicles: AI enables self-driving cars to perceive their environment, make decisions, and
navigate safely without human intervention, potentially revolutionizing transportation.
3. Google Maps: Google Maps uses Al technology, known as global localization that provides detailed
information about geographical regions and sites around the world. Google maps can analyze the speed of
movement of traffic at any given time.
4. E-commerce and Recommendation Systems: AI powers recommendation engines that suggest
products based on user preferences, improving customer experience and sales.
5. Recommendation System: A recommendation engine is an information filtering system rendering
information tailored to users' interests and preferences. It is able to predict a specific user's preference for
an item based on their profile. Amazon uses recommendations for targeted marketing via email campaigns
and website pages.
6. Chatbots: Chatbots are essentially software applications that use Al and NLP to assist humans and
communicate through text or voice.

Depending on how they are programmed, they can be categorized as:

a) Simple chatbots: They work on pre-written keywords that they understand. Each of the
commands that they are going to follow must be coded into them by the developer. So, if a user
asks them something outside of their knowledge base, they respond with "sorry, I did not
understand", or something along those lines.
b) Smart chatbots: Smart chatbots are based on Al, these bots don't have pre-programmed answers.
They learn with time, catching keywords and putting them in context, and help users arrive at the
most relevant answers to their queries.

What is Not AI:Al is not just automation; Al means the use of own intelligence not just the automation.
A fully automatic washing machine can work on its own, but it requires human intervention to select the
parameters of washing and to do the necessary preparation for it to function correctly before each wash, which
makes it an example of automation, not Al.
An air conditioner can be operate remotely with the help of internet but still needs a human touch. This
is an example of Internet of Things (IOT), not AI.
We can also say that not all the devices which are "smart" in works are Al-enabled. For example, a smart
TV does not become Al-enabled if it is a smart one.

Difference between what is AI and what is not AI .

AI Machine Not AI machine

1. AI machines are trained with data and


1. Smart machines which are not AI, do not
algorithm.
require training data, they work on algorithms
2. AI machines learn from mistakes and
only.
experience. They try to improvise on their next
2. Smart machines work on fixed algorithms and
iterations.
they always work with the same level of
3. AI machines can analyses the situation and can
efficiency, which is programmed into them.
take decisions accordingly.
3. Machines which are not AI cannot take
4. AI based drones capture the real-time data
decisions on their own.
during the flight, processes it in real-time, and
4. An automatic door in a shopping mall, seems
makes a human-independent decision based on
to be AI-enabled, but it is built with only
the processed data.
sensor technology.

AI, ML & DL:


Artificial Intelligence (AI): Artificial Intelligence refers to any technique that
enables Computers to mimic human intelligence. An artificially intelligent
machine works on algorithms and data fed to it and gives the desired output.
Machine Learning:Machine Learning is an application of artificial intelligence
(AI) that provides the ability to automatically learn and improve from
experience. The intention of Machine Learning is to enable machines to learn by
themselves using the provided data and make accurate Predictions/ Decisions.
Deep Learning:It enables software to train itself to perform tasks with vast
amounts of data. In Deep Learning, the machine is trained with huge amounts of
data which helps it in training itself around the data. Such machines are intelligent
enough to develop algorithms for themselves. Deep Learning is the most advanced
form of Artificial Intelligence out of these three.

Domains of Artificial Intelligence (AI):

With respect to the type of data fed in the AI model, AI models can be broadly categorized into three domains:
1. Data Science 2. Computer Vision (CV) 3. Natural language Processing (NLP)

1. Data Science: Data science is a field that uses scientific methods, processes, algorithms and systems to
extract knowledge and insights from many structural and unstructured data.
Data science is related to data mining, machine learning and big data.
Data Mining: Data Mining is a process of finding potentially useful patterns from huge data sets.
Machine Learning (ML): Machine Learning is a process of automatic learning of computers and
machines by dis- covering insights from data with experience.
Big Data: Big Data refers to huge amounts of data, which is regularly growing at an exponential rate,
e.g., data of social media (posts, pictures, responses, users, etc.).
Some applications of Data Science are:
o Price comparison website
o Recommendation System

2. Computer Vision: Computer Vision refers to the training of computers to have a vision somewhat like
humans so that machines can accurately identify and classify objects and produce specific 'reactions'.
Some applications of Computer Vision are:
o Cancer Detection using Computer Vision
o Analysis of X-rays, MRI, and CT scans using Computer Vision
o Self-driving cars
o Analyzing text and barcodes (OCR)
o Fingerprint recognition and Biometrics
o Facial recognition & Facial filters
o Goggle lens

3. Natural Language Processing (NLP) :Natural Language Processing (NLP) is a subfield of AI, mainly
concerned with the interactions between computers and human languages in the form of speech input and
speech output.
Some applications of NLP are:
o Chatbots
o Autocomplete in Search Engines
o Voice Assistants
o Language Translator
o Grammar Checkers
o Email Classification and Filtering

Ethics in AI: AI ethics is a system of moral principles and techniques intended to inform the development and
responsible use of artificial intelligence technology. As AI has become integral to products and services, organizations
are starting to develop AI codes of ethics.
Major ethical issues of Al are:

 Bias and Fairness


 Accountability
 Safety
 Human-AI interaction
 Trust, privacy and control
 Cyber security and malicious use
 Transparency
 Automation and impact over jobs
 Democracy, civil rights, Robot right etc.

Data Privacy:
The world of Artificial Intelligence revolves around Data. Every company whether small or big is mining data from as
many sources as possible. It is not wrongly said that Data is the new gold. One of the major sources of data for many
major companies is the smartphone
Whenever you download an app and install it, it asks you for several permissions to access the app, we
allow the app to get all the permissions that it wants. We need to understand that the data which is collected by
various applications is ethical as the smartphone users agree to it. But at the same time if one does not want to
share his/her data with anyone, he/she can opt for alternative applications. For example, an alternative to
WhatsApp is the Telegram app which does not collect any data from us.

What is AI bias ? AI Bias means favoring someone or something. When we talk about a machine, we know that it
is artificial and cannot think on its own. It can have intelligence, but we cannot expect a machine to have any biases of
its own. Any bias can transfer from the developer to the machine while the algorithm is being developed. Let us look at
some of the examples of AI Bias:
1. Majorly, all the virtual assistants have a female voice.
2. If you search on Google for salons, the first few searches are mostly for female salons.

AI Access: Since Artificial Intelligence is still a budding technology, not everyone has the opportunity to access it. The
people who can afford AI enabled devices make the most of it while others who cannot are left behind. Because of this,
a gap has emerged between these two classes of people and it gets widened with the rapid advancement of technology.
Let us understand this with the help of some examples:
 AI creates unemployment:AI is making people’s lives easier. Most of the things nowadays are done in just
a few clicks. In no time AI will manage to be able to do all the laborious tasks which we humans have been doing
since long. Maybe in the coming years, AI enabled machines will replace all the people who work as labourers.
This may start an era of mass unemployment where people having little or no skills may be left without jobs and
others who keep up with their skills according to what is required, will flourish.
 AI for kids:As we all can see, kids nowadays are smart enough to understand technology from a very early
age. As their thinking capabilities increase, they learn everything more easily than an adult. But should
technology be given to children so young?
Consider this: A young boy in class 3 has got some Maths homework to finish. He is sitting at a table
which has the Google chat bot - Alexa on it, and he is struggling with his homework. Soon, he starts asking Alexa
to answer all his questions. Alexa replies with answers and the boy simply writes them down in his notebook.
On one hand where it is good that the boy knows how to use technology effectively, on the other hand
he uses it to complete his homework without really learning anything since he is not applying his brain to solve
the Math problems. So, while he is smart, he might not be getting educated properly.

Class – X
ARTIFICIAL
INTELLIGENCE

Unit-2
(AI Project Cycle)

Introduction to AI Project Cycle:


An AI Project Cycle is the sequence of phases that a project goes through from its initiation to
its closure. The project cycle provides the basic foundation of the actions that has to be performed in
the project, irrespective of the specific work involved.
Stages of AI Project Cycle:
An AI project cycle involved the following phases which are as follows:

Problem Scoping: The problem scoping refers to the identification of a problem and the vision to solve it.

Data Acquisition: This stage includes acquiring (collecting) the data for the AI project.

Data Exploration: This includes exploring the data, interpreting some useful information out of the acquired
data and put it uniformly for a better understanding of the data.

Modeling: This includes looking at different AI-enabled algorithms, going through several models and select
the ones which match your requirements and then implementing the chosen model.

Evaluation: This includes deploying the concerned model in the real world and evaluating each and every
model and then choosing the model which gives the most efficient and reliable results.

Problem Scoping
What is Problem Scoping?:
Problem Scoping is the first stage of the AI project cycle. In this stage of AI development,
problems will be identified. It is then followed by designing, developing, or building, and finally testing
the project.
In AI project cycle everything will be failed if problem scoping is failed or without appropriate
problem scoping. Incorrect problem scoping also leads to failure of the project as well.
How to scoping a problem?:
To scoping a problem first we choose a theme for our project e.g, Environment, agriculture,
Digital Literacy, Health, Cyber Security etc. we can even choose a theme from the 17 SDGs (Sustainable
Development Goal). We will then look inside the theme and find out topics where problems exist. After
listing down the topics select any one topic out of them. we will then find out various problems related
to the topic. select any one problem out of them and write it as the goal of our project.
For example we choose a theme for our AI Project based on Sustainable Development Goal:3 i.e
“Good Health and Well-Being” and choose a topic for that theme is “Face Mask Detection System”.
After choosing the theme and its subtopic let us first identify the issues and problems around it
so that AI can help with it.
After studying the problems listed for the chosen topic, we have decided to address these
problems and thus the goal of our Face mask detection system is :
“Make a Camera based AI system that can check for presence and absence of face mask on
people in movement”.

4Ws Problem Canvas:


This canvas helps us in identifying 4 crucial parameters we need to know for solving a problem.
It refers to Who, What, When and Why.”

Who?: In this stage, we are looking at the person who is having the problem, they are also
known as the stakeholders of the problem.

What? In this stage, we consider the nature of the problem. What is the problem and how do
you know that it is a problem? Is there evidence to support that it is a problem?”

Where/when?: This block will help us look into the situation in which the problem arises, the
context of it, and the locations where it is prominent.

Why?: Refers to why we need to solve the problem and what are the benefits to the
stakeholders after solving the problem

4Ws Canvas for AI Project for FACE Mask Detection


WHERE/WHEN does the problem
WHO has the problem? WHAT is the Problem?
arise?
When people step out of their
Agencies insuring public health 1. People do not wear face mask homes without wearing face
and wellbeing 2. People wear mark wrongly marks or wearing face mask
wrongly
WHY the problem should be solved
It is important to ensure that the people wear face mask properly at public species so that infection
spreading is reduced and a clear and safe environment is made available to people

Problem Statement Template: The Problem Statement Template helps us to summarize all the key
points into one single template. So that in the future, whenever there is a need to look back at the basis of
the problem, we can take a look at the Problem Statement Template and understand its key elements of it.

Our Stakeholder Who


Has /Have a Issue/Problem What
problem that
When/While Context/Situation/Location Where
An ideal How the Solution will help
Why
solution would Stakholder

Problem Statement Template

Let us now try to write the problem statement for our AI project of “Face Mask Detection”.

“Government and non-government agencies responsible for public health and well-being (WHO) ensure that
a safe and healthy environment is made available to people. For this, certain rules and laws are in place - one
such rule by law is to wear face masks on public places, especially during pandemic times.
But, some people violate this law and do not wear face masks (WHAT) at public places
(WHERE) or wear them wrongly (WHAT)
It is important to ensure that face masks are worn properly to ensure a safe, infection-
freepublic environment for people (WHY).

Data Acquisition
What is Data: Data can be a piece of information or facts and statistics collected together for reference or
analysis. Whenever we want an AI project to be able to predict an output, we need to train it first using data.

For example, if we want to make an Artificially Intelligent system which can help to identify
fruits, based on pictures of various fruits already fed into the system. This is the data with which the
machine can be trained. Now, once it is ready it will identify a given' fruit efficiently. The pictures of
various fruits here are known as Training Data while the picture of the fruit to be identified is known as
the Testing Data.
Data Features: Data features refer to the type of data we want to collect for our project. For example
fruits identification system, data features would be the name of the fruit, the color of the fruit, the shape of
the fruit, etc. After finding out the Data features, we now need to acquire the same.

Data Acquisition: Data acquisition is the second stage of the AI project cycle. Which is used to collect
data for the problem scoped and this data needs to be authentic, reliable and consistent.

Finding Reliable Data Source: There can be different sources where from data may be collected.most
commonly used data sources are being discussed below.

1. Surveys:A survey refers to study of the opinions, responses, etc. of a group of stakeholders

2. Web Scraping:Wab scrapping refers to a data collection technique using a tool called wab scraper that
extract data from websites.

3. Cameras:The method of data collection using cameras is a way to collect data graphically or in video
form about the look, design or action as par the requirements
4. Observations:The observation method refers to human or mechanical watching, notifying or perceiving
of what people actually do or what event take place in a specific working environment.

5. Sensors:Sensors are mini devices that can collect data about an environment of a body or specific task.

6. Application Program Interface (API ):An API refers to application programming interface that works
behind popular software program or game to collect specific type of data partaining to users way of using
that program

Points to remember while acquisition of data:

1. Data should not be collected from random websites as the data might not be authentic.
2. Data which we collect should be open sourced. Extracting private data can be an offence.

Data Exploration

What is data exploration?: Data exploration is the phase after data acquisition in AI Project Cycle,
wherein the collected data is cleaned by removing redundant data and handling missing values and then
analysed using data visualisation and statistical techniques to understand the nature of data before it can be
converted into AI models.

Data Visualisation: Data visualisation refers to the process of representing data visually or graphically,
by using visual elements like charts, graphs, diagrams and maps etc. It can help in:

1. A better understanding of data.


2. Reduces complexity of data.
3. Define strategy for which model to use at a later stage.
4. Provides the relationships and patterns contained within data.
5. Provides an effective way of communication among users.
6. Allows user interaction.
7. Help to make decisions.

Data Visualisation Techniques:

1. SCATTER CHART:

An XY (scatter) chart either shows the relationships among the numeric values in several data
series or plots two groups of numbers as one series of XY coordinates.
The scatter chart is drawn by plotting the independent variable on the horizontal axis X, the
dependent variable on the vertical axis Y and then by marking data points as per their XY values
Example:

The local ice cream shop keeps track of how much ice cream they sell versus the noon temperature on that
day. Following is the Scatter Diagram which shows the figures for the last 12 days:

2. BUBBLE CHART:
A bubble chart is primarily used to depict and show relationships between numeric variables with
marker size as additional dimension. Bigger marker means bigger value.
The bubble chart is drawn by plotting the independent variable on the horizontal axis (X), the
dependent variable on the vertical axis (Y) and then by marking bubbles at their XY values. The Y values
will determine the bubble size.

3. LINE GRAPH:
A line chart shows trends in data at equal intervals. Line charts are useful for
depicting the change in a value over a period of time.
The line chart is drawn by plotting the independent variable on the horizontal axis
(X), the dependent variable on the vertical axis (Y) and then by marking data points as per their XY values.
Then a line is drawn by joining the marked data points.
4. PIE GRAPH:
A pie chart shows the proportional size of items that make up a single data series to the sum of
the items.
The pie chart represents single data series, whole of which represents full circle (360°). Each
data value is calculated as a percentage of whole and drawn as a pie of the circle.

Histogram: A histogram is used to summarize discrete or continuous data by showing the


number of data points that fall within a specified range of values (called "bins"). Unlike a bar chart.
there are no gaps in between in a histogram.
BAR Chart: A bar chart illustrates comparisons among individual items, mainly of number types.
The bar chart is drawn by plotting the independent variable on the horizontal axis (X), the
dependent variable(s) on the vertical axis (Y) and then by marking bars for their Y values.

Modelling

What is Modelling?: Al Modelling refers to developing algorithms, also called models which can be
trained to get intelligent outputs. That is, writing codes to make a machine artificially intelligent.
Generally, AI models can be classified as follows:

Rule Based Approach: Rule Based Approach refers to the AI modelling where the relationship or pattern in data are
defined by the developer. The machine follows the rules or instructions mentioned by the developer and performs its
task accordingly. Decision Tree is an example of rule based AI model.
Decision Tree (Rule Based Approach): Decision tree is the most powerful and popular tool for classification and
prediction. A Decision tree is a flowchart like tree structure, where each internal node denotes a test on an attribute,
each branch represents an outcome of the test, and each leaf node (terminal node) holds a class label.

Learning Based Approach: Learning Based Approach refers to the Al modelling where the relationship or patterns
in data are not defined by the developer. In this approach, random data is fed to the machine and it is left on the
machine to figure out patterns and trends out of it.
Generally this approach is followed when the data is unlabeled and too random for a human to make
sense out of it.Thus, the machine looks at the data, tries to extract similar features out of it and clusters same
datasets together.In the end as output, the machine tells us about the trends which it observed in
the training data. `

The learning-based approach can further be divided into three parts:


1. Supervised Learning
2. Unsupervised Learning
3. Reinforcement Learning

Supervised Learning: In a supervised learning model, the dataset which is fed to the machine is labelled. In other
words, we can say that the dataset is known to the person who is training the machine only then he/she is able to label
the data.A label is some information which can be used as a tag for data.
There are two types of Supervised Learning models:

Classification: A Classification Al model refers to a type of Supervised Learning technique, which can
classify the category of new unlabeled test inputs on the basis of training data.
Some examples of problem that a classification model may answer are:
1. Is this a picture of a specific animal?
2. Is this email Spam or not?
3. Is this social media post negative or positive (Predict the sentiment)?
4. Is it going to rain or not?
Regression: Regression AI model refers to a type of Supervised Learning technique, which is based on
a mathematical approach used to find the relationship between two or more variables and predict the outcome.
Some examples of problems that a regression model may answer, are:

1. What would be the house prices in the wake of factors like square footage, lo proximity to schools, hospitals,
public transport etc.
2. What will be the sales if the historical data of demand and sales is available and other factors like marketing and
target customers are known?

Unsupervised Learning: An unsupervised learning model works on unlabeled dataset. This means that the data
which is fed to the machine is random and there is a possibility that the person who is training the model does not have
any information regarding it.The unsupervised learning models are used to identify relationships, patterns and trends
out of the data which is fed into it.It helps the user in understanding what the data is about and what are the major
features identified by the machine in it.
Unsupervised learning models can be further divided into two categories:

Clustering: Refers to the unsupervised learning algorithm which can cluster the unknown data
according to the patterns or trends identified out of it. The patterns observed might be the ones which are
known to the developer or it might even come up with some unique patterns out of it.
Some examples of clustering problems/applications are :
1. Pattern recognition. A group of cancer patients may be considered for a special type of treatment on
the basis of their gene expression measurements.
2. Identifying fake news by clustering articles with high percentage of sensationalizing and click-bait terms.
3. Document analysis by clustering and organising similar documents quickly using the characteristics
identified in the paragraphs of multiple documents.

Dimensionality Reduction: Dimensionality reduction is an unsupervised learning approach that


uses techniques for reducing the number of input variables in training data while retaining its
sense and meaning. For example 2D to 1D, 3D to 2D. Used basically for two purpose:
1. Data Compressing
2. Data Visualization
Reinforcement Learning: Reinforcement Learning (RL) is the science of decision making. It is about learning the
optimal behavior in an environment to obtain maximum reward. This optimal behavior is learned through interactions
with the environment and observations of how it responds, similar to children exploring the world around them and
learning the actions that help them achieve a goal.
Broadly, there are two types of Reinforcement Learning:

1. Positive Reinforcement Learning:Which focusses on increasing rewards to encourage a certain behavior.


2. Negative Reinforcement Learning: That focusses on removing or lessening penalty to encourage a certain
type of behavior.

Some applications of Reinforcement Learning are:

1. Training Self-driving cars about how to drive on roads, in traffic situations.


2. Training robots to perform difficult and dangerous tasks in various industries.
3. Text summarizing engines and Dialogue agents that use text and speech (in NLP), suchas Siri, Alexa, Google
Assistant etc.
4. In healthcare for determining time-dependent decisions for the best treatment for apatient at a specific time.

NEURAL NETWORKS

BIOLOGICAL NEURAL NETWORKS: Brain is the CPU for human that controls the whole body. Brain is a huge and
complex network of approximately 1011 neurons, with each neuron connects approximately 104 toother neurons.
A neuron has the following components:

 Soma. It is a cell body that contains nucleus, and sums and thresholds all incoming signals.
 Axon. The axon is a long fibre that carries signal from the cell body out to other neurons.
 numerous Dendrites. Dendrites are tree-like receptive networks of nerve fibres that carry electrical signals
into the cell body.
 Synapse. The point of contact between an axon of one cell and a dendrite of another cell is called a synapse.

Pulses from other neurons are inputted to the soma from the dendrites via synapses, and are integrated there. The
neuron sends a pulse to other neurons through the axon, via synapses.

Artificial Neural Networks(ANN) :


The neural networks are the model that how neurons in the human brain behave. It is also
known as ANN (Artificial Neural Network) that copy the working of the human brain neurons or cells
inside the computers. It can extract the features of data without any programming or input. The
computer can learn, recognize, and make decisions like human beings.A neural network is essentially a
system of organizing machine learning algorithms to perform certain tasks. It is a fast and efficient way
to solve problems for which the dataset is very large.

As seen in the figure given, the larger Neural Networks tend to perform better with larger
amounts of data whereas the traditional machine learning algorithms stop improving after a certain
saturation point.

Structor of ANN:

Neural network is divided into different layers and each layer is divided into a block that accomplishes its
own task and then passes to the next layer.

Neural network is divided into different layers and each layer is divided into a block that accomplishes its own task and
then passes to the next layer.There are three types of layers in an ANN:

1. Input Layer:The first layer of a Neural Network is called the input layer, whose role is to acquire data and feed it
to the Neural Network. The input layer carries out no processing, it just takes the input data and passes it on to
the next connected layer.
2. Hidden Layer:Input layer is connected to a hidden layer, which is further connected to other hidden layers or to
the final output layer. The role of hidden layers is to process the inputs and carry out a task.There can be multiple
hidden layers in an ANN depending upon the complexity of the task(s) being performed.
3. Output Layer:After processed data travels through multiple hidden layers, it (the final processed data) is finally
fed to the final layer known as the output layer. The output layer simply provides the final output to the user. At
the output layer also, no processing takes place; it only provides user-interface for the output

Features of a Neural Network:


1. Neural Network systems are modelled on the human brain and nervous stem.
2. They are able to automatically extract features of data without input from the programmer.
3. Every neural network node is essentially a machine learning algorithm.
4. it is useful when solving problems for which the data set is very large.

Comparison between BNN and ANN .

Criteria Biological Neural Network Artificial Neural Network (ANN)


(BNN)
Processing Parallel, Slow but is superior Parallel, Fast but is inferior than
than ANN BNN
Learning Ambiguity can be tolerated Structured, precise data is
required to tolerate ambiguity
Fault Performance degrades even Has the potential to be fault
Tolerance with partial damage to the tolerant due to its capability of
system capability robust performance
Storage Stores the information in the Stores the information in
synapse contiguous memory location
Class – X

ARTIFICIAL
INTELLIGENCE

Unit 3
(Advanced Python)
PYTHON:
Python is an open source object oriented, high level programming language. It was developed
by Guido Van Rossum in February 1991 at the National Research Institute for Mathematics and
Computer Science in the Netherlands. It is based on ABC language, a teaching language created as a
replacement of BASIC language.

Features of Python:
1. Python language is freely available, which means it doesn't cost anything to use Python. It is open
source, so it can be freely modified and redistributed.
2. Python uses a few keywords and clear, simple English like structure. Thus it is very easy to read and
understand and is developer friendly.
3. Python can run on a variety of platforms - Windows, Linux, Macintosh, smart phones (Android,
iOS), etc which means it is a portable language.
4. Python supports procedure-oriented as well as object-oriented programming.
5. It supports graphical user interface.
6. It is compatible with C, C+ languages, etc.
7. There are a variety of applications of this language. Python is used in Game development, database
applications, web applications, Artificial Intelligence, etc.
8. Python has a huge bunch of libraries with plenty of built-in functions to solve a variety of problems.
9. Python has support for interactive mode which allows interactive testing and debugging of snippets
of code.

Applications of Python:
1. Web and Internet Development:Python offers many choices for web development
2. Scientific and Numeric: Python is widely used in scientific and numeric computing.
3. Education: Python is a superb language for teaching programming, both at the introductory level
and in more advanced courses.
4. Software Development: Python is often used as a support language for software developers, for
build control and management, testing, and in many other ways.
5. Business Applications: Python is also used to build ERP and e-commerce systems

Working in Python:

(i) in Interactive mode ii) in Script mode

Working in Interactive Mode:


Interactive mode of working means you type the command - one command at a time, and
thePython executes the given command there and then and gives you output.
In this kind of mode, you have to type the command in front of Python command prompt >>> .
For example, if you type 4+5 in front of Python Prompt, it will give you the result as 9.
To work in interactive mode, follow the process given below:

Step 1: Click Start button All Programs Python 3.8 IDLE (Python 3.8 32-bit)
Or
Click Start button All Programs Python 3.8 Python 3.8 (32-bit)

Step 2: It will open Python Shell where you'll see thePython prompt (three ‘>’ signs i.e., >>>).

Step 3: Type commands in front of this Python prompt and Python will immediately give
you the result.
Working in Script Mode:
The script mode allows us to write all the commands in the form of a program file,and we can
see alloutput lines together. The commands in the program are executed sequentially. All the errors of
the program are shown together after the entire program execution is over.
To work in a script mode, you need to do the following:

Step 1:Click Start button All Programs Python 3.8 IDLE (Python 3.8 32-bit )
Step 2: Click File New File, in IDLE Python Shell.
Step 3: In the New window that opens, type the commands you want to save in the form of a program (or
script).
For example, for the simple Hello World program, you'll need to type following line :

Print ("Hello World!")

Step 4:Click FileSave, and then save the file with an extension .py. For example first.py, Now your program
would be saved on the disk and the saved file will have .py extension.

How to Execute/Run a Script/Program:


After the program/script file is created, we can run it by the following given steps:
Step 1: Open the script/program created by you by using the command, File Open option.
Step 2:Click Run Run Module command in the open program/ script file'swindow.You may also press F5 key.
Step 3:And it will execute all the commands stored in module / program/ script that youhad opened and show
you the complete output in a separate Python Shell window.

Python IDE (Integrated Development Environment):


IDE typically provides code editor, compiler/ interpreter and debugger in one GUI (Graphical
User Interface). It encapsulates the entire process of code creation, compilation and testing which
increases the productivity of developers.
IDLE is Python's Integrated Development and Learning Environment and is an alternative to the
command line. As the name may imply, IDLE is very useful for developing new code or learning Python.
On Windows this comes with the Python interpreter, but in other operating systems you may need to
install it through your package manager.

Python Character Set:


Character set is a set of valid characters that a language can recognize. A character represents
any letter, digit or any other symbol. The Python Character Set includes:

Letters A-Z, a-z


Digits 0-9
Special Symbols Space + - * / ** \ () [] // = != == <> . ‘ ‘ “ , ; : % !
Whitespaces Blank space, tabs (-), carriage return (), newline, form feed
Other Python can process all ASCII and Unicode characters as part of data or
Characters literals.

Keywords:
 The Keywords are some predefined and reserved words in python that have special meanings.
 Keywords are used to define the syntax of the coding.
 The keywords cannot be used as an identifier, functions, and variable name.
 All the keywords in python are written in lower case except –True, False, and None.
 For python 3.8.0, there are 35 keywords in total and may change slightly with versions.
Identifiers:
The identifier is a name used to identify a variable, function, class, module, etc. It helps to
differentiate one entity from another.

Rules for writing identifiers:

1. Every identifier name should start with alphabets or underscore (_).


2. No spaces are allowed in identifier declaration.
3. Except underscore ( _ ) no other special symbol are allowed in the middle of the identifier.
4. An identifier is written with a combination of letters, numbers and special characters _ (underscore)
5. Keywords cannot be used as identifier.

Variables:
A variable is a named location used to store data in the memory. It is helpful to think of variable
as a container that holds data that can be changed later in the program.

Rules for writing Variables:


1. Every variable name should start with alphabets or underscore (_).
2. No spaces are allowed in variable declaration.
3. Except underscore ( _ ) no other special symbol are allowed in the middle of the variable
declaration
4. A variable is written with a combination of letters, numbers and special characters _ (underscore)
5. Keywords cannot be used as variable.

Examples of valid variable names are:last _name, name, name1, _name


Examples of invalid variable names:last-name, 9marks, marks%

Data types:
Data type represents the type of data stored into a variable or memory. Python offers the
following standard data types:
1. Numeric/Number Data Type: Numeric data type is used to store Numerical values. Python
supports the following numerical types:

(i) Integer:The integer datatype represents an integer number. An integer number without any
decimal point or fraction part. In Python, It is possible to store very large integer number as there is no
limit for the size of an int datatype.

Example:
20, 10, -50, -1002
y = 10
pin_code = 564512

(ii) Float:The float data type represents floating point numbers. A floating point number is a
number that contains a decimal point.

(iv) Complex:A complex number is a number that is written in the form of a + bj or a + bJ.
Where,

a = Real Part of the number


b = Imaginary part of the number
j or J = Square root value of -1
a and b may contain integer or float number.

Example:
5+7j, 0.8+2j
com = 5+7j

2. Dictionary:A dictionary represents a group of elements in the form of key value pairs. Each
key is separated from its value by a colon (:), the items are separated by commas, and the entire
dictionary is enclosed in curly braces.
Example:
data = {101: ‘Rahul’, 102: ‘Raj’, 103: ‘Sonam’ }
data = {‘rahul’:2000, ‘raj’:3000, ‘sonam’:8000, }

3. Boolen Type:The bool datatype represents boolean value True or False. Python internally
represents True as 1 and False as 0.
Example:
True, False
True + True = 2
True – False = 1

4. Set: A set is an unordered collection of elements. The order of elements may not appear in
the same order. It means the elements may not appear in the same order as they are entered into the
set. A set does not accept duplicate elements. Sets are unordered so we can not access its element
using index. Sets are represented using curly brackets { }.

Example:
data = {10, 20, 30, “India”, “Raj”, 40}
data = {10, 20, 30, “India”, “Raj”, 40, 10, 20}

5. Sequence Type:Following are the sequence type:-


 String
 List
 Tuple

(i) Strings:String represents group of characters. Strings are enclosed in double quotes or single
quotes.

Ex:- “Hello”, “My India”, ‘Rahul’


str1 = “I love my country”
str1 = ‘I love my country’
(ii) Lists: A list represents a group of elements. A list can store different types of elements which can be
modified. Lists are dynamic which means size is not fixed. Lists are represented using square bracket [ ].

Ex:- data = [10, 20, -50, 21.3, ‘My India’]

(iii) Tuple:A tuple contains a group of elements which can be different types. It is similar to List
but Tuples are read-only which means we can not modify it’s element. Tuples are represented using
parentheses ( ).

Ex:- data = (10, 20, -50, 21.3, ‘My India’)

OPERATORS: Operators are special symbols that perform an operation. Various types of operators are as
follows:
• Arithmetic Operators
• Relational Operators / Comparison Operators
• Logical Operators
• Assignment Operators

1. Arithmetic operators: Arithmetic Operators are used to perform basic arithmetic operations
like addition, subtraction, division etc.
There are 7 arithmetic operators in Python :
Example1. What will be the output produced by the following code?

Code:
A=9.2
B=2.0
C=4
D=21
print (A/4)
print (A//4)
print (B**C)
print (D//B)
print (A%C)
Output:
2.3
2.0
16.0
10.0
1.2

Example 2. Print the area of a circle of radius 3.75 metres.

Solution:
Radius = 3.75
Area = 3.14159*Radius**2
print (Area, 'sq. metre')
Output:
44.178609375 sq. metre

2. Relational operators: Relational operators are used for comparing two values. It either returns True or
False according to the condition. These operators are also known as Comparison Operators.
There are 6 Relational operators in Python :

Example:
a=5
a=5
b=2
b=2
value = a < b
value = a >= b
3. Logical operators: Logical operators are used to connect more relational operations to form a
complex expression called logical expression. A value obtained by evaluating a logical expression is
always logical, i.e. either True or False.
There are 3 Logical operators in Python :

Example:

Logical and Logical or Logical not

a=5 a=5 a=5


b=2 b=2 b=2
c=3 c=3 print(not(a<b))
print(a>b and a>c) print(a>b or a>c)
print(a>b and a<c) print(a>b or a<c) Output:
print(a<b and a>c) print(a<b or a>c) True
print(a<b and a<c) print(a<b or a<c)

Output: Output:
True True
False True
False True
False False
4. Assignment Operators:Assignment Operators are used to assigning values to variables.
There are 8 Assignment operators in Python.

Example:

a = 10 Output
b = 20
m = 15
y=a+b 30
print(y) 25
m+=10 15
print(m) 150
15.0
m-=10 5.0
print(m) 25.0
2.0
m*=10
print(m)

m/=10
print(m)

m%=10
print(m)

m**=2
print(m)

m//=10
print(m)

Operator Precedence and Associativity:


The computer scans an expression which contains the operators from left to right and performs
only one operation at a time. The expression will be scanned many times to produce the result. The order in
which various operations are performed is known as hierarchy of operations or operator precedence . Some
of the operators of the same level of precedence are evaluated from left to right or right to left. This is
referred to associativity.
Example:

Type Conversion: The process of converting one data type (integer, string,float etc.) to another data type is
called type conversion. Python has two types of type conversion:
1. Implicit Type Conversion
2. Explicit Type Conversion

Implicit Type Conversion: In the Implicit type conversion, python automatically converts one data type into
another data type. This process doesn’t need any user involvement.

For example:

a=5 x = 10
b=2 y = 5.5
value = a/b total = x + y
print (value) print(total)

Output: Output:
2.5 15.5

Explicit Type Conversion: In the Cast/Explicit Type Conversion, Programmer converts one data type into
another data type.
For example:

a=5 q = 20
b=2 u = '10'
value = a/b r = q + int(u)
print(int(value)) print(r)

Output:
2 Output:
30

Output Statements:
print( ) Function - The print() function is used to print the specified message to the output
screen/device. The message can be a string, or any other object.

Syntax:-
print(obj1, obj2, obj3…….)
print(str1, str2, str3……….)

various methods to use print() function are as follows:

 print ( ) – This function is used to display a blank line.


 print(“string”) - When a string is passed to the function, the string is displayed as it is.

Ex:- Output
print(“I Love My India”) I Love My India
print(‘I Love My India’)
I Love My India
print(“Like”, “Share”, “Subscribe”)
Like share subscribe
print(‘10’)
10

print(“Welcome”)
print(“to”)
Welcome
print(“Geeky Shows”) to
Geeky Shows

 print(object) -We can pass objects like list, tuples and dictionaries to display the elements of those
objects.
Ex:-
data = [10, 20, -50, 21.3, ‘Geekyshows’]
print(data)
print(data[0])
print(data[1])
Output- [10, 20, -50, 21.3, 'Geekyshows']
10
20

 print(“string” sep=’ ‘) – It separates string with given sep character. Character can be any string.
Default is ‘ ’ or can write none.
Ex:- Output
print("Like", "Share","Subscribe", sep=' ') Like Share Subscribe

print("Like", "Share","Subscribe", sep='***') Like***Share***Subscribe

 print(variable list) –This is used to display the value of a variable or a list of variable.

Ex:- a = 10 x = 20 x = 20
print(a) y = 30 y = 30
print(x, y) print(x, y, sep=‘,’)

Output: 10 Output: 20 30 Output: 20, 30

 print(“String”, variable list) –This is used to display the string along with variable.

Ex:-

m = 40 name = “Rahul”
print(“Value: ”, m) age = 62
print(“My Name is ”, name, “and My age is”, age)

Output: Value: 40 Output: My Name is Rahul and My age is 62

Input Statements:
input() Function:This function is used to accept input from the keyboard. The input( ) function
is used in the following manner:

Syntax:
Variable_Nmae = input (<prompt to be displayed>)

Example: name = input ( “What is your name ?”)

Whatever user gives as input, input function converts it into a string. If user enters an integer
value still input() function convert it into a string.
So if you need an integer you have to use type conversion.

Comments: Comments are non-executable statements. A Comment is used to describe the feature of a
program.
There are two type of comments:-

• Single Line Comment: These comments start with a hash symbol (#).
Ex:-
# I am single Line Comment
# This is my first Python Program
# Adding two numbers

• Multi line Comment : There is no concept of multi line comment in python but we can create string
starting and ending with triple double quotes (”””) or triple single quotes (’’’) which can be used as
block of comments.

Ex:-
””” ’’’
Comment Line 1 Comment Line 1
Comment Line 2 Comment Line 2
Comment Line 3
Comment Line 3
”””
’’’
Indentation: Indentation refers to spaces that are used in the beginning of a statement. By default python
puts 4 spaces but it can be changed by programmers.

if (condition):
____Statement
____if(condition):
________statement 1
________statement 2
____if(condition):
________Statement
if(condition):
____Statement 1
____Statement 2
Rest of the code

Example Programs

Program-1: Write a program to input a welcome message and print it

Message= input("Enter welcome message: ")


print("Hello",Message)
_________________________________________________________________

Enter welcome message: Python welcomes you to its beautiful world.


Hello, Python welcomes you to its beautiful world.
Program-2: Program to obtain three numbers and print their sum

num1= int(input("Enter number 1 :"))


num2= int(input("Enter number 2: "))
num3= int(input("Enter number 3: "))
Sum= num1+num2 + num3
print("Three numbers are:", num1, num2, num3)
print("Sum is: ", Sum)
___________________________________________________

Enter number 1 :12


Enter number 2: 45
Enter number 3: 56
Three numbers are: 12 45 56
Sum is: 113

Program-3: Program to obtain length and breadth of a rectangle and calculate its area.

length = float(input("Enter length of the rectangle: "))


breadth = float(input("Enter breadth of the rectangle: "))
area = length*breadth
print("Rectangle specifications")
print("Length= ", length,)
print("breadth = ", breadth)
print("Area = " , area)
___________________________________________________

Enter length of the rectangle: 23


Enter breadth of the rectangle: 45
Rectangle specifications
Length= 23.0
breadth = 45.0
Area = 1035.0

Program-4: Write a program to read distance in miles and print in kilometres.

miles=float(input("Enter a distance in miles: "))


kilometres= 1.609*miles
print("The distance in kilometres is: ", kilometres)
___________________________________________________

Enter a distance in miles: 45


The distance in kilometres is: 72.405

Program-5: Write a program to compute "how many days is a million seconds ?"

sec=1000000
minutes = sec/60
hours= minutes/60
days = hours/24
print("One million seconds are equal to:")
print(days, "days or", hours, "hours Or", minutes, "minutes Or", sec,
"seconds")

___________________________________________________

One million seconds are equal to:


11.574074074074074 days or 277.77777777777777 hours Or 16666.666666666668
minutes Or 1000000 seconds

Program-6: Program to calculate BMI (Body Mass Index) of a person.


(Body Mass Index is a simple calculation using a person's height and weight. The formula is BMI = kg/m 2 where kg
is a person's weight in kilograms and m2 is their height in meters squared.)

weight_in_kg = float(input("Enter weight in kg :"))


height_in_meter = float(input("Enter height in meters: "))
bmi= weight_in_kg/(height_in_meter*height_in_meter)
print("BMI is", bmi)
___________________________________________________

Enter weight in kg :60


Enter height in meters: 2.5
BMI is 9.6

Program-7: Write a program to input a number and print its cube.

num=int(input("Enter a number :"))


cube= num*num*num
print("Number is: ", num)
print("Its cube is: ", cube)
___________________________________________________

Enter a number :25


Number is: 25
Its cube is: 15625

Program-8: Write a program to input a value in kilometres and convert it into miles
(1 km = 0.621371 miles)

km=int(input("Enter kilometers :"))


miles= km*0.621371
print("kilometers :", km)
print("Miles:", miles)
___________________________________________________

Enter kilometers :45


kilometers : 45
Miles: 27.961695

Program-9: Write a program to input a value in tonnes and convert it into quintals and kilograms
(1 tonne = 10 quintals, 1 tonne 1000 kg, 1 quintal = 100 kg)

tonnes=float(input("Enter tonnes :"))


quintals=tonnes*10
kgs=quintals*100
print("Tonnes:" , tonnes)
print("Quintals:" , quintals)
print("Kilograms :" , kgs)

___________________________________________________
Enter tonnes :45
Tonnes: 45.0
Quintals: 450.0
Kilograms : 45000.0

Program-10: Write a program to enter a small poem or poem verse and print it

poem=input("Enter a small poem: ")


print("The poem you entered")
print(poem)
___________________________________________________

Enter a small poem: "Hope" is the thing with feathers- That perches in the soul- And
sings the tune without the words- And never stops at all

The poem you entered


"Hope" is the thing with feathers- That perches in the soul- And sings the tune
without the words- And never stops at all

Program-11: Write a program to input two numbers and swap them

n1=int(input("Enter first number: "))


n2=int(input("Enter Second number: "))
print("original numbers: ",n1,n2)
n1,n2=n2,n1
print("After Swapping: ",n1,n2)
___________________________________________________

Enter first number: 23


Enter Second number: 56
original numbers: 23 56
After Swapping: 56 23

Program-12: Write a program to input three numbers and swap them as this 1st number becomes the 2nd
number, 2nd number becomes the 3rd number and the 3rd number becomes the 1st number

x=int(input("Enter first number: "))


y=int(input("Enter second number: "))
z=int(input("Enter third number: "))
print("Original Numbers: ",x,y,z)
x,y,z=y,z,x
print("After Swapping: ",x,y,z)
___________________________________________________

Enter first number: 23


Enter second number: 45
Enter third number: 67
Original Numbers: 23 45 67
After Swapping: 45 67 23

Program-13: Write a program that asks the user to input number of seconds and then express it in term of
many minutes and seconds it contains.
num_second=int(input("Enter number of seconds: "))
num_minutes=num_second//60
rem_seconds=num_second%60
print("Number of Minutes is: ",num_minutes)
print("Numbers of seconds is: ",rem_seconds)
___________________________________________________

Enter number of seconds: 1000


Number of Minutes is: 16
Numbers of seconds is: 40

Program-14: Write a program to obtain temperature in Celsius and convert it into Fahrenheit using formula
o
C x 9/5 + 32 =oF

C=float(input("Enter the temperature in Celsius: "))


F=C*9/5+32
print("Temperature in Celsius: ",C)
print("Temperature in Fahrenheit: ",F)
___________________________________________________

Enter the temperature in Celsius: 34


Temperature in Celsius: 34.0
Temperature in Fahrenheit: 93.2

Program-15: Write a program to calculate in how many days a work will be completed by three persons A,
Band C together. A, B, C take x days, y days and z days respectively to do the job alone. The formula to
calculate the number of days if they work together is xyz/(xy+yz+xz) days where x, y and z are given as
input to the program.

X=int(input("Enter the value of x: "))


Y=int(input("Enter the value of y: "))
Z=int(input("Enter the value of z: "))
print("Days taken by A,B,C individually respectively as: ",X,Y,Z)
days=X*Y*Z/(X*Y+Y*Z+Z*X)
print("Days taken by A,B,C together is: ",days)
___________________________________________________

Enter the value of x: 10


Enter the value of y: 15
Enter the value of z: 12
Days taken by A,B,C individually respectively as: 10 15 12
Days taken by A,B,C togather is: 4.0
Python Conditionals and Loops
If Statement: It is used to execute an Statement or block of Statement only if a condition is True.

Syntax: -
if (condition):
statement
[statements]

If there is single statement it can be written in one line.

if (condition): Statement

If - Else Statement: It is a conditional statement, which allow us to select one option out of two available
options depending upon the condition True or False.

Syntax: -

if(condition):
Statement 1
else:
Statement 2

For Examples:

if a >= 0:
print (a, "is zero or a positive number")
else:
print (a, "is a negative number")
if sales >= 10000 :
discount = sales * 0.10
else:
discount = sales * 0.05

Program-16: Write a program to input age from user and print if as per the input age, one is eligible to vote
or not

age=int(input("Enter your Age: "))


if age>=18:
print("Your age is 18 or above, You are eligible for Vote")
else:
print("Your age is below 18 , You are not eligible for Vote")
________________________________________________________

Enter your Age: 14


Your age is below 18 , You are not eligible for Vote

Enter your Age: 24


Your age is 18 or above, You are eligible for Vote

Program-17: Write a program to input two numbers and check if the two numbers are equal or not

a=int(input("Enter First Number: "))


b=int(input("Enter Second Number: "))
if(a==b):
print("Two Numbers a and b are equal")
else:
print("Two Numbers a and b are not equal")
________________________________________________________

Enter First Number: 45


Enter Second Number: 12
Two Numbers a and b are not equal

Enter First Number: 15


Enter Second Number: 15
Two Numbers a and b are equal

Program-18: Write a program to check if a given number is more than 100 or not

N=int(input("Enter any Number: "))


if N>100:
print("Number is more than 100")
else:
print("Number is not more than 100")
___________________________________________________________

Enter any Number: 25


Number is not more than 100

Enter any Number: 125


Number is more than 100
Program-19: Program that takes a number and check whether the given number is odd or Even

num=int(input("Enter any Number: "))


if num%2==0:
print("The given number is Even")
else:
print("The given number is Odd")
___________________________________________________________

Enter any Number: 23


The given number is Odd

Enter any Number: 26


The given number is Even

Program-20: Program to accept three integers and print the largest of the three. Make use of only if
statement.

a=float(input("Enter First Number: "))


b=float(input("Enter Second Number: "))
c=float(input("Enter Third Number: "))
big=a
if b>big:
big=b
if c>big:
big=c
print("Largest Number is: ",big)

___________________________________________________________

Enter First Number: 23


Enter Second Number: 45
Enter Third Number: 67
Largest Number is: 67.0

range() Function: range() function is used to generate a sequence of integers starting from 0 by default, and
increments by 1 by default, till j-1.

Syntax:-
range(start, stop, stepsize)

Start – Starting position. If we do not mention start by default it’s 0

*Stop – Ending position. The range of integers stops one element prior to stop. If stop is j then it will stop at
exact j-1
Stepsize – Increment by stepsize. If we do not mention start by default it’s 1

Syntax:- range( j ) [0, 1, 2, 3, 4,………..., j-1]


Ex:- range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Syntax:- range(i, j) [i, i+1, i+2. i+3,….., j-1]
Ex:- range(1, 10) [1, 2, 3, 4, 5, 6, 7, 8, 9]

Syntax: - range(i, j, k) [i, i+k, i+2k, i+3k, i+4k,….., j-1]


Ex:-
range(1, 10, 2) [1, 3, 5, 7, 9]
range(-1, -10, -2) [-1 -3 -5 -7 -9]
range(10, 0, -1) [10 9 8 7 6 5 4 3 2 1]

‘in’ and ‘not in’ Operators: ‘in’ and ‘not in’ Operators are used with range() function in for loops. To check
whether a value is contained inside a list you can use in operator. For example
3 in [1,2,3,4]
will return True as value 3 is contained in sequence [1, 2, 3, 4].
5 in [1,2,3,4]
will return False as value 5 is not contained in sequence [1, 2, 3, 4].

But 5 not in [1,2,3,4] will return True as this fact is true that as value 5 is not contained in sequence [1,2,3,4]
The operator not in does opposite of in operator.

The for Loop: The for loop of Python is designed to process the items of any sequence, such as a list or a
string, one by one.
The general form of for loop is as given below:

for <variable> in <sequence>:


statements_to_repeat

For example, consider the following loop:

for a in [1, 4, 7]
print(a)

The output produced by above for loop will be


1
4
7

consider another following loop:

for v in [1, 2, 3]:


print(v*v)

The above loop will produce output as:


1
4
9

Program-21: Write a program to print all items from a list containing some colour names in it.

colist=["Blue", "Green", "Yellow", "Orange", "Red", "Brown"]


for colname in colist:
print(colname)
___________________________________________________

Blue
Green
Yellow
Orange
Red
Brown
Program-22: Write a program to compute totol marks from the marks of different subjects stored in the
form of a list
marks=[45,67,89,62,75]
print("Marks are: ",marks)
total=0
for value in marks:
total=total+value
print("Total Marks = ",total)
___________________________________________________

Marks are: [45, 67, 89, 62, 75]


Total Marks = 338

Program-23: Program to print table of a number, say 5

num=5
for a in range(1,11):
print(num,'x',a,'=',num*a)
___________________________________________________

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Program-24: Program to print sum of natural numbers between 1 to 7

sum=0
for num in range(1,8):
sum=sum+num
print(sum)
___________________________________________________

1
3
6
10
15
21
28

THE while LOOP: A while loop is a conditional loop that will repeat the instructions within itself as long as a
condition remains true. The general form of Python while loop is:

while <condition>
loop-body

where the loop-body may contain a single statement or multiple statements.

For example consider the following codes:

a=5 n=1
while a>0: while (n<5):
print("Hello",a) print("squre of", n,
a=a-3 "is",n*n)
print("Loop is over!") n=n+1
print("Thank You")

The above code will print:


squre of 1 is 1
Hello 5 squre of 2 is 4
Hello 2 squre of 3 is 9
Loop is over! squre of 4 is 16
Thank You

Program-25: Write a Python Program to print squares of first 5 natural numbers.

n=1
while(n<=5):
print(n*n)
n=n+1
___________________________________________________

1
4
9
16
25

Program-26: Write a program to input a number (num) and print the sum of numbers from 1 to num.

sum=0
num=int(input("Enter any Number: "))
for i in range(1,num+1):
sum=sum+i
print("Sum of numbers from 1 to",num, "is",sum)
Enter any Number: 34
Sum of numbers from 1 to 34 is 595

Program-27: Program to calculate and print the sums of even and odd integers of the first n natural
numbers.

n=int(input("Upto which natural mumber: "))


ctr=1
sum_even=0
sum_odd=0
while(ctr<=n):
if(ctr%2==0):
sum_even=sum_odd+ctr
else:
sum_odd=sum_even+ctr
ctr=ctr+1
print("The Sum of even integer = ",sum_even)
print("The Sum of odd integers = ",sum_odd)

Upto which natural mumber: 10


The Sum of even integer = 55
The Sum of odd integers = 45

Program28: Write a program to input a number and print how many digits are there in the given number.

num=int(input("Enter any number: "))


count=0
while(num!=0):
num=num//10
count=count+1
print("Number of digits in given numbers are: ",count)

Enter any number: 12345


Number of digits in given numbers are: 5

Program 29: Write a program to input two numbers (first number n1 being less than the second number n2)
and print number of odd numbers in the range n1...n2.

n1=int(input("Enter the starting number: "))


n2=int(input("Enter the ending number: "))
num=n1
count=0
while(num<=n2):
if(num%2>0):
count=count+1
num=num+1
print("Number of odd numbers in the given range is: ",count)

Enter the starting number: 3


Enter the ending number: 15
Number of odd numbers in the given range is: 7

Program 30: Write Python code to add the odd numbers up to (and including) a given value N and print the
result.

N=int(input("Enter any value: "))


num=1
sum=0
while(num<=N):
if(num%2>0):
sum=sum+num
num=num+1
print("sum is: ",sum)

Enter any value: 5


sum is: 9

Program 31: Write a program to input a year and check if it is a leap year or not.

year=int(input("Enter a year: "))


if((year%400==0) or (year%4==0)):
print("Given year is a Leap year")
else:
print("Given year is not a Leap year")

Enter a year: 1999


Given year is not a Leap year

Enter a year: 2020


Given year is a Leap year

Program 32: Write a Program to print squares of all numbers present in a list [8, 2, 7, 11, 20, 6].

num=[8, 2, 7, 11, 20, 6]


for i in num:
sq=i*i
print("square of number:",i,"is",sq)

square of number: 8 is 64
square of number: 2 is 4
square of number: 7 is 49
square of number: 11 is 121
square of number: 20 is 400
square of number: 6 is 36

Program 33: Write a program to print the numbers divisible by 5 from a given list of numbers [11, 25, 35, 26,
50, 61]

num=[11, 25, 35, 26, 50, 61]


for i in num:
if(i%5==0):
print(i)
25
35
50

Program 34: Write a program to input a number and print the sum of digits in the given number.

num=int(input("Enter any number(>=100): "))


sum=0
while(num !=0):
dig=(num%10)
sum=sum+dig
num=num//10
print("Sum of the digits= ",sum)

Enter any number(>=100): 567


Sum of the digits= 18

Program 35: Write a program to input a number and print its reversed number

Orig_num=int(input("Enter any number(>=1000): "))


num=Orig_num
rev=0
while(num!=0):
dig=num%10
rev=(rev*10+dig)
num=num//10
print("Original Number= ",Orig_num)
print("Reverse Number=",rev)

Enter any number(>=1000): 6754


Original Number= 6754
Reverse Number= 4576

Program-36:Write a program to print if a number is a palindrome number. A palindrome number is the one
which is same as its reverse number.

Orig_num=int(input("Enter any number(>=1000): "))


num=Orig_num
rev=0
while(num!=0):
dig=num%10
rev=(rev*10+dig)
num=num//10
if(rev==Orig_num):
print("The given number is a palindrome number")
else:
print("The given number is a not a palindrome number")

Enter any number(>=1000): 12321


The given number is a palindrome number

Program-37: Write a program to input a 3 digit number and check if it is an Armstrong number. An Armstrong
number is the one which is equal to the sum of the cubes of its digits, eg. 153=1 3+53+33.

num=int(input("Enter any number(>=1000): "))


temp=num
sum=0
while(temp!=0):
dig=temp%10
sum=(sum+dig**3)
temp=temp//10
if(sum==num):
print("Given number is Armstrong number")
else:
print("Given number is not Armstrong number")
Enter any number(>=1000): 153
Given number is Armstrong number

Program-38: Write a program to input a positive number and print its factorial . The factorial of a number n is:
n*(n-1)*(n-2)*……..*1

N=int(input("Enter any positive number: "))


fact=1
for i in range(1,N+1):
fact=fact*i
print("Factoreal of number",N,"is:",fact)

Enter any positive number: 5


Factoreal of number 5 is: 120
Class – X

ARTIFICIAL
INTELLIGENCE

Unit 4
(Data Science)
Introduction to Data Science: Data science is a field that uses scientific methods, processes, algorithms
and systems to extract knowledge and insights from many structural and unstructured data.
Data science is related to data mining, machine learning and big data.
Data Mining: Data Mining is a process of finding potentially useful patterns from huge data sets.
Machine Learning (ML): Machine Learning is a process of automatic learning of computers and
machines by dis- covering insights from data with experience.
Big Data: Big Data refers to huge amounts of data, which is regularly growing at an exponential rate,
e.g., data of social media (posts, pictures, responses, users, etc.).

Applications of Data Sciences: There exist various applications of Data Science in today’s world. Some of
them are:

1. In Search Engines: The most useful application of Data Science is Search Engines. As we know when we
want to search for something on the internet, we mostly use Search engines like Google, Yahoo, Safari, Firefox,
etc. So Data Science is used to get Searches faster.

2. In Finance: Financial Industries always have an issue of fraud and risk of losses. Thus, Financial Industries
needs to automate risk of loss analysis in order to carry out strategic decisions for the company. Also, Financial
Industries uses Data Science Analytics tools in order to predict the future. It allows the companies to predict
customer lifetime value and their stock market moves.

3. In E-Commerce: E-Commerce Websites like Amazon, Flipkart, etc. uses data Science to make a better user
experience with personalized recommendations.

4. Targeting Advertising: Targeting advertising is a type of online advertising. For target advertising, the
data science works with data based on browsing habits, past purchases, or any other recent activities.

5. In Health Care: In the Healthcare Industry data science is used for:


 Drug discoveriey and Development.
 Diagnosis with Medical Image Analysis.
 Genetics and Genomics Reseaech.

6. Airline Routing Planning: With the help of Data Science, Airline Sector is also growing like with the help
of it, it becomes easy to predict flight delays. It also helps to decide whether to directly land into the destination
or take a halt in between.

7. Autocomplete: Autocomplete feature is used where he/she is an efficient choice to auto-complete the
whole line. Also in Search Engines in social media, in various apps, AutoComplete feature is widely used.

Data Collection: Data collection is a method of gathering numeric and alphanumeric data. For data analysis,
you need to perform data collection. The AI predictions and suggestions by the machine are possible through data
collection. The data collection is mainly used for record maintenance and other purposes.
The commonly used datasets are:
Banks It holds data for loans, accounts, lockers, payrolls, bank visitors etc.
ATM Machines It holds data related to daily transactions, visitors information, money is withdrawn etc.
Movie Theaters It holds details on movie details, tickets sold online and offline modes, purchase of refreshments etc.
School School data like students fee collection, results, teachers; salary database etc.

Sources of Data: There exist various sources of data from where we can collect any type of data required and
the data collection process can be categorised in two ways: Offline and Online.

Offline Data Collection Online Data Collection


Sensors Open-sourced Government Portals

Surveys Reliable Websites (Kaggle)

Interviews
World Organisations’ open-sourced statistical
websites
Observations

While accessing data from any of the data sources, following points should be kept in mind:

1. Data which is available for public usage only should be taken up.
2. Personal datasets should only be used with the consent of the owner.
3. One should never breach someone’s privacy to collect data.
4. Data should only be taken form reliable sources as the data collected from random sources can be wrong or
unusable.
5. Reliable sources of data ensure the authenticity of data which helps in proper training of the AI model.

Types of data: For data science models or projects, generally, data is collected in the form of tables in different
formats:
1. CSV: It is a common and simple file format to store data in tabular form. It can be opened through any
spreadsheet software (MS Excel), documentation software (MS Word )and any text editor.

2. Spreadsheet: A spreadsheet contains rows and columns to represent data in tabular form. Mostly spreadsheet
is used to calculate data, manipulate data, analyse data and maintain data records. Ms excel is well known and
popular spreadsheet software.

3. SQL: It stands for Structured Query Language. It is used to handle the data stored in DBMS (Database
Management Software) System. It provides basic commands to create, alter, delete and manage transactions for
database management.

Data Access : After collecting the data, to be able to use it for programming purposes, we should know how to
access the same in a Python code. To make our lives easier, there exist various Python packages which help us in
accessing structured data (in tabular form) inside the code.

Let us take a look at some of these packages:

NumPy: NumPy, which stands for Numerical Python, is the fundamental package for Mathematical and logical
operations on arrays in Python. It is a commonly used package when it comes to working around numbers. NumPy
gives a wide range of arithmetic operations around numbers giving us an easier approach in working with them.
NumPy also works with arrays, which is nothing but a homogenous collection of Data.
Pandas: Pandas is a software library written for the Python programming language for data manipulation and
analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series.

Pandas is well suited for many different kinds of data:

• Tabular data with heterogeneously-typed columns, as in an SQL table or Excel spreadsheet


• Ordered and unordered (not necessarily fixed-frequency) time series data.
• Arbitrary matrix data (homogeneously typed or heterogeneous) with row and column labels
• Any other form of observational / statistical data sets.

Matplotlib: Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-
platform data visualization library built on NumPy arrays. Matplotlib comes with a wide variety of plots. Plots
helps to understand trends, patterns, and to make correlations. They’re typically instruments for reasoning
about quantitative information. Some types of graphs that we can make with this package are listed below:

Not just plotting, but you can also modify your plots the way you wish. You can stylise them and make them
more descriptive and communicable.

Class – X
ARTIFICIAL
INTELLIGENCE

Unit 5
(Computer Vision)

Computer Vision (CV): Computer Vision (CV) is a subset of artificial intelligence that makes computers,
machines and devices visually enabled by giving them capability to analyse and understand the image
captured by camera.

Applications of Computer Vision:


1. Facial Recognition System: A Facial Recognition System is a computer vision based technology that
identifies or verifies or matches a digital image (live or stored) of a human face against a database of
stored face images.

2. Face Filters: The modern-day apps like Instagram and snapchat have a lot of features based on the usage of
computer vision. The application of face filters is one among them. Through the camera the machine or the
algorithm is able to identify the facial dynamics of the person and applies the facial filter selected.

3. Google’s Search by Image: Google’s search engine has an interesting feature of getting search
results through an image. This uses Computer Vision as it compares different features of the input image to the
database of images and give us the search result while at the same time analysing various features of the image.

4. Self-Driving Cars: In Self-Driving Cars, Computer Vision is one of the most important technology used
along with a good quality fast camera and automatic route navigation. The self-driving cars or the driver-less
cars or the hands-free cars are possible today only because of Computer Vision along with other Al technologies.

5. Goggle lens: To search data, Google uses Computer Vision for capturing and analyzing different features of
the input image to the database of images and then gives us the search.

6. Medical Imaging: For the last decades, computer vision medical imaging application has been a
trustworthy help for physicians and doctors. It creates and analyzes images and helps doctors with their
interpretation.
The application is used to read and convert 2D scan images into interactive 3D models. that enable medical
professionals to gain a detailed understanding of a patient’s health condition.

Computer Vision Tasks: The Application of the computer is performed by certain tasks on the data or input
provided by the user so it can process and analyze the situation and predict the outcome. The tasks used in a computer
vision application are :

1. Image Classification: Image Classification refers to the act of identifying and classifying a given image
as belonging to one of a set of predefined categories or classes.

2. Classification + Localisation: This is the task which involves both processes of identifying what
object is present in the image and at the same time identifying at what location that object is present in that
image.
3. Object Detection: Object Detection refers to a combined action of localisation and classification, carried
out on different items/things/subjects of interest in an image/video to identify and label them as objects of
specific types and know their count.

4. Instance Segmentation: This task refers to dividing of an image into its sub- components so that
objects can be separated from its background and other objects. In other words, an image is separated in
different segments in this task. A segment is identified using a pixel mask which is actually a 2-d area whose
every pixel is extracted out and this is called image segment

Basics of Images: Various terms related to the digital images used with CV are:

1.Pixel: The small dots that create an image are called pixels. A pixel represents the smallest piece of the screen
that can be controlled individually in terms of colour and intensity. Each pixel can be set to a different colour and
intensity. An image created with pixels is known as a bitmap graphic.

2. Pixel Colour and Intensity: Each pixel of the screen image is displayed on a monitor using a
combination of three different colour signals: Red, Green and Blue (RGB). Each pixel's appearance is controlled by
the intensity of these three beams of light. Intensity of the RGB colours is stored as a value (generally 0-255) for
each of the three colours. When all are set to the highest level the result is white (ie., R:255, G:255, B:255); when
all are set to zero the result is black (ie, R:O, G:0, B:0), other combinations of RGB values create other colours.
3. Resolution: Image Resolution refers to the quality and size of an image. In simple words, the number of
pixels in an image determine its resolution. Image resolution measures the dimension of an overall image or how
big the size of an image is. Image resolution is measured in width (vertical pixels) and height (horizontal pixels).
For example, 100*100-pixel image has a total of 10,000 pixels.

4.Colour Depth/Pixel Value: The amount of information that is stored about a pixel determine pixel
value, which controls how precisely the pixel's colour can be specified. This is also sometimes called the bit depth,
because the precision of colour depth is specified in bits. The more bits that are used per pixel, the finer the
colour detail of the image is.

The 24 bit colour depth is said to be True Colour image. True colour name means it gives a very realistic
representation of the colour of images.

5. Grayscale Images: If the pixels of an image only use a number between 0-255 to represent colours-
black, white and grey, where 0/255 represent black/white and the numbers 1-254 represent different shades of
grey colour, then such an image is known as a grayscale image. In other words, the colour information is removed
and only the intensity value is stored in pixel (0 dark black: 255-bright white).

6. RGB Images (coloured Images): An RGB image is a coloured image that is formed by the three-
colour information (Red, Green, Blue ) stored for each pixel of a digital image. So, in an RGB image, internally
three image channels/layers are stored, one each for Red channel, Green channel and Blue channel. The image
channels store the colour value for each pixel. The combination of these three image channels results into full
colour image.
Class – X

ARTIFICIAL
INTELLIGENCE
Unit 6
(Natural Language Processing)

Natural Language Processing: Natural Language Processing (NLP) is a branch of artificial intelligence that
enables computers to process human language in the form of text or voice data, 'understand' its full meaning
and mimic human conversation.

Application of NLP: Some common NLP applications are:

1. AutoText Summaritation: Automatic Text Summarisation is an NLP technique where a computer


program shortens longer texts and generates summaries to pass the intended message as the most
important information is retained.

2. Sentiment Analysis: Sentiment Analysis refers to the use of linguistic analysis using Al to detect
emotional and language tones in written text or speech to text.

3. Text Classification: Text Classification is the process of understanding, analysing and categorising
unstructured text into organised groups using NLP and other AI technologies based on predetermined
tags and categories.
4. Virtual Assistants: Virtual Assistants are NLP based programs that are auto- mated to communicate in
human voice, mimicking human interaction to help ease your day-to-day tasks, such as showing
weather reports, creating remainders, making shopping lists etc. for example, Siri, Cortana, Alexa,
Google Assistant.

7. Chatbots: Chatbots are essentially a software applications that use Al and NLP to assist humans and
communicate through text or voice.

Depending on how they are programmed, they can be categorized as:


i. Script Chatbots: They work on pre-written keywords that they understand. Each of the
commands that they are going to follow must be coded into them by the developer. So,
if a user asks them something outside of their knowledge base, they respond with
"sorry, I did not understand", or something along those lines.

ii. Smart Chatbots: Smart chatbots are based on Al, these bots don't have pre-
programmed answers. They learn with time, catching keywords and putting them in
context, and help users arrive at the most relevant answers to their queries.

Script Chatboat vs Smart Chatboat:

S.No. Script Chatboat Smart Chatboat


1 These are task specific chatbots These are flexible and versatile chatbots
Script bots work around a script which Smart bots work on bigger databases and
2
is programmed in them other resources directly
These require simple or very less These require advanced AI based
3
programming programming
4 These have limited functionality These are flexible and adaptive

Human Language VS Computer Language:


Humans communicate through language which we process all the time. As a person speaks, the
sound travels and enters the listener's eardrum. This sound then converted into neuron impulse and
transported to the brain for processing. After processing, the brain gains understanding around the meaning
of sound.

The computer understands the language of numbers. Everything that is sent to the machine has to
be converted to numbers. And while typing, if a single mistake is made, the computer throws an error and
does not process that part. The communications made by the machines are very basic and simple.

Difficulties faced by machine to understand human language:

1. Arrangement of the words and meaning: There are rules in human language which provide structure to a
language. There are nouns, verbs, adverbs, adjectives. A word can be a noun at one time and an adjective
some other time.

2. Multiple meanings of a word: In natural language, a word can have multiple meanings and the meanings fit
into the statement according to the context of it.

3. Perfect Syntax, no Meaning: Sometimes, a statement can have a perfectly correct syntax but it does not
mean anything. For example, take a look at this statement:

Chickens feed extravagantly while the moon drinks tea.

This statement is correct grammatically but does not make any sense.

How NLP makes it possible for the machines to understand and speak just like humans?:
We all know that the language of computers Is Numerical, so the very first step that comes to
our mind is to convert our language to numbers. This conversion happens in various steps which are
given below.

1. Text Normalisation: In Text Normalisation, we undergo several steps to normalise the text to a lower
level. Text Normalisation helps in cleaning up the textual data in such a way that it comes down to a level
where its complexity is lower than the actual data. Steps of Text Normalisation are:

a) Sentence Segmentation: Sentence Segmentation is the process of dividing the whole text into smaller
components, i.e., individual sentences. This is done to understand the thought or idea of each
individual sentence. For example:

Hello world. AI is fun to know.  Hello world.


It has starting impacting our  AI is fun to know.
lives in many ways. Many  It has starting impacting our lives in
more revolutionary many ways.
technologies will soon  Many more revolutionary technologies
evolve out of it. will soon evolve out of it.

b) Tokenisation: After segmenting the sentences, each sentence is then further divided into tokens.
Tokens is a term used for any word or number or special character occurring in a sentence. Under
tokenisation, every word, number and special character is considered separately and each of them is
now a separate token. For example:

c) Removing Stopwords, Special Characters and Numbers: The function of this step is to find
unimportant words as per the overall meaning and retain the important words in the text. For
example, consider the following two sentences which are conveying the same meaning to the
computer.

‘Delhi is the capital and the most populous city.’

‘Delhi capital most populous city’

This step, along with removing the stop words, also removes the redundant special characters and
numbers, which are not contributing to the overall meaning.

d) Converting text to a common case : After the stopwords removal, we convert the whole text into a
similar case, preferably lower case. This is done to ensure that if any machine is case sensitive, it should
not affect the overall result by considering two same words in different cases as different words.

e) Stemming : In this step, the remaining words are reduced to their root words. In other words,
stemming is the process in which the affixes of words are removed and the words are converted to
their base form. Note that in stemming, the stemmed words might not be meaningful.
f) Lemmatization: Stemming and lemmatization both are alternative processes to each other as the role
of both the processes is same – removal of affixes. But the difference between both of them is that in
lemmatization, the word we get after affix removal (also known as lemma) is a meaningful one.

2. Bag of Words : Bag of Words is a Natural Language Processing model which helps in extracting features
out of the text which can be helpful in machine learning algorithms. In bag of words, we get the occurrences of each
word and construct the vocabulary for the text.

A bag of words gives us two things:


1. A vocabulary of words for the corpus
2. The frequency of these words (number of times it has occurred in the whole corpus).
It is called a "bag" of words, because it contains just the collection of words without any information about the order or
structure of words in the document.

Steps to Implement Bag-of-Words Model:

Step 1: Text Normalisation: In the first step, the data is to be collected and then pre-processed. For example, we have
the following text available:

“Aman and Anil are stressed.


Aman went to a therapist.
Anil went to download a health chatbot.”
After text normalisation, the text becomes:

Document 1: [aman, and, anil, are, stressed]


Document 2: [aman, went, to, a, therapist]
Document 3: [anil, went, to, download, a, health, chatbot]

Step 2: Create Dictionary: Now we can make a list of all of the words in our model vocabulary with the unique words
left after pre-processing of all the documents. So, the unique words in our Dictionary for the text will be:

Step 3: Create document vector: In this step, the vocabulary is written in the top row. Now, for each word in the
document, if it matches with the vocabulary, put a 1 under it. If the same word appears again, increment the previous
value by 1. And if the word does not occur in that document, put a 0 under it.

Since in the first document, we have words: aman, and, anil, are, stressed. So, all these words get a value of 1 and rest of
the words get a 0 value.

Step 4: Repeat for all documents: Same exercise has to be done for all the documents. Hence, the table becomes:

In this table, the header row contains the vocabulary of the corpus and three rows correspond to three
different documents.
Finally, this gives us the document vector table for our corpus. But the tokens have still not converted to
numbers. This leads us to the final steps of our algorithm: TFIDF.

3. TFIDF: Term Frequency & Inverse Document Frequency: TFIDF stands for Term Frequency and
Inverse Document Frequency. TFIDF helps un in identifying the value for each word. Let us understand each term one by
one.

Term Frequency: Term frequency is the frequency of a word in one document. Term frequency can easily be found
from the document vector table as in that table we mention the frequency of each word of the vocabulary in each
document.
Inverse Document Frequency: To understand Inverse Document Frequency, let us first understand what does
document frequency mean. Document Frequency is the number of documents in which the word occurs irrespective of
how many times it has occurred in those documents. The document frequency for the exemplar vocabulary would be:

In inverse document frequency, we need to put the document frequency in the denominator while the total number of
documents is the numerator. Here, the total number of documents are 3, hence inverse document frequency becomes:

Finally, the formula of TFIDF for any word W becomes:

TFIDF(W) = TF(W) * log( IDF(W) )

Class – X

ARTIFICIAL
INTELLIGENCE

Unit-7
(Evaluation)
What is evaluation? : Evaluation is the process of understanding the reliability of any AI model, based on outputs
by feeding test dataset into the model and comparing with actual answers.
Evolution checks and access an AI model for these:

1. If an AI model is producing result because of its learning or memorization


2. If an AI model is operating correctly and optimily

Causes Behind Performance of Al Model: The causes behind the performance of an Al model are:

Overfitting: Overfitting means the Al model performs so well against only known data, i.e., the training data or the
data very much similar to it. However, the AI model fails to fit the unknown data, i.e., cannot predict the reliable results
for unknown data.

Underfitting: Underfitting refers to a situation when an AI model is not complex enough to capture the structure and
relationships of its training data and predict effective outcomes.

Confusion Matrix: A Confusion Matrix is a technique using a chart or table for summarising the performance of a
classification based AI model by listing the predicted values of an AI model and the actual/correct outcome values. in a
confusion table.

 The Actual Value (True/False) represents the actual result of the AI model (observed or measured).

 The Predicted Value (Positive/Negative) is the value of the outcome/result of the AI model, produced on
the basis of its algorithm and learning

Commonly used terms with confusion matrix are:


1. True Positive (TP): True Positive refers to an instance for which both predicted value of the AI model and
actual value are positive.
2. True Negative (TN): True Negative refers to an instance for which both predicted value of the AI model and
actual value are negative.
3. False Positive (FP) (also called Type I Error): False Positive refers to an instance for which predicted value of
an Al model is positive but actual value is negative.
4. False Negative (FN) (also called Type II Error): False Negative refers to an instance for which predicted value
of an AI model is negative but actual value is positive.

Using these values, we create a confusion matric for our AI model in the following format:

Using the Confusion matrices, we need to compute the following values to evaluate an AI model:

1. Accuracy rate: Accuracy of an AI model is defined as the percentage of correct predictions (i.e TP+TN) out of all the
observations (i.e TP+FP+TN+FN). A prediction can be said to be correct if it matches the reality.
The formula to determine Accuracy is:

2. Precision rate: Precision is defined as the percentage of true positive cases out of all the cases where the prediction
is true.

The formula to determine Precision is:

3. Recall: Recall is defined as the percentage of true positive cases out of all the cases where the actual value is true is
true.
4 . F1 Score: F1 Score refers to a metric that balances Precision and Recall and hence balances the impact of False
Positives and False Negatives.
It is computed as per the following formula:

TP
= TP+ 1 ∗( FP+ FN )
2

You might also like