ch-1 2
ch-1 2
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.
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.
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.
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:
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)
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”.
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
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.
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
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. 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.
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. `
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.
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.
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
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:
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 :
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.
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.
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.
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,
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}
(i) Strings:String represents group of characters. Strings are enclosed in double quotes or single
quotes.
(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 ( ).
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
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:
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)
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……….)
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(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=‘,’)
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)
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>)
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-3: Program to obtain length and breadth of a rectangle and calculate its area.
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")
___________________________________________________
Program-8: Write a program to input a value in kilometres and convert it into miles
(1 km = 0.621371 miles)
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)
___________________________________________________
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
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
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
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)
___________________________________________________
Program-14: Write a program to obtain temperature in Celsius and convert it into Fahrenheit using formula
o
C x 9/5 + 32 =oF
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.
Syntax: -
if (condition):
statement
[statements]
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
Program-17: Write a program to input two numbers and check if the two numbers are equal or not
Program-18: Write a program to check if a given number is more than 100 or not
Program-20: Program to accept three integers and print the largest of the three. Make use of only if
statement.
___________________________________________________________
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)
*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
‘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 a in [1, 4, 7]
print(a)
Program-21: Write a program to print all items from a list containing some colour names in it.
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)
___________________________________________________
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
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
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")
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.
Program28: Write a program to input a number and print how many digits are there in the given number.
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.
Program 30: Write Python code to add the odd numbers up to (and including) a given value N and print the
result.
Program 31: Write a program to input a year and check if it is a leap year or not.
Program 32: Write a Program to print squares of all numbers present in a list [8, 2, 7, 11, 20, 6].
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]
Program 34: Write a program to input a number and print the sum of digits in the given number.
Program 35: Write a program to input a number and print its reversed number
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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:
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:
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.
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.
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:
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:
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:
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
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.
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