Question Bank With Answers
Question Bank With Answers
1. Write down any 3 examples of machine learning and deep learning algorithms
Machine Learning Algorithms
a) Linear Regression
b) Decision Trees
c) Support Vector Machines (SVM)
Deep Learning Algorithms
a)Convolutional Neural Networks (CNNs)
b)Recurrent Neural Networks (RNNs)
c)Generative Adversarial Networks (GANs)
1
6. Define Artificial Intelligence. Discuss its key components and how they interact
with each other.
Answer: Artificial Intelligence (AI) refers to the simulation of human intelligence in
machines programmed to think and learn. Key components include:
Machine Learning: Algorithms that enable systems to learn from data.
Natural Language Processing (NLP): Allows machines to understand and interpret
human language.
Robotics: The design of robots that can perform tasks autonomously.
Computer Vision: Enabling machines to interpret and process visual information. These
components interact to create intelligent systems that can learn, reason, and act
autonomously.
2
Handling missing values: Imputation or removal of incomplete data.
Encoding categorical variables: Converting categorical data into numerical form.
10. Explain the concept of neural networks. How do they mimic the human brain’s
structure and function?
Neural networks are a fundamental concept in machine learning, inspired by the
structure and functioning of the human brain. They are designed to recognize patterns
and make decisions based on data, similar to how the human brain processes information.
Structure of Neural Networks
A neural network consists of layers of interconnected neurons (also called nodes). These
layers include:
Input Layer: This is where the network receives the raw data (features) as input.
Hidden Layers: These layers process the input data by transforming it through
various operations and abstractions.
Output Layer: This produces the final result or prediction, such as classifying an
image or predicting a value.
Each neuron in a layer is connected to neurons in the next layer, and each connection has
an associated weight that determines the strength of the connection.
Components of a Neuron
Each neuron performs the following functions, analogous to biological neurons:
Weights: The connections between neurons have weights, which control the influence of
one neuron on another. These are like the synapses in the brain, adjusting based on
experience.
Activation Function: After the weighted sum of inputs reaches a neuron, it passes
through an activation function (such as sigmoid, ReLU, or tanh), which determines
whether the neuron "fires" or becomes active.
Bias: Each neuron has a bias value that shifts the weighted sum, influencing the neuron’s
activation.
How Neural Networks Learn
Neural networks learn by adjusting the weights and biases during training, a process that
mimics how the brain strengthens or weakens synaptic connections in response to
experiences. This adjustment is done using algorithms like backpropagation and gradient
descent:
Backpropagation: The algorithm calculates the error by comparing the network’s output
to the desired output. The error is then propagated backward through the network to
adjust the weights in such a way that future predictions will be more accurate.
3
Gradient Descent: This optimization algorithm adjusts the weights by minimizing a loss
function (which measures how far the network’s output is from the desired output).
Mimicking the Human Brain
The structure and function of artificial neural networks (ANNs) are inspired by biological
neural networks. Let’s look at how they are analogous to the human brain:
1. Neurons
Biological neurons: In the brain, neurons process and transmit information. They
receive signals from other neurons, process these signals, and pass them on.
Artificial neurons: In ANNs, each node performs a similar function by taking inputs,
processing them through weights, applying an activation function, and passing the output
to the next layer.
2. Synapses and Weights
Synapses: In the brain, neurons are connected through synapses, which determine the
strength of the signal passed from one neuron to the next. Synapses strengthen with
repeated activity, which is akin to learning.
Weights: In ANNs, the connections between nodes are represented by weights. These
weights are learned and adjusted during training to influence how much input from one
neuron affects the output of another.
3. Learning through Experience
Brain learning: The brain learns by adjusting synaptic strengths through experiences
(like learning to ride a bike or recognizing faces). This process is known as synaptic
plasticity.
Neural network learning: ANNs adjust weights based on feedback (error signals), which
is analogous to the brain strengthening or weakening synaptic connections through
feedback (e.g., rewards, punishments).
4. Parallel Processing
Brain: The human brain processes information in parallel across millions of neurons,
allowing it to handle complex tasks like vision, language, and decision-making
simultaneously.
Neural networks: ANNs also perform parallel processing, with neurons in the hidden
layers processing multiple pieces of data at the same time. This allows them to handle
large amounts of data efficiently.
5. Hierarchical Processing
Brain: The brain processes information hierarchically, starting with simpler patterns (like
edges in vision) and gradually building up to complex patterns (like recognizing a face).
4
Neural networks: In deep learning, the multiple hidden layers of a neural network
progressively extract higher-level features from raw input data. Early layers might detect
basic patterns (e.g., edges in an image), while later layers identify more complex
structures (e.g., shapes, objects).
Example: Image Recognition
To illustrate, consider how neural networks are used in image recognition:
Input Layer: The network receives pixel values of the image.
Hidden Layers: Early layers identify edges or simple patterns in the image. Subsequent
layers recognize more complex shapes (e.g., parts of objects like eyes, ears, etc.).
Output Layer: The network combines the features to classify the image (e.g., identifying
it as a "cat").
This process is similar to how the visual cortex in the brain processes visual stimuli,
detecting simple patterns first, then gradually recognizing complex objects.
11. What are the ethical considerations in the development and deployment of AI
systems?
Answer: Ethical considerations include:
Bias in algorithms leading to unfair treatment.
Privacy concerns with data collection and usage.
Accountability for decisions made by AI systems. Potential societal impacts include job
displacement and the need for regulation to ensure responsible use.
12. Define the term "Natural Language Processing" (NLP). What are its main
challenges?
Answer: NLP is a field of AI focused on the interaction between computers and human
language. Main challenges include:
Ambiguity in language (context-dependent meanings).
Understanding nuances, idioms, and cultural references.
Sentiment analysis in varying tones and contexts.
13. Illustrustrate and solve an example problem using Reinforcement learning
techniques
The objective is to balance a pole on a moving cart. The cart can move left or right,
and the pole starts upright. The goal is to keep the pole balanced as long as possible.
Reference Link : https://www.youtube.com/watch?v=JNKvJEzuNsc
5
Environment:
• State Space: The state consists of four variables:
o Cart position
o Cart velocity
o Pole angle
o Pole angular velocity
15. What is deep learning, and how does it differ from traditional machine
learning?
Answer:
Deep Learning is a subfield of machine learning that uses artificial neural networks
with many layers (hence "deep") to model complex patterns in data. Traditional
machine learning models often require feature engineering, where a human selects
the relevant features. Deep learning models, however, automatically learn features
from raw data, which makes them especially effective for tasks such as image
recognition, speech processing, and natural language understanding.
6
16. Discuss how you would use reinforcement learning to train an agent in a
simulated environment. What metrics would you use to evaluate its
performance?
7
• Continue this process until the agent reaches a terminal state or predefined
criteria.
• The process repeats across many episodes to help the agent refine its policy
and converge to an optimal strategy.
17. Describe about various steps involved in implanting a machine learning model
Answer:
1. Problem Definition
The first step is to define the problem you're trying to solve, whether it’s
classification, regression, clustering, etc.
2. Data Collection
Gather relevant data that will be used to train the model. The data can be from
different sources such as databases, APIs, or CSV files.
3. Data Preprocessing
Clean the data to remove noise, handle missing values, and transform it into a
format suitable for model training. This often includes:
8
Once the model has been tuned and validated, deploy it into a production
environment where it can be used to make predictions on new data.
10. Monitoring and Maintenance
After deployment, monitor the model's performance over time and update it if
necessary as new data becomes available or conditions change.
9
5. Sentiment Analysis: Understanding the sentiment of a piece of text, which is
especially useful for analysing customer feedback, social media posts, and reviews
(e.g., analysing product reviews to gauge user satisfaction).
Problematic Questions
21. Write a program to perform the following arithmetic operations. Input
different values using keyboard Addition, Subtraction, Multiplication, Division
Answer :
10
if num < 0:
print("Factorial is not defined for negative numbers.")
else:
result = factorial(num)
print("The factorial is “, result")
23. Write a program to check whether the given number is Armstrong or not
# Display Results
print("Matrix 1:\n", matrix1)
print("Matrix 2:\n", matrix2)
print("\nMatrix Addition:\n", addition)
print("Matrix Subtraction:\n", subtraction)
print("Element-wise Multiplication:\n", elementwise_multiplication)
print("Dot Product (Matrix Multiplication):\n", dot_product)
print("Transpose of Matrix 1:\n", transpose_matrix1)
12
print("Transpose of Matrix 2:\n", transpose_matrix2)
27. Demonstrate with a python program to plot the following types of graph using
the given data.
# Sample Data
data = [23, 45, 56, 78, 213, 43, 21, 98, 120, 67, 45, 35, 78, 56, 90]
plt.figure(figsize=(8, 5))
plt.bar(categories, values, color='skyblue')
plt.title("Bar Chart Example")
plt.xlabel("Categories")
plt.ylabel("Values")
plt.show()
# Plotting Histogram
def plot_histogram():
plt.figure(figsize=(8, 5))
plt.hist(data, bins=7, color='green', alpha=0.7)
plt.title("Histogram Example")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
# Plotting Boxplot
def plot_boxplot():
plt.figure(figsize=(8, 5))
sns.boxplot(data=data, color='lightblue')
plt.title("Boxplot Example")
plt.show()
13
def plot_pie_chart():
labels = ['Apple', 'Banana', 'Orange', 'Grapes']
sizes = [25, 35, 20, 20]
colors = ['gold', 'lightcoral', 'lightskyblue', 'lightgreen']
plt.figure(figsize=(8, 5))
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%',
startangle=140)
plt.title("Pie Chart Example")
plt.axis('equal') # Equal aspect ratio ensures that pie chart is drawn as
#a circle.
plt.show()
14
28. Write sample python programs to differentiate between Python lists and
NumPy arrays
Key Differences:
Addition:
Python List: When adding two lists, they are concatenated.
NumPy Array: Supports element-wise addition between two arrays of the same size.
Scalar Multiplication:
Python List: Repeats the elements when multiplied by a scalar.
NumPy Array: Multiplies each element by the scalar.
Mathematical Operations:
Python List: Requires a loop or list comprehension to perform operations like
squaring elements.
NumPy Array: Supports vectorized operations (like squaring elements) without
loops, which is faster and more efficient.
import numpy as np
# 1. Addition
print("Addition:")
print("Python List:", py_list + [10, 20]) # List concatenation
print("NumPy Array:", np_array + np.array([10, 20, 30, 40, 50])) # Element-wise
addition
# 2. Scalar Multiplication
print("\nScalar Multiplication:")
print("Python List:", py_list * 2) # Repeats the list elements
print("NumPy Array:", np_array * 2) # Multiplies each element by 2
Dataset source : -
https://gist.github.com/curran/a08a1080b88344b0c8a7
17
https://www.kaggle.com/datasets/uciml/iris
# Load dataset
iris = load_iris()
X = iris.data
y = iris.target
imread() function − This is the function for reading an image. OpenCV imread()
supports various image formats like PNG, JPEG, JPG, TIFF, etc.
imshow() function − This is the function for showing an image in a window. The
window automatically fits to the image size. OpenCV imshow() supports various
image formats like PNG, JPEG, JPG, TIFF, etc.
imwrite() function − This is the function for writing an image. OpenCV imwrite()
supports various image formats like PNG, JPEG, JPG, TIFF, etc.
import cv2
Now, for reading a particular image, use the imread() function –
For showing the image, use the imshow() function. The name of the window in
which you can see the image would be image_flower.
cv2.imshow('image_flower',image)
cv2.destroyAllwindows()
19
Color Space Conversion
In OpenCV, the images are not stored by using the conventional RGB color, rather they are
stored in the reverse order i.e. in the BGR order. Hence the default color code while reading
an image is BGR. The cvtColor() color conversion function in for converting the image from
one color code to other.
import cv2
image = cv2.imread('image_flower.jpg')
cv2.imshow('BGR_Penguins',image)
image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('gray_penguins',image)
Edge Detection
Humans, after seeing a rough sketch, can easily recognize many object types and their poses.
That is why edges play an important role in the life of humans as well as in the applications
of computer vision. OpenCV provides very simple and useful function called Canny()for
detecting the edges.
import cv2
import numpy as np
image = cv2.imread('Penguins.jpg')
cv2.imwrite(‘edges_Penguins.jpg’,cv2.Canny(image,200,300))
cv2.imshow(‘edges’, cv2.imread(‘‘edges_Penguins.jpg’))
20
Face Detection
Face detection is one of the fascinating applications of computer vision which makes it more
realistic as well as futuristic. OpenCV has a built-in facility to perform face detection. We are
going to use the Haar cascade classifier for face detection.
import cv2
import numpy as np
face_detection= cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml')
img = cv2.imread('AB.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_detection.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w, y+h),(255,0,0),3)
cv2.imwrite('Face_AB.jpg',img)
21