Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

CS3491 AIML Lab Final

The document outlines the curriculum for the CS3491 Artificial Intelligence and Machine Learning course at JCT College of Engineering and Technology, detailing the course objectives, outcomes, and practical exercises. It emphasizes the importance of both theoretical knowledge and practical skills in areas such as search algorithms, machine learning models, and deep learning. Additionally, it includes instructions for students regarding lab conduct and a syllabus with specific programming tasks related to AI and ML techniques.

Uploaded by

befarin2022
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

CS3491 AIML Lab Final

The document outlines the curriculum for the CS3491 Artificial Intelligence and Machine Learning course at JCT College of Engineering and Technology, detailing the course objectives, outcomes, and practical exercises. It emphasizes the importance of both theoretical knowledge and practical skills in areas such as search algorithms, machine learning models, and deep learning. Additionally, it includes instructions for students regarding lab conduct and a syllabus with specific programming tasks related to AI and ML techniques.

Uploaded by

befarin2022
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

JCT

COLLEGE OF ENGINNERING AND TECHNOLOGY

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING

SIXTH SEMESTER

CS3491 – ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING

RECORD

NAME :
SEMESTER / YEAR :
BRANCH :
REGISTER NUMBER :
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

INSTITUTE VISION:
To emerge as a Premier Institute for developing industry ready engineers with competency, initiative and
character to meet the challenges in global environment.

INSTITUTE MISSION:

 To impart state-of-the-art engineering and professional education through strong theoretical basics and hands on
training to students in their choice of field.

 To serve our students by teaching them leadership, entrepreneurship, teamwork, values, quality, ethics and
respect for others.

 To provide opportunities for long-term interaction with academia and industry.

 To create new knowledge through innovation and research.

DEPARTMENT VISION
Electronics and Communication Engineering department aims to empower the budding engineers with
technological excellence to meet current and imminent challenges in creative research and employment.
DEPARTMENT MISSION

 To cater all necessary inputs to excel in electronics knowledge both in theory and practical.
 To develop leadership and entrepreneurship qualities with social and ethical values.
 To provide the opportunities for innovation & collaborative research with industry.

Programme Educational Objectives (PEO)

1. Graduates will have the potential to become globally competent team players and leaders in the allied fields of
electronics and communication engineering
2. Graduates will have the core technical skills and knowledge that will empower them to pursue lifelong learning
and research
3. Graduates will deliver innovative solutions and services to address industrial and societal challenges, upholding
ethical principles and social responsibility.
Program Outcomes (POs)
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching
substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering problems and design system components
or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research methods including design
of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools
including prediction and modelling to complex engineering activities with an understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety,
legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal and
environmental contexts, and demonstrate the knowledge of, and need for sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering
practice.

9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in
multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the engineering community and
with society at large, such as, being able to comprehend and write effective reports and design documentation, make
effective presentations, and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the engineering and management
principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.

12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-
long learning in the broadest context of technological change.

Program specific outcomes (PSO)

1. Analyze, Design, Simulate and Integrate Electronic Circuits and Systems for given specifications.

2. Apply the technical knowledge to solve complex problems in the areas like signal processing, Communication,
VLSI design and Embedded Systems.
DEPARTMENT OF ECE

INSTRUCTION TO THE STUDENTS

1. Students have to go to respective lab classes according to the lab time table.

2. They have to wear the shoes & the prescribed uniform.

3. They have to know about the procedure of the experiment before start doing the

experiment. It will be checked by the staff members.

4. They have to sit in the allotted system .

5. They have to write the programme themselves and get the output

6. They have to submit their completed previous experiment record at the time of entering into

the laboratory.

7. After completing the experiment, they have to properly switch off their system.

8. Strict discipline is solicited inside the laboratory.

CS3491 Artificial Intelligence and Machine Learning Page 1


DEPARTMENT OF ECE

SYLLABUS

CS3491 ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING LTPC

3024
COURSE OBJECTIVES:
The main objectives of this course are to:
• Study about uninformed and Heuristic search techniques.
• Learn techniques for reasoning under uncertainty
• Introduce Machine Learning and supervised learning algorithms
• Study about ensembling and unsupervised learning algorithms
• Learn the basics of deep learning using neural networks

S.No Practical Exercises 30 PERIODS


1 Implementation of Uninformed search algorithms (BFS, DFS)
2 Implementation of Informed search algorithms (A*, memory-bounded A*)
3 Implement naive Bayes models
4 Implement Bayesian Networks
5 Build Regression models
6 Build decision trees and random forests
7 Build SVM models
8 Implement ensembling techniques
9 Implement clustering algorithms
10 Implementation of Uninformed search algorithms (BFS, DFS)
11 Build simple NN models
12 Build Deep Learning NN models

COURSE OUTCOMES: At the end of this course, the students will be able to:

CO1: Apply the techniques like uninformed search strategies, Heuristic search strategies , Local search and optimization
techniques like adversarial search ,constraint satisfaction problems (CSP) for problem solving.
CO2: Apply Bayesian inference and Naive Bayes models for classification, use probabilistic reasoning to model
uncertainties, construct and analyze Bayesian networks, and perform both exact and approximate inference in complex
systems.
CO3:Build diverse machine learning models, including linear regression, logistic regression, naive Bayes, support vector
machines, decision trees, and random forests for various data analysis and classification tasks.
CO4:Make use of ensemble learning techniques like bagging, boosting, and stacking, combine multiple learners through
voting, and apply various unsupervised learning methods, including K-means clustering, KNN, Gaussian mixture models,
and Expectation Maximization, for effective data analysis and pattern recognition.
CO5: Build deep learning neural network models to design and train neural networks, including perceptrons and
multilayer perceptrons, understand activation functions, implement gradient descent optimization techniques, address
issues like vanishing gradients through ReLU and regularization, and perform hyperparameter tuning.

CONTENT BEYOND SYLLABUS


1. Dimensionality Reduction With PCA
2. Anomaly Detection Using Isolation Forest

CS3491 Artificial Intelligence and Machine Learning Page 2


DEPARTMENT OF ECE
INDEX
EXP. PAGE MARKS FACULTY
DATE TITLE OF THE EXPERIMENT
NO NO AWARDED SIGN

CS3491 Artificial Intelligence and Machine Learning Page 3


DEPARTMENT OF ECE
EX.NO:1 IMPLEMENTATION OF UNINFORMED SEARCHALGORITHMS(BFS,DFS)

DATE:

AIM:

To write a program to implement BFS,DFS Search algorithm using Python.

ALGORITHM:

Breadth First Search (BFS):

Step 1:Start the program

Step 2:Create an empty queue and an empty visited set.

Step 3:Add the starting node to the queue and the visited set.

Step 4:While the queue is not empty, do the following:

Step 4.1 : Remove the first node from the queue.

Step 4.2 :Visit the node.

Step 4.3 :For each unvisited neighbor of the node, add it to the queue and the visited set.

Step 5:Stop the program

Depth First Search (DFS):

Step 1:Start the program

Step 2:Create an empty visited set.

Step 3:Call a helper function with the starting node and the visited set.

Step 4:In the helper function, do the following:

a. Visit the node.

b. Add the node to the visited set.

c. For each unvisited neighbor of the node, call the helper function recursively with the neighbor and the visited set.

Step 5:Stop the program.

CS3491 Artificial Intelligence and Machine Learning Page 4


DEPARTMENT OF ECE
PROGRAM:
# BFS algorithm in Python

import collections

# BFS algorithm
def bfs(graph, root):
visited, queue = set(), collections.deque([root])
visited.add(root)
while queue:
# Dequeue a vertex from queue
vertex = queue.popleft()
print(str(vertex) + " ", end="")

# If not visited, mark it as visited, and


# enqueue it
for neighbour in graph[vertex]:
if neighbour not in visited:
visited.add(neighbour)
queue.append(neighbour)

if __name__ == '__main__':
graph = {0: [1, 2], 1: [2], 2: [3], 3: [1, 2]}
print("Following is Breadth First Traversal:")
bfs(graph, 0)

# DFS algorithm in Python

class Graph:
def __init__(self):
self.graph = {}

def add_edge(self, u, v):


if u not in self.graph:
self.graph[u] = []
self.graph[u].append(v)

def DFS(self, v, visited):


visited.add(v)
print(v, end=' ')

for neighbour in self.graph[v]:


if neighbour not in visited:
self.DFS(neighbour, visited)

def DFS_main(self, v):


visited = set()
self.DFS(v, visited)

g = Graph()
g.add_edge(0, 1)
g.add_edge(0, 2)
g.add_edge(1, 2)
g.add_edge(2, 0)
g.add_edge(2, 3)
g.add_edge(3, 3)

CS3491 Artificial Intelligence and Machine Learning Page 5


DEPARTMENT OF ECE

print("\nDepth First Traversal (starting from vertex 2):")


g.DFS_main(2)

OUTPUT:
Following is Breadth First Traversal:
0123
Depth First Traversal (starting from vertex 2):
2013

RESULT:

Thus the program to implement BFS,DFS and perform inferences is executed and the output is obtained
successfully.

CS3491 Artificial Intelligence and Machine Learning Page 6


DEPARTMENT OF ECE

EX.NO:2 IMPLEMENTATION OF INFORMED SEARCH ALGORITHMS

DATE: (A*,MEMORY-BOUNDED A*)

AIM:

To write a program to implement A* Search algorithm using Python.

ALGORITHM:

Step 1: Start a program

Step 2: Declare the variables.

Step 3: Get the values using input function.

Step 4:Then calculate the approximate value.

Step 5: print the result of program using print function


Step 6: Stop the program execution.

PROGRAM:

A* Algorithm

import heapq

class Node:
def __init__(self, state, parent=None, cost=0, heuristic=0):
self.state = state
self.parent = parent
self.cost = cost
self.heuristic = heuristic

def total_cost(self):
return self.cost + self.heuristic

def astar(start, goal):


open_set = [Node(start, None, 0, heuristic(start, goal))]
closed_set = set()

while open_set:
current_node = min(open_set, key=lambda x: x.total_cost())

if current_node.state == goal:
# Goal reached, reconstruct the path
path = []
while current_node:
path.insert(0, current_node.state)
current_node = current_node.parent
return path

open_set.remove(current_node)
closed_set.add(current_node.state)

for neighbor in get_neighbors(current_node.state):

CS3491 Artificial Intelligence and Machine Learning Page 7


DEPARTMENT OF ECE

if neighbor in closed_set:
continue

cost = current_node.cost + distance(current_node.state, neighbor)


heuristic_value = heuristic(neighbor, goal)
total_cost = cost + heuristic_value

# Check if the neighbor is already in the open set


neighbor_node = next((node for node in open_set if node.state == neighbor), None)

if neighbor_node is None or total_cost < neighbor_node.total_cost():


if neighbor_node is not None:
open_set.remove(neighbor_node)
open_set.append(Node(neighbor, current_node, cost, heuristic_value))

# No path found
return None

def get_neighbors(state):
x, y = state
neighbors = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
# Consider only valid neighbors within the grid
return [(i, j) for i, j in neighbors if 0 <= i < 5 and 0 <= j < 5]

def distance(state1, state2):


# In this example, we assume a distance of 1 between adjacent cells
return 1

def heuristic(state, goal):


# Manhattan distance heuristic
return abs(state[0] - goal[0]) + abs(state[1] - goal[1])

# Example usage
start = (0, 0)
goal = (4, 4)

path = astar(start, goal)

if path:
print("Path found:", path)
else:
print("No path found.")

OUTPUT:
[ (0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4) ]

CS3491 Artificial Intelligence and Machine Learning Page 8


DEPARTMENT OF ECE

Bounded A* Algorithm

class Node:
def __init__(self, state, parent=None, cost=0, heuristic=0):
self.state = state
self.parent = parent
self.cost = cost
self.heuristic = heuristic

def total_cost(self):
return self.cost + self.heuristic

def bounded_a_star(start, goal, bound):


open_set = [Node(start, None, 0, heuristic(start, goal))]
closed_set = set()

while open_set:
current_node = min(open_set, key=lambda x: x.total_cost())

if current_node.state == goal:
# Goal reached within the bound
path = []
while current_node:
path.insert(0, current_node.state)
current_node = current_node.parent
return path

open_set.remove(current_node)
closed_set.add(current_node.state)

for neighbor in get_neighbors(current_node.state):


if neighbor in closed_set:
continue

cost = current_node.cost + 1 # Assuming cost of moving to a neighbor is 1


heuristic_value = heuristic(neighbor, goal)
total_cost = cost + heuristic_value

if total_cost <= bound:


neighbor_node = Node(neighbor, current_node, cost, heuristic_value)

if neighbor_node not in open_set:


open_set.append(neighbor_node)

# No solution found within the bound


return None

def get_neighbors(state):
x, y = state
neighbors = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
# Consider only valid neighbors within the grid
return [(i, j) for i, j in neighbors if 0 <= i < 5 and 0 <= j < 5]

def distance(state1, state2):


# In this example, we assume a distance of 1 between adjacent cells
return 1

CS3491 Artificial Intelligence and Machine Learning Page 9


DEPARTMENT OF ECE

def heuristic(state, goal):


# Manhattan distance heuristic
return abs(state[0] - goal[0]) + abs(state[1] - goal[1])

# Example usage
start = (0, 0)
goal = (4, 4)
bound = 10

path = bounded_a_star(start, goal, bound)

if path:
print("Path found:", path)
else:
print("No path found within the given bound.")

CS3491 Artificial Intelligence and Machine Learning Page 10


DEPARTMENT OF ECE

OUTPUT:
[ (0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4) ]

RESULT:

Thus the program to implement A* and memory bounded A* Search algorithm is executed and the output
is obtained successfully.

CS3491 Artificial Intelligence and Machine Learning Page 11


DEPARTMENT OF ECE

EX.NO:3 IMPLEMENTATION OF NAÏVEBAYES MODELS

DATE:

AIM:

To write a program to implement Naive Bayes models using Python.

ALGORITHM:

Step 1: Start a program


Step 2: Declare the variables.
Step 3: Get the values using input function
Step 4:Then calculate the approximate value.
Step 5: print the result of program using print function
Step 6: Stop the program execution

PROGRAM:
from sklearn.feature_extraction.text import
CountVectorizer
from sklearn.naive_bayes import
MultinomialNB
from sklearn.metrics import accuracy_score,
classification_report
from sklearn.model_selection import
train_test_split

# Sample data (text classification example)


corpus = [
('I love programming', 'positive'),
('Machine learning is fascinating', 'positive'),
('I dislike bugs', 'negative'),
('Python is my favorite language', 'positive'),
('I hate errors', 'negative'),
]

# Extract features and labels


texts, labels = zip(*corpus)

# Split the data into training and test sets


text_train, text_test, label_train, label_test =
train_test_split(texts, labels, test_size=0.2,
random_state=42)
# Vectorize the text data
vectorizer = CountVectorizer()
X_train = vectorizer.fit_transform(text_train)
X_test = vectorizer.transform(text_test)
# Train a Naive Bayes classifier
CS3491 Artificial Intelligence and Machine Learning Page 12
DEPARTMENT OF ECE

classifier = MultinomialNB()
classifier.fit(X_train, label_train)

# Make predictions on the test set


predictions = classifier.predict(X_test)

# Evaluate the classifier


accuracy = accuracy_score(label_test,
predictions)
print(f'Accuracy on test set: {accuracy:.2f}')

print('\nClassification Report on test set:')


print(classification_report(label_test,
predictions))
)

OUTPUT:

Accuracy on test set: 1.00

Classification Report on test set:


precision recall f1-score support

positive 1.00 1.00 1.00 1

accuracy 1.00 1
macro avg 1.00 1.00 1.00 1
weighted avg 1.00 1.00 1.00 1

RESULT:

Thus the program to implement Naive Bayes models is executed and the output is obtained successfully.

CS3491 Artificial Intelligence and Machine Learning Page 13


DEPARTMENT OF ECE

EX.NO: 4 IMPLEMENTATION OF BAYESIAN NETWORKS

DATE:

AIM:

To write a program to implement Bayesian networks and perform inferences using Python.

ALGORITHM:

Step 1: Start a program


Step 2: Declare the variables.
Step 3: Get the values using input function.

Step 4:Then calculate the approximate value.


Step 5: print the result of program using print function
Step 6: Stop the program execution

PROGRAM:
!pip install pgmpy

from pgmpy.models import BayesianModel


from pgmpy.estimators import ParameterEstimator
from pgmpy.inference import VariableElimination
import pandas as pd

# Define the structure of the Bayesian network


model = BayesianModel([('Rain', 'TrafficJam'), ('Accident', 'TrafficJam')])

# Generate some random data for training


data = pd.DataFrame(data={'Rain': [1, 0, 1, 0, 1, 0, 1, 0],
'Accident': [1, 0, 1, 0, 1, 0, 1, 0],
'TrafficJam': [1, 1, 1, 1, 0, 0, 0, 0]})

# Fit the model to the data


model.fit(data)

# Print the CPDs (Conditional Probability Distributions)


for cpd in model.get_cpds():
print("CPD for {}: \n{}".format(cpd.variable, cpd))

# Perform inference
inference = VariableElimination(model)
query_result = inference.map_query(variables=['TrafficJam'], evidence={'Rain': 1, 'Accident': 0})
print("\nProbability of TrafficJam given Rain=1 and Accident=0:")
print(query_result)

# Predict TrafficJam given Rain=1 and Accident=0


predicted_traffic_jam = model.predict(data.loc[:, ['Rain', 'Accident']])
print("\nPredicted TrafficJam:")
print(predicted_traffic_jam['TrafficJam'])

CS3491 Artificial Intelligence and Machine Learning Page 14


DEPARTMENT OF ECE

OUTPUT

RESULT:

Thus the program to implement Bayesian networks and perform inferences is executed and the output
isobtained successfully.
CS3491 Artificial Intelligence and Machine Learning Page 15
DEPARTMENT OF ECE

EX.NO:5 BUILD REGRESSION MODELS

DATE:

AIM:

To write a program to implement Build Regression models and perform inferences using Python.

ALGORITHM:

Step 1: Start the program

Step 2:Import the necessary libraries, including pandas, numpy, and scikit-learn.

Step 3:Load the data into a Pandas DataFrame.

Step 4:Preprocess the data by removing any missing values and converting categorical variables to
numerical representations using one-hot encoding or label encoding.

Step 5:Split the data into training and testing sets using the train_test_split function from scikit-learn.

Step 6:Choose a regression algorithm and instantiate the model object. Popular choices include linear regression,
polynomial regression, and random forest regression.

Step 7:Fit the model to the training data using the fit method.

Step 8:Evaluate the model on the testing data using metrics such as mean squared error (MSE) or R-squared.

Step 9:Use the model to make predictions on new data using the predict method.

Step 10:Perform inferences by analyzing the model coefficients or feature importances to gain insight into the
relationships between the input variables and the output variable.

Step 11:Stop the program

CS3491 Artificial Intelligence and Machine Learning Page 16


DEPARTMENT OF ECE

PROGRAM:
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt

# Generate some random data for demonstration


np.random.seed(42)
X = 2 * np.random.rand(100, 1)
y = 4 + 3 * X + np.random.randn(100, 1)

# Split the data into training and test sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a Linear Regression model


model = LinearRegression()
model.fit(X_train, y_train)

# Make predictions on the test set


y_pred = model.predict(X_test)

# Evaluate the model


mse = mean_squared_error(y_test, y_pred)
print(f'Mean Squared Error: {mse:.2f}')

# Plot the regression line


plt.scatter(X_test, y_test, color='black')
plt.plot(X_test, y_pred, color='blue', linewidth=3)
plt.xlabel('X')
plt.ylabel('y')
plt.title('Linear Regression Model')
plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 17


DEPARTMENT OF ECE

OUTPUT:

RESULT:

Thus the program to implement build regression models and perform inferences is executed and the
output is obtained successfully.

CS3491 Artificial Intelligence and Machine Learning Page 18


DEPARTMENT OF ECE

EXNO: 6 BUILD DECISION TREES AND RANDOM FORESTS

DATE:

AIM:

To write a program for build decision trees and random forests.

ALGORITHM:

DECISION TREES:

Step-1: Begin the tree with the root node, says S, which contains the complete dataset.

Step-2: Find the best attribute in the dataset using Attribute Selection Measure (ASM).

Step-3: Divide the S into subsets that contains possible values for the best attributes.

Step-4: Generate the decision tree node, which contains the best attribute.

Step-5: Recursively make new decision trees using the subsets of the dataset created in step -3. Continue this
process until a stage is reached where you cannot further classify the nodes and called the final node as a leaf
node.

RANDOM FOREST:

Step 1: Select random samples from a given data or training set.

Step 2: This algorithm will construct a decision tree for every training data.

Step 3: Voting will take place by averaging the decision tree.

Step 4: Finally, select the most voted prediction result as the final prediction result.

CS3491 Artificial Intelligence and Machine Learning Page 19


DEPARTMENT OF ECE

PROGRAM:

DECISION TREES:

from sklearn.datasets import load_iris


from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
import matplotlib.pyplot as plt
import seaborn as sns

# Load the Iris dataset


iris = load_iris()
X = iris.data
y = iris.target

# Split the data into training and test sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a Decision Tree classifier


model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train)

# Make predictions on the test set


y_pred = model.predict(X_test)

# Evaluate the classifier


accuracy = accuracy_score(y_test, y_pred)
print(f'Accuracy: {accuracy:.2f}')

print('\nClassification Report:')
print(classification_report(y_test, y_pred))

# Plot the confusion matrix


cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(6, 4))
sns.heatmap(cm, annot=True, fmt='g', cmap='Blues', xticklabels=iris.target_names, yticklabels=iris.target_names)
plt.title('Confusion Matrix')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 20


DEPARTMENT OF ECE

PROGRAM:

RANDOM FOREST:

from sklearn.datasets import load_iris


from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
import matplotlib.pyplot as plt
import seaborn as sns

# Load the Iris dataset


iris = load_iris()
X = iris.data
y = iris.target

# Split the data into training and test sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a Random Forest classifier


model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Make predictions on the test set


y_pred = model.predict(X_test)

# Evaluate the classifier


accuracy = accuracy_score(y_test, y_pred)
print(f'Accuracy: {accuracy:.2f}')

print('\nClassification Report:')
print(classification_report(y_test, y_pred))

# Plot the confusion matrix


cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(6, 4))
sns.heatmap(cm, annot=True, fmt='g', cmap='Blues', xticklabels=iris.target_names, yticklabels=iris.target_names)
plt.title('Confusion Matrix')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 21


DEPARTMENT OF ECE

OUTPUT:

CS3491 Artificial Intelligence and Machine Learning Page 22


DEPARTMENT OF ECE

RESULT:

Thus the program decision trees and random has been build and output is verified successfully.
CS3491 Artificial Intelligence and Machine Learning Page 23
DEPARTMENT OF ECE

EXNO:7 BUILD SVM MODELS

DATE:

AIM:

To write a program for build SVM models using python.

ALGORITHM:

Step 1: Load Pandas library and the dataset using Pandas.

Step 2: Define the features and the target.

Step 3: Split the dataset into train and test using sklearn before building the SVM algorithm model.

Step 4: Import the support vector classifier function or SVC function from Sklearn SVM module. Build the Support
Vector Machine model with the help of the SVC function.

Step 5: Predict values using the SVM algorithm model.

Step 6: Evaluate the Support Vector Machine model

PROGRAM:

# importing scikit learn with make_blobs


from sklearn.datasets import make_blobs

# creating datasets X containing n_samples


# Y containing two classes
X, Y = make_blobs(n_samples=500, centers=2,
random_state=0, cluster_std=0.40)
import matplotlib.pyplot as plt
# plotting scatters
plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='spring');
plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 24


DEPARTMENT OF ECE

OUTPUT

RESULT:

Thus the program has been build SVM models and output is verified successfully.
CS3491 Artificial Intelligence and Machine Learning Page 25
DEPARTMENT OF ECE

EXNO:8 IMPLEMENT ENSEMBLING TECHNIQUES

DATE:

AIM:

To write and implement ensembling techniques program using python.

ALGORITHM:

Step 1:import the pandas.

Step 2:insert the csv file.

Step 3:create the model and predictions.

Step 4:display the output.

Step 5:stop.

CS3491 Artificial Intelligence and Machine Learning Page 26


DEPARTMENT OF ECE

PROGRAM:

from sklearn.datasets import load_iris

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier

from sklearn.metrics import accuracy_score, classification_report, confusion_matrix

import matplotlib.pyplot as plt

import seaborn as sns

# Load the Iris dataset

iris = load_iris()

X = iris.data

y = iris.target

# Split the data into training and test sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Bagging: Random Forest

rf_model = RandomForestClassifier(n_estimators=100, random_state=42)

rf_model.fit(X_train, y_train)

# Make predictions on the test set using Random Forest

y_pred_rf = rf_model.predict(X_test)

# Evaluate the Random Forest model

accuracy_rf = accuracy_score(y_test, y_pred_rf)

print(f'Accuracy (Random Forest): {accuracy_rf:.2f}')

print('\nClassification Report (Random Forest):')

print(classification_report(y_test, y_pred_rf))

# Plot the confusion matrix for Random Forest

CS3491 Artificial Intelligence and Machine Learning Page 27


DEPARTMENT OF ECE

cm_rf = confusion_matrix(y_test, y_pred_rf)

plt.figure(figsize=(6, 4))

sns.heatmap(cm_rf, annot=True, fmt='g', cmap='Blues', xticklabels=iris.target_names, yticklabels=iris.target_names)

plt.title('Confusion Matrix (Random Forest)')

plt.xlabel('Predicted')

plt.ylabel('Actual')

plt.show()

# Boosting: AdaBoost

adaboost_model = AdaBoostClassifier(n_estimators=50, random_state=42)

adaboost_model.fit(X_train, y_train)

# Make predictions on the test set using AdaBoost

y_pred_adaboost = adaboost_model.predict(X_test)

# Evaluate the AdaBoost model

accuracy_adaboost = accuracy_score(y_test, y_pred_adaboost)

print(f'\nAccuracy (AdaBoost): {accuracy_adaboost:.2f}')

print('\nClassification Report (AdaBoost):')

print(classification_report(y_test, y_pred_adaboost))

# Plot the confusion matrix for AdaBoost

cm_adaboost = confusion_matrix(y_test, y_pred_adaboost)

plt.figure(figsize=(6, 4))

sns.heatmap(cm_adaboost, annot=True, fmt='g', cmap='Blues', xticklabels=iris.target_names, yticklabels=iris.target_names)

plt.title('Confusion Matrix (AdaBoost)')

plt.xlabel('Predicted')

plt.ylabel('Actual')

plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 28


DEPARTMENT OF ECE

OUTPUT:

CS3491 Artificial Intelligence and Machine Learning Page 29


DEPARTMENT OF ECE

RESULT:

Thus the program ensembling techniques has been implemented and output is verified successfully.

CS3491 Artificial Intelligence and Machine Learning Page 30


DEPARTMENT OF ECE

EXNO:9 IMPLEMENT CLUSTERING ALGORITHMS

DATE:

AIM:

To write a program to implement clustering algorithms using python.

ALGORITHM:

Step 1:import the numpy and seaborn

Step 2:insert the dataset.

Step 3:define the dataset.

Step 4:plot the points for the given data set.

Step 5:Stop.

PROGRAM:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

# Generate synthetic data for demonstration


X, _ = make_blobs(n_samples=300, centers=4, random_state=42)

# Visualize the data


plt.scatter(X[:, 0], X[:, 1], s=50, cmap='viridis')
plt.title('Generated Data')
plt.show()

# Apply K-Means clustering


kmeans = KMeans(n_clusters=4, random_state=42)
kmeans.fit(X)

# Get cluster centers and labels


centers = kmeans.cluster_centers_
labels = kmeans.labels_

# Visualize the clusters


plt.scatter(X[:, 0], X[:, 1], c=labels, s=50, cmap='viridis')
plt.scatter(centers[:, 0], centers[:, 1], c='red', s=200, alpha=0.75, marker='X')
plt.title('K-Means Clustering')
plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 31


DEPARTMENT OF ECE

OUTPUT:

RESULT:
Thus the program clusters algorithm has been implemented and output is verified successfully.
CS3491 Artificial Intelligence and Machine Learning Page 32
DEPARTMENT OF ECE

EXNO:10 IMPLEMENT EM FOR BAYESIAN NETWORKS

DATE:

AIM:

To implement EM implement for Bayesian networks using python.

ALGORITHM:

Step 1. Define the discrete probability distributions for the guest, prize, and Monty's choices.

Step 2. Create three states for each distribution using the pomegranate library.

Step 3. Add the three states to a Bayesian Network object and add edges connecting the guest and prize to the Monty
state.

Step 4. Bake the network.

Step 5. Predict the probabilities of the prize distribution given that the guest chose a specific door (in this case, door
A).

Step 6. Print the resulting beliefs.

PROGRAM:
import numpy as np
from pgmpy.models import BayesianModel
from pgmpy.estimators import ParameterEstimator
from pgmpy.inference import VariableElimination
from pgmpy.sampling import BayesianModelSampling

# Generate a simple Bayesian Network


model = BayesianModel([('A', 'B'), ('C', 'B')])

# Generate some synthetic data


data = BayesianModelSampling(model).forward_sample(size=1000, seed=42)

# Introduce missing values


missing_data = data.copy()
missing_data.loc[np.random.choice(data.index, size=100, replace=False), 'B'] = None

# Define the EM algorithm


def expectation_maximization(model, data, max_iterations=100):
for _ in range(max_iterations):
# Expectation step
inferred_data = VariableElimination(model).map_query(variables=['B'], evidence={'A': data['A'].values, 'C':
data['C'].values})

# Maximization step
data['B'].fillna(inferred_data['B'], inplace=True)

return data

# Apply EM to fill in missing values


completed_data = expectation_maximization(model, missing_data)

# Learn parameters from the completed data


pe = ParameterEstimator(model, completed_data)
model.fit(data, estimator=pe)
CS3491 Artificial Intelligence and Machine Learning Page 33
DEPARTMENT OF ECE

# Print CPDs (Conditional Probability Distributions)


for cpd in model.get_cpds():
print(f"CPD for {cpd.variable}:\n{cpd}")

# Perform inference on the learned model


inference = VariableElimination(model)
query_result = inference.map_query(variables=['B'], evidence={'A': 1, 'C': 0})
print("\nProbability of B given A=1 and C=0:")
print(query_result)

CS3491 Artificial Intelligence and Machine Learning Page 34


DEPARTMENT OF ECE

OUTPUT:

guest tDiscreteDistribution({'A': 1.0, 'B': 0.0, 'C': 0.0})

prize tDiscreteDistribution({'A': 0.3333333333333333, 'B': 0.3333333333333333, 'C': 0.3333333333333333})

monty tDiscreteDistribution({'C': 0.49999999999999983, 'A': 0.0, 'B': 0.49999999999999983})

RESULT:

Thus the program EM for Bayesian networks has been implemented and output is verified successfully.

CS3491 Artificial Intelligence and Machine Learning Page 35


DEPARTMENT OF ECE

EXNO: 11 BUILD SIMPLE NN MODELS

DATE:

AIM:

To write a program for build simple NN models using python.

ALGORITHM:

Step 1: Import the required libraries: TensorFlow and Matplotlib

Step 2: Load the CIFAR-10 dataset using the `datasets.cifar10.load_data()` function from

TensorFlow. This function returns two tuples, one for the training set and another for the test set.

Step 3: Normalize the pixel values of the images in both the training and test sets to be between 0 and 1.

Step 4:Define a list of class names for the 10 categories in CIFAR-10.

Step 5:Plot 25 images from the training set with their corresponding labels using Matplotlib.

PROGRAM:

import tensorflow as tf

from tensorflow.keras import datasets, layers, models


import matplotlib.pyplot as plt

(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()

# Normalize pixel values to be between 0 and 1


train_images, test_images = train_images / 255.0, test_images / 255.0
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
'dog', 'frog', 'horse', 'ship', 'truck']

plt.figure(figsize=(10,10))
for i in range(25):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i])
# The CIFAR labels happen to be arrays,
# which is why you need the extra index
plt.xlabel(class_names[train_labels[i][0]])
plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 36


DEPARTMENT OF ECE

OUTPUT:

RESULT:

Thus the program simple NN models has been implemented and output is verified successfully.

CS3491 Artificial Intelligence and Machine Learning Page 37


DEPARTMENT OF ECE

EXNO:12 BUILDI DEEP LEARNING NN MODELS

DATE:

AIM:

To write a program for build Deep Learning NN models using python.

ALGORITHM:

Step 1: Import Necessary Libraries

Step 2: Define Input and Output Data

Step 3: Build the Neural Network Model

Step 4:Compile the Model.

Step 5:Train the model

PROGRAM:

# Import python libraries required in this example:

from keras.models import Sequential

from keras.layers import Dense, Activation

import numpy as np

# Use numpy arrays to store inputs (x) and outputs (y):

x = np.array([[0,0], [0,1], [1,0], [1,1]])

y = np.array([[0], [1], [1], [0]])

# Define the network model and its arguments.

# Set the number of neurons/nodes for each layer:

model = Sequential()

model.add(Dense(2, input_shape=(2,)))

model.add(Activation('sigmoid'))

model.add(Dense(1))

model.add(Activation('sigmoid'))

# Compile the model and calculate its accuracy:

model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy'])

# Print a summary of the Keras model:

model.summary()

CS3491 Artificial Intelligence and Machine Learning Page 38


DEPARTMENT OF ECE

OUTPUT:

RESULT:

Thus the program simple Deep Learning NN models has been implemented and output is verified
successfully.

CS3491 Artificial Intelligence and Machine Learning Page 39


DEPARTMENT OF ECE

CONTENT BEYOND THE SYLLABUS

CS3491 Artificial Intelligence and Machine Learning Page 40


DEPARTMENT OF ECE

EXNO:13 DIMENSIONALITY REDUCTION WITH PCA

DATE:

AIM:

To write a program for Dimensionality Reduction with Principal Component Analysis (PCA) using python.

ALGORITHM:

Step 1: Loads the Iris dataset.

Step 2: Standardizes the data using StandardScaler.

Step 3: Applies PCA to reduce the data to 2 principal components.

Step 4:Prints the explained variance ratio for each principal component.

Step 5:Plots the 2D projection of the data.

PROGRAM:

# Import necessary libraries

import numpy as np

import matplotlib.pyplot as plt

from sklearn.decomposition import PCA

from sklearn.datasets import load_iris

# Load the Iris dataset

iris = load_iris()

X = iris.data

y = iris.target

# Standardize the data (optional, but recommended for PCA)

from sklearn.preprocessing import StandardScaler

X_standardized = StandardScaler().fit_transform(X)

# Apply PCA and reduce the data to 2 principal components

pca = PCA(n_components=2)

X_pca = pca.fit_transform(X_standardized)

# Print the explained variance ratio


CS3491 Artificial Intelligence and Machine Learning Page 41
DEPARTMENT OF ECE

print("Explained Variance Ratio:", pca.explained_variance_ratio_)

# Plot the 2D projection of the data

plt.figure(figsize=(8, 6))

colors = ['red', 'green', 'blue']

for i in range(len(colors)):

plt.scatter(X_pca[y == i, 0], X_pca[y == i, 1], label=iris.target_names[i], color=colors[i])

plt.title('PCA of Iris Dataset')

plt.xlabel('Principal Component 1')

plt.ylabel('Principal Component 2')

plt.legend()

plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 42


DEPARTMENT OF ECE

OUTPUT:

RESULT:

Thus the program for Dimensionality Reduction with Principal Component Analysis (PCA) using python.

has been implemented and output is verified successfully.

CS3491 Artificial Intelligence and Machine Learning Page 43


DEPARTMENT OF ECE

EXNO:14 ANOMALY DETECTION USING ISOLATION FOREST

DATE:

AIM:

To write a program for Anomaly Detection using Isolation Forests using python

ALGORITHM:

Step 1: Generates a synthetic datasets with normal data and anomalies.

Step 2:Creates an Isolation Forest model and fits it to the datasets.

Step 3: Predicts outliers (anomalies) in the datasets using the trained model.

Step 4:Plots the data points and highlights anomalies using different colors.

PROGRAM:

# Import necessary libraries

import numpy as np

import matplotlib.pyplot as plt

from sklearn.ensemble import IsolationForest

# Generate a synthetic dataset with anomalies

np.random.seed(42)

normal_data = np.random.normal(loc=0, scale=1, size=(1000, 2))

anomalies = np.random.normal(loc=5, scale=1, size=(50, 2))

data = np.vstack([normal_data, anomalies])

# Create and fit an Isolation Forest model

clf = IsolationForest(contamination=0.05, random_state=42)

clf.fit(data)

# Predict outliers (anomalies) in the dataset

predictions = clf.predict(data)

CS3491 Artificial Intelligence and Machine Learning Page 44


DEPARTMENT OF ECE

# Plot the data points and highlight anomalies

plt.figure(figsize=(8, 6))

plt.scatter(data[:, 0], data[:, 1], c=predictions, cmap='viridis', edgecolor='k')

plt.title('Isolation Forest Anomaly Detection')

plt.xlabel('Feature 1')

plt.ylabel('Feature 2')

plt.show()

CS3491 Artificial Intelligence and Machine Learning Page 45


DEPARTMENT OF ECE

OUTPUT:

RESULT:

Thus the program for Anomaly Detection using Isolation Forests using python has been implemented and output is
verified successfully.

CS3491 Artificial Intelligence and Machine Learning Page 46


DEPARTMENT OF ECE

ANNEXURE I

SAMPLE VIVA VOCE QUESTIONS AND ANSWERS

1) What do you understand by Artificial Intelligence?

Artificial intelligence is computer science technology that emphasizes creating intelligent machine that can mimic human behavior.
Here Intelligent machines can be defined as the machine that can behave like a human, think like a human, and also capable of
decision making. It is made up of two words, "Artificial" and "Intelligence," which means the "man-made thinking ability."

With artificial intelligence, we do not need to pre-program the machine to perform a task; instead, we can create a machine with the
programmed algorithms, and it can work on its own.

2) Why do we need Artificial Intelligence?

The goal of Artificial intelligence is to create intelligent machines that can mimic human behavior. We need AI for today's world to
solve complex problems, make our lives more smoothly by automating the routine work, saving the manpower, and to perform
many more other tasks.

3) Give some real-world applications of AI.

There are various real-world applications of AI, and some of them are given below:

o Google Search Engine: When we start writing something on the google search engine, we immediately get the relevant
recommendations from google, and this is because of different AI technologies.

o Ridesharing Applications: Different ride-sharing applications such as Uber uses AI and machine learning to determine the
type of ride, minimize the time once the car is hailed by the user, price of the ride, etc.

o Spam Filters in Email: The AI is also used for email spam filtering so that you can get the important and relevant emails
only in your inbox. As per the studies, Gmail successfully filters 99.9% of spam mails.

o Social Networking: Different social networking sites such as Facebook, Instagram, Pinterest, etc., use the AI technology
for different purposes such as face recognition and friend suggestions, when you upload a photograph on Facebook,
understanding the contextual meaning of an emoji in Instagram, and so on.

o Product recommendations: When we search for a product on Amazon, we get the recommendation for similar products,
and this is because of different ML algorithms. Similarly, on Netflix, we get personalized recommendations for movies and
web series.

4) How Artificial intelligence, Machine Learning, and Deep Learning differ from each other?

The difference between AI, ML, and Deep Learning is given in the below table:

Artificial Intelligence Machine Learning Deep Learning

The term Artificial intelligence was The term ML was first coined The term DL was first coined in the year 2000
first coined in the year 1956 by in the year 1959 by Arthur Igor Aizenberg.
John McCarthy. Samuel.

It is a technology that is used to It is a subset of AI that It is the subset of machine learning and AI that is
create intelligent machines that can learns from past data and inspired by the human brain cells, called neurons,
mimic human behavior. experiences. and imitates the working of the human brain.

AI completely deals with structured, ML deals with structured and Deep learning deals with structured and
semi-structured data. semi-structured data. unstructured data.

CS3491 Artificial Intelligence and Machine Learning Page 47


DEPARTMENT OF ECE

It requires a huge amount of data to It can work with less amount It requires a huge amount of the data compared to
work. of data compared to deep the ML.
learning and AI.

The goal of AI is to enable the The goal of ML is to enable The goal of deep learning is to solve the complex
machine to think without any human the machine to learn from problems as the human brain does, using various
intervention. past experiences. algorithms.

5) What are the types of AI?

Artificial intelligence can be divided into different types on the basis of capabilities and functionalities.

Based on Capabilities:

o Weak AI or Narrow AI: Weak AI is capable of performing some dedicated tasks with intelligence. Siri is an example of
Weak AI.

o General AI: The intelligent machines that can perform any intellectual task with efficiency as a human.

o Strong AI: It is the hypothetical concept that involves the machine that will be better than humans and will surpass human
intelligence.

Based on Functionalities:

o Reactive Machines: Purely reactive machines are the basic types of AI. These focus on the present actions and cannot
store the previous actions. Example: Deep Blue.

o Limited Memory: As its name suggests, it can store the past data or experience for the limited duration. The self-driving
car is an example of such AI types.

o Theory of Mind: It is the advanced AI that is capable of understanding human emotions, people, etc., in the real world.

o Self-Awareness: Self Awareness AI is the future of Artificial Intelligence that will have their own consciousness, emotions,
similar to humans. Read More.

6) What are the different domains/Subsets of AI?

AI covers lots of domains or subsets, and some main domains are given below:

o Machine Learning

o Deep Learning

o Neural Network

o Expert System

o Fuzzy Logic

o Natural Language Processing

o Robotics

o Speech Recognition. Read More

7) What are the types of Machine Learning?

Machine Learning can be mainly divided into three types:

CS3491 Artificial Intelligence and Machine Learning Page 48


DEPARTMENT OF ECE

a. Supervised Learning: Supervised learning is a type of Machine learning in which the machine needs external supervision
to learn from data. The supervised learning models are trained using the labeled
dataset. Regression and Classification are the two main problems that can be solved with Supervised Machine Learning.

b. Unsupervised Learning: It is a type of machine learning in which the machine does not need any external supervision to
learn from the data, hence called unsupervised learning. The unsupervised models can be trained using the unlabelled
dataset. These are used to solve the Association and Clustering problems.

c. Reinforcement Learning: In Reinforcement learning, an agent interacts with its environment by producing actions, and
learn with the help of feedback. The feedback is given to the agent in the form of rewards, such as for each good action, he
gets a positive reward, and for each bad action, he gets a negative reward. There is no supervision provided to the agent.
Q-Learning algorithm is used in reinforcement learning.

8) Explain the term "Q-Learning."

Q-learning is a popular algorithm used in reinforcement learning. It is based on the Bellman equation. In this algorithm, the agent
tries to learn the policies that can provide the best actions to perform for maximining the rewards under particular circumstances.
The agent learns these optimal policies from past experiences.

In Q-learning, the Q is used to represent the quality of the actions at each state, and the goal of the agent is to maximize the value
of Q.

9) What is Deep Learning, and how is it used in real-world?

Deep learning is a subset of Machine learning that mimics the working of the human brain. It is inspired by the human brain cells,
called neurons, and works on the concept of neural networks to solve complex real-world problems. It is also known as the
deep neural network or deep neural learning.

Some real-world applications of deep learning are:

o Adding different colors to the black&white images

o Computer vision

o Text generation

o Deep-Learning Robots, etc.

10) Which programming language is used for AI?

Below are the top five programming languages that are widely used for the development of Artificial Intelligence:

o Python

o Java

o Lisp

o R

o Prolog

Among the above five languages, Python is the most used language for AI development due to its simplicity and availability of lots of
libraries, such as Numpy, Pandas, etc.

11) What is the intelligent agent in AI, and where are they used?

The intelligent agent can be any autonomous entity that perceives its environment through the sensors and act on it using the
actuators for achieving its goal.

These Intelligent agents in AI are used in the following applications:

CS3491 Artificial Intelligence and Machine Learning Page 49


DEPARTMENT OF ECE

o Information Access and Navigations such as Search Engine

o Repetitive Activities

o Domain Experts

o Chatbots, etc.

12) How is machine learning related to AI?

Machine learning is a subset or subfield of Artificial intelligence. It is a way of achieving AI. As both are the two different concepts
and the relation between both can be understood as "AI uses different Machine learning algorithms and concepts to solve the
complex problems."

13) What is Markov's Decision process?

The solution for a reinforcement learning problem can be achieved using the Markov decision process or MDP. Hence, MDP is used to
formalize the RL problem. It can be said as the mathematical approach to solve a reinforcement learning problem. The main aim of
this process is to gain maximum positive rewards by choosing the optimum policy.

MDP has four elements, which are:

o A set of finite states S

o A set of finite actions A

o Rewards

o Policy Pa

In this process, the agent performs an action A to take a transition from state S1 to S2 or from the start state to the end state, and
while doing these actions, the agent gets some rewards. The series of actions taken by the agent can be defined as the policy.

14) What do you understand by the reward maximization?

Reward maximization term is used in reinforcement learning, and which is a goal of the reinforcement learning agent. In RL, a
reward is a positive feedback by taking action for a transition from one state to another. If the agent performs a good action by

CS3491 Artificial Intelligence and Machine Learning Page 50


DEPARTMENT OF ECE

applying optimal policies, he gets a reward, and if he performs a bad action, one reward is subtracted. The goal of the agent is to
maximize these rewards by applying optimal policies, which is termed as reward maximization.

15) What are parametric and non-parametric model?

In machine learning, there are mainly two types of models, Parametric and Non-parametric. Here parameters are the predictor
variables that are used to build the machine learning model. The explanation of these models is given below:

Parametric Model: The parametric models use a fixed number of the parameters to create the ML model. It considers strong
assumptions about the data. The examples of the parametric models are Linear regression, Logistic Regression, Naïve Bayes,
Perceptron, etc.

Non-Parametric Model: The non-parametric model uses flexible numbers of parameters. It considers a few assumptions about the
data. These models are good for higher data and no prior knowledge. The examples of the non-parametric models are Decision Tree,
K-Nearest Neighbour, SVM with Gaussian kernels, etc.

16) What do you understand by the hyperparameter?

In machine learning, hyperparameter is the parameters that determine and control the complete training process. The examples of
these parameters are Learning rate, Hidden Layers, Hidden units, Activation functions, etc. These parameters are external from the
model. The selection of good hyperparameters makes a better algorithm.

17) Explain the Hidden Markov model.

Hidden Markov model is a statistical model used for representing the probability distributions over a chain of observations. In the
hidden markov model, hidden defines a property that it assumes that the state of a process generated at a particular time is hidden
from the observer, and Markov defines that it assumes that the process satisfies the Markov property. The HMM models are mostly
used for temporal data.

The HMM is used in various applications such as reinforcement learning, temporal pattern recognition, etc.

18) What is Strong AI, and how is it different from the Weak AI?

Strong AI: Strong AI is about creating real intelligence artificially, which means a human-made intelligence that has sentiments,
self-awareness, and emotions similar to humans. It is still an assumption that has a concept of building AI agents with thinking,
reasoning, and decision-making capabilities similar to humans.

Weak AI: Weak AI is the current development stage of artificial intelligence that deals with the creation of intelligent agents and
machines that can help humans and solve real-world complex problems. Siri and Alexa are examples of Weak AI programs.

19) Give a brief introduction to the Turing test in AI?

Turing test is one of the popular intelligence tests in Artificial intelligence. The Turing test was introduced by Alan Turing in the year
1950. It is a test to determine that if a machine can think like a human or not. According to this test, a computer can only be said to
be intelligent if it can mimic human responses under some particular conditions.

In this test, three players are involved, the first player is a computer, the second player is a human responder, and the third player
is the human interrogator, and the interrogator needs to find which response is from the machine on the basis of questions and
answers.

20) Which assessment is used to test the intelligence of the machine?

Turing Test.

21) What is overfitting? How can it be overcome in Machine Learning?

When the machine learning algorithm tries to capture all the data points, and hence, as a result, captures noise also, then overfitting
occurs in the model. Due to this overfitting issue, the algorithm shows the low bias, but the high variance in the output. Overfitting
is one of the main issues in machine learning.

CS3491 Artificial Intelligence and Machine Learning Page 51


DEPARTMENT OF ECE

Methods to avoid Overfitting in ML:

o Cross-Validation

o Training With more data

o Regularization

o Ensembling

o Removing Unnecessary Features

o Early Stopping the training.

22) Tell one technique to avoid overfitting in neural networks?

Dropout Technique: The dropout technique is one of the popular techniques to avoid overfitting in the neural network models. It is
the regularization technique, in which the randomly selected neurons are dropped during training.

23) What is NLP? What are the various components of NLP?

NLP stands for Natural Language Processing, which is a branch of artificial intelligence. It enables machines to understand, interpret,
and manipulate the human language.

Components of NLP:

There are mainly two components of Natural Language processing, which are given below:

a. Natural Language Understanding (NLU):


It involves the below tasks:

o To map the input to useful representations.

o To analyze the different aspects of the language.

b. Natural Language Generation (NLG)

o Text Planning

o Sentence Planning

o Text Realization

24) What are the different components of the Expert System?

An expert system mainly contains three components:

a. User Interface: It enables a user to interact or communicate with the expert system to find the solution for a problem.

b. Inference Engine: It is called the main processing unit or brain of the expert system. It applies different inference rules to
the knowledge base to draw a conclusion from it. The system extracts the information from the KB with the help of an
inference engine.

c. Knowledge Base: The knowledge base is a type of storage area that stores the domain-specific and high-quality
knowledge.

25) What is the use of computer vision in AI?

Computer vision is a field of Artificial Intelligence that is used to train the computers so that they can interpret and obtain
information from the visual world such as images. Hence, computer vision uses AI technology to solve complex problems
such as image processing, object detections, etc.

CS3491 Artificial Intelligence and Machine Learning Page 52


DEPARTMENT OF ECE

26) Explain the minimax algorithm along with the different terms.

Minimax algorithm is a backtracking algorithm used for decision making in game theory. This algorithm provides the optimal moves
for a player by assuming that another player is also playing optimally.

This algorithm is based on two players, one is called MAX, and the other is called the MIN.

Following terminologies that are used in the Minimax Algorithm:

o Game tree: A tree structure with all possible moves.

o Initial State: The initial state of the board.

o Terminal State: Position of the board where the game finishes.

o Utility Function: The function that assigns a numeric value for the outcome of the game.

27) What is game theory? How is it important in AI?

Game theory is the logical and scientific study that forms a model of the possible interactions between two or more rational players.
Here rational means that each player thinks that others are just as rational and have the same level of knowledge and
understanding. In the game theory, players deal with the given set of options in a multi-agent situation, it means the choice of one
player affects the choice of the other or opponent players.

Game theory and AI are much related and useful to each other. In AI, the game theory is widely used to enable some of the key
capabilities required in the multi-agent environment, in which multiple agents try to interact with each other to achieve a goal.

Different popular games such as Poker, Chess, etc., are the logical games with the specified rules. To play these games online or
digitally, such as on Mobile, laptop, etc., one has to create algorithms for such games. And these algorithms are applied with the
help of artificial intelligence.

28) What are some misconceptions about AI?

There are lots of misconceptions about artificial intelligence since starting its evolution. Some of these misconceptions are given
below:

o AI does not require humans: The first misconception about AI is that it does not require human. But in reality, each AI-
based system is somewhere dependent on humans and will remain. Such as it requires human gathered data to learn about
the data.

o AI is dangerous for humans: AI is not inherently dangerous for humans, and still, it has not reached the super AI or
strong AI, which is more intelligent than humans. Any powerful technology cannot be harmful if it is not misused.

o AI has reached its peak stage: Still, we are so far away from the peak stage of the AI. It will take a very long journey to
reach its peak.

o AI will take your job: It is one of the biggest confusions that AI will take most of the jobs, but in reality, it is giving us
more opportunities for new jobs.

o AI is new technology: Although some people think that it is a new technology, this technology actually first thought in
the year 1840 through an English newspaper.

29) What are the eigenvalues and eigenvectors?

Eigenvectors and eigenvalues are the two main concepts of Linear algebra.

Eigenvectors are unit vectors that have a magnitude equal to 1.0.

Eigenvalues are the coefficients that are applied to the eigenvectors, or these are the magnitude by which the eigenvector is scaled.

CS3491 Artificial Intelligence and Machine Learning Page 53


DEPARTMENT OF ECE

30) What is an Artificial neural network? Name some commonly used Artificial Neural networks.

Artificial neural networks are the statistical model inspired by the functioning of human brain cells called neurons. These neural
networks include various AI technologies such as deep learning and machine learning.

An Artificial neural network or ANN consists of multiple layers, including the Input layer, Output Layer, and hidden layers.

ANN, with the help of various deep learning techniques, is the AI tools to solve various complex problems like pattern recognition,
facial recognition, and so on.

Some commonly used Artificial neural networks:

o Feedforward Neural Network

o Convolutional Neural Network

o Recurrent Neural Network

o Autoencoders

31) Give a brief introduction of partial, alternate, artificial, and compound keys?

Partial Keys: A set of attributes that uniquely identifies weak entities, which are related to the same owner entity.

Alternate Keys: All candidate keys except the primary key are known as alternate keys.

Compound Key: It has multiple fields that enable the user to uniquely recognize a specific record.

Artificial Key: It is the extra attribute added to the table when there are no stands alone or compounds key is available. It is
created by assigning a number to each record in the table.

32) What is a Chatbot?

A chatbot is Artificial intelligence software or agent that can simulate a conversation with humans or users using Natural language
processing. The conversation can be achieved through an application, website, or messaging apps. These chatbots are also called as
the digital assistants and can interact with humans in the form of text or through voice.

The AI chatbots are broadly used in most businesses to provide 24*7 virtual customer support to their customers, such as HDFC Eva
chatbot, Vainubot, etc.

33) What is knowledge representation in AI?

Knowledge representation is the part of AI, which is concerned with the thinking of AI agents. It is used to represent the knowledge
about the real world to the AI agents so that they can understand and utilize this information for solving the complex problems in AI.

Following elements of Knowledge that are represented to the agent in the AI system:

o Objects

o Events

o Performance

o Meta-Knowledge

o Facts

o Knowledge-base

CS3491 Artificial Intelligence and Machine Learning Page 54


DEPARTMENT OF ECE

34) What are the various techniques of knowledge representation in AI?

Knowledge representation techniques are given below:

o Logical Representation

o Semantic Network Representation

o Frame Representation

o Production Rules

35) Which programming language is not generally used in AI, and why?

Perl Programming language is not commonly used language for AI, as it is the scripting language.

36) What is reinforcement learning?

Reinforcement learning is a type of machine learning. In this, an agent interacts with its environment by producing actions, and
learn with the help of feedback. The feedback is given to the agent in the form of rewards, such as for each good action, he gets a
positive reward, and for each bad action, he gets a negative reward. There is no any labeled data or supervision is provided to the
agent. In RL, the agent continuously does three things(performing actions, changing state, and getting the feedback) to explore the
environment.

The popular reinforcement learning algorithms are:

o Q-Learning

o SARSA(State Action Reward State Action)

o Deep Q Neural Network

37) How does RL work?

The working of reinforcement learning can be understood by the below diagram:

The RL-based system mainly consists of the following components:

o Environment: The environment is the surrounding of the agent, where he needs to explore and act upon.

CS3491 Artificial Intelligence and Machine Learning Page 55


DEPARTMENT OF ECE

o Agent: The agent is the AI program that has sensors and actuators and the ability to perceive the environment.

o State: It is the situation that is returned by the environment to the agent.

o Reward: The feedback received to the agent after doing each action.

In RL, the agent interacts with the environment in order to explore it by doing some actions. On each action, the state of agent gets
changed or sometimes remains the same, and based on the type of action, and he gets a reward. The reward is feedback, which
may be negative or positive based on the action.

The goal of the agent is to maximize the positive reward and to achieve the goal of the problem.

38) What are the different areas where AI has a great impact?

Following are some areas where AI has a great impact:

o Autonomous Transportation

o Education-system powered by AI.

o Healthcare

o Predictive Policing

o Space Exploration

o Entertainment, etc.

39) What are the different software platforms for AI development?

a. Google Cloud AI platform

b. Microsoft Azure AI platform

c. IBM Watson

d. TensorFlow

e. Infosys Nia

f. Rainbird

g. Dialogflow

40) Kindly explain different ways to evaluate the performance of the ML model.

Some popular ways to evaluate the performance of the ML model are:

o Confusion Matrix: It is N*N table with different sets of value that is used to determine the performance of the
classification model in machine learning.

o F1 score: It is the harmonic mean of precision and recall, which is used as one of the best metrics to evaluate the ML
model.

o Gain and lift charts: Gain & Lift charts are used to determine the rank ordering of the probabilities.

o AUC-ROC curve: The AUC-ROC is another performance metric. The ROC is the plot between the sensitivity.

o Gini Coefficient: It is used in the classification problems, also known as the Gini Index. It determines the inequality
between the values of variables. The high value of the Gini represents a good model.

o Root mean squared error: It is one of the most popular metrics used for the evaluation of the regression model. It works
by assuming that errors are unbiased and have a normal distribution.

o Cross-Validation: It is another popular technique for evaluating the performance of the machine learning model. In this,
the models are trained on subsets of the input data and evaluated on the complementary subset of the data.

CS3491 Artificial Intelligence and Machine Learning Page 56


DEPARTMENT OF ECE

41) Explain rational agents and rationality?

A rational agent is an agent that has clear preferences, model uncertainty, and that performs the right actions always. A rational
agent is able to take the best possible action in any situation.

Rationality is a status of being reasonable and sensible with a good sense of judgment.

42) What is tensor flow, and how it is used in AI?

Tensor flow is the open-source library platform developed by the Google Brain team. It is a math library used for several machine
learning applications. With the help of tensor flow, we can easily train and deploy the machine learning models in the cloud.

43) Which algorithm is used by Facebook for face recognition? Explain its working.

Facebook uses the DeepFace tool that uses the deep learning algorithms for the face verification that allows the photo tag
suggestions to you when you upload a photo on Facebook. The deep face identifies the faces in the digital images using neural
network models. The working of DeepFace is given in below steps:

o It first scans the uploaded images. It makes the 3-D model of the image, and then rotate that image into different angles.

o After that, it starts matching. To match that image, it uses a neural network model to determine the high-level similarities
between other photos of a person. It checks for the different features such as the distance between the eyes, the shape of
the nose, eyes color, etc.

o Then it does the recursive checking for 68 landmark testing, as each human face consists of 68 specific facial points.

o After mapping, it encodes the image and searches for the information of that person.

44) What is a market-basket analysis?

The market-basket analysis is a popular technique to find the associations between the items. It is frequently used by big retailers in
order to get maximum profit. In this approach, we need to find combinations of items that are frequently bought together.

For example, if a person buys bread, there are most of the chances that he will buy butter also. Hence, understanding such
correlations can help retailers to grow their business by providing relevant offers to their customers.

45) How can AI be used in fraud detection?

The artificial intelligence can be broadly helpful in fraud detection using different machine learning algorithms, such as supervised
and unsupervised learning algorithms. The rule-based algorithms of Machine learning helps to analyze the patterns for any
transaction and block the fraudulent transactions.

Below are the steps used in fraud detection using machine learning:

o Data extraction: The first step is data extraction. Data is gathered through a survey or with the help of web scraping
tools. The data collection depends on the type of model, and we want to create. It generally includes the transaction
details, personal details, shopping, etc.

o Data Cleaning: The irrelevant or redundant data is removed in this step. The inconsistency present in the data may lead to
wrong predictions.

o Data exploration & analysis: This is one of the most crucial steps in which we need to find out the relation between
different predictor variables.

o Building Models: Now, the final step is to build the model using different machine learning algorithms depending on the
business requirement. Such as Regression or classification.

46) Give the steps for A* algorithm?

CS3491 Artificial Intelligence and Machine Learning Page 57


DEPARTMENT OF ECE

A* algorithm is the popular form of the Best first search. It tries to find the shortest path using the heuristic function with the cost
function to reach the end node. The steps for A* algorithms are given below:

Step 1: Put the first node in the OPEN list.

Step 2: Check if the OPEN list is empty or not; if the list is empty, then return failure and stops.

Step 3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if node n is goal node then
return success and stop, otherwise

Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each successor n', check whether n' is
already in the OPEN or CLOSED list; if not, then compute evaluation function for n' and place into Open list.

Step 5: Else if node n' is already in OPEN and CLOSED list, then it should be attached to the back pointer, which reflects the lowest
g(n') value.

Step 6: Return to Step 2.

47) What is the inference engine, and why it is used in AI?

In artificial intelligence, the inference engine is the part of an intelligent system that derives new information from the knowledge
base by applying some logical rules.

It mainly works in two modes:

o Backward Chaining: It begins with the goal and proceeds backward to deduce the facts that support the goal.

o Forward Chaining: It starts with known facts, and asserts new facts.

48) What do you understand by the fuzzy logic?

Fuzzy logic is a method of reasoning applied to the AI, which resembles human reasoning. Here the word "fuzzy" defines things that
are not clear, it means the situations where it is difficult to decide if the state is True or False. It involves all the possibilities that
occur between Yes and NO.

The below diagram shows the difference between fuzzy logic and Boolean logic

CS3491 Artificial Intelligence and Machine Learning Page 58


DEPARTMENT OF ECE

Since it resembles human reasoning, hence it can be used in neural networks.

49) What is a Bayesian network, and why is it important in AI?

Bayesian networks are the graphical models that are used to show the probabilistic relationship between a set of variables. It is a
directed cycle graph that contains multiple edges, and each edge represents a conditional dependency.

Bayesian networks are probabilistic, because these networks are built from a probability distribution, and also use probability
theory for prediction and anomaly detection. It is important in AI as it is based on Bayes theorem and can be used to answer the
probabilistic questions.

50) What is a heuristic function, and where is it used?

The heuristic function is used in Informed Search, and it finds the most promising path. It takes the current state of the agent as its
input and produces the estimation of how close the agent is from the goal. The heuristic method, however, might not always give
the best solution, but it guaranteed to find a good solution in a reasonable time. Heuristic function estimates how close a state is to
the goal. It is represented by h(n), and it calculates the cost of an optimal path between the pair of states. The value of the heuristic
function is always positive.Admissibility of the heuristic function is given as:

h(n) <= h*(n)

Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should be less than or equal to the estimated cost.

CS3491 Artificial Intelligence and Machine Learning Page 59

You might also like