ST.
ANDREWS INSTITUTE
OF TECHNOLOGY & MANAGEMENT
Gurgaon Delhi (NCR)
Approved by AICTE, Govt. of India, New Delhi Affiliated to Maharshi
Dayanand University
‘A’ Grade State University, accredited by NAAC
Session: 2025-2026
Bachelor of Technology (Data Science)
PRACTICAL FILE
ARTIFICIAL & COMPUTATIONAL INTELLIGENCE LAB
COURSE CODE: LC-DS-347G
Submitted To : Submitted by:
Keerti Maithil
Name : NIKET
Sem : Vth
Roll No. : 23DS016
St. Andrews Institute of Technology &
Management, Gurugram
Department of……………………………
Practical Lab Evaluation Sheet
Practical Viva- Attendance Practical Overall Remarks
[Link]. Program Date CO Performed Voice (05 File (05) (25) &
(10) (05) Signature
1 Toy Problem 4 Sept CO 3
Implementation 2025
2 Simple Agent 4 Sept CO 1
Program (Vacuum 2025
Cleaner)
3 Constraint Satisfaction 11 Sept CO 4
(N-Queens) 2025
4 DFS & BFS 11 Sept CO 3
2025
5 A*Search (Shortest 18 Sept CO 3
Path) 2025
6 Minimax (Tic- Tac- CO 3
Toe Simplified) 18 Sept
2025
7 Unification Example 25 Sept CO 4
2025
8 Knowledge 25 Sept CO 3
Representation 2025
(Semantic Network)
9 Uncertain Reasoning 30 Oct CO 3
(Fuzzy Logic) 2025
10 Learning Algorithm 30 Oct CO 4
(Perceptron) 2025
11 Deep Learning 30 CO 2
(Keras MLP) 2025
12 Neural Tool – Logic 6 Nov CO4
Gates 2025
13 Pattern Classification 6 Nov CO4
& Clustering 2025
14 Fuzzy Controller 13 Nov CO4
Example 2025
15 Genetic Algorithm 13 Nov CO4
(Simple 2025
Optimization)
Average Marks
Approved & Verified by (Faculty Name)
(Faculty Sign.)
PROGRAM NO. - 1
AIM: A toy problem is a simplified, small-scale problem used to practice modelling, training,
and evaluation. Here we implement a tiny logistic regression classifier to predict pass/fail from
two marks.
SOURCE CODE:
import pandas as pd
from sklearn.linear_model import LogisticRegression
x = [[60, 75], [45, 50], [80, 90], [30, 40], [70, 65]]
y = [1, 0, 1, 0, 1] # 1 = Pass, 0 = Fail
model = LogisticRegression().fit(X, y)
print("Predict [50, 60]:", [Link]([[50, 60]]))
OUTPUT:
PROGRAM NO. - 2
AIM: Agent programs perceive their environment and act. A simple reflex agent for a two-room vacuum
cleans when it senses dirt.
SOURCE CODE:
rooms = {'A':'Dirty','B':'Clean'}
agent_pos = 'A'
print('Initial:', rooms, 'Agent at', agent_pos)
if rooms[agent_pos]=='Dirty':
rooms[agent_pos]='Clean'
print("Cleaned Room", agent_pos)
agent_pos='B'
print("Agent moved to", agent_pos)
print('Final:', rooms)
OUTPUT:
PROGRAM NO-3
AIM: CSPs have variables, domains and constraints. N-Queens places N queens on N×N board so none
attack each other. Backtracking solves it.
SOURCE CODE:
def is_safe(board, row, col):
for i in range(col):
if board[i]==row or abs(board[i]-row)==abs(i-col): return False
return True
def solve_nq(n, col=0, board=[]):
if col==n:
print('Solution (row indices per column):', board)
return
for row in range(n):
if is_safe(board,row,col):
solve_nq(n,col+1,board+[row])
solve_nq(4)
OUTPUT:
PROGRAM NO-4
AIM: DFS explores depth-first (stack/recursion), BFS explores level-by-level (queue). We'll traverse
a small directed graph to compare.
SOURCE CODE:
graph = {'A':['B','C'], 'B':['D'], 'C':['E'], 'D':[], 'E':[]}
def dfs(v, visited=None):
if visited is None: visited=set()
if v not in visited:
print(v, end=' ')
[Link](v)
for n in graph[v]: dfs(n, visited)
def bfs(start):
q=[start]; visited=set()
while q:
v=[Link](0)
if v not in visited:
print(v, end=' ')
[Link](v); [Link](graph[v])
print("DFS:", end=' '); dfs('A')
print("\nBFS:", end=' '); bfs('A')
OUTPUT:
PROGRAM NO-5
AIM: A* uses actual cost + heuristic to guide search. Here we simulate a small graph with a
heuristic and use a priority queue.
SOURCE CODE:
from queue import PriorityQueue
graph = {'A':{'B':1,'C':3},'B':{'D':3},'C':{'D':1},'D':{}}
h = {'A':3,'B':2,'C':1,'D':0}
def astar(start,goal):
q = PriorityQueue(); [Link]((0,start,'start'))
visited=set()
while not [Link]():
cost,node,_ = [Link]()
if node==goal:
print("Reached",goal); return
if node in visited: continue
[Link](node)
for n,c in graph[node].items():
[Link]((cost+c+h[n], n, node))
print('No path')
astar('A','D')
OUTPUT:
PROGRAM NO-6
AIM: Minimax models adversarial games. This tiny demo computes minimax scores for a
small(depth-limited) game tree.
SOURCE CODE:
def minimax(depth,isMax):
if depth==0: return 1 if isMax else -1
scores=[]
for i in range(2): [Link](minimax(depth-1, not isMax))
return max(scores) if isMax else min(scores)
print("Score:", minimax(3, True))
OUTPUT:
PROGRAM NO-7
AIM : Unification finds substitutions making logical expressions identical. This simple example
handles variable-to-constant binding.
SOURCE CODE:
def unify(x, y):
if x == y: return {}
if isinstance(x,str) and [Link](): return {x:y}
if isinstance(y,str) and [Link](): return {y:x}
return None
print(unify('x', 'John'))
print(unify('John','John'))
print(unify('X','Y')) # note: capitalized treated as constants in this simple demo
OUTPUT :
PROGRAM NO-8
AIM: Semantic networks store entities and relations (is-a, has, can). Useful for inheritance and
simple reasoning.
SOURCE CODE:
semantic_net = {
'bird': {'can':'fly', 'has':'wings'},
'penguin': {'is_a':'bird', 'can':'swim'}
}
print("Penguin can:", semantic_net['penguin']['can'])
print("Bird has:", semantic_net['bird']['has'])
OUTPUT:
PROGRAM NO-9
AIM : Fuzzy sets model degrees of membership. We use triangular membership functions to show
fuzziness of 'cold' and 'hot'.
SOURCE CODE:
import numpy as np
import skfuzzy as fuzz
x_temp = [Link](0, 41, 1)
cold = [Link](x_temp, [0, 0, 20])
hot = [Link](x_temp, [20, 40, 40])
print("Cold(10°C):", fuzz.interp_membership(x_temp,
cold, 10))
print("Hot(30°C):", fuzz.interp_membership(x_temp,
hot, 30))
OUTPUT:
PROGRAM NO-10
AIM: Perceptron is a simple linear classifier trained with a weight update rule. It can learn linearly
separable functions (e.g., AND).
SOURCE CODE:
import numpy as np
X = [Link]([[0,0],[0,1],[1,0],[1,1]])
y = [Link]([0,0,0,1])
w = [Link](2); b = 0; lr=0.1
for epoch in range(20):
for i in range(len(X)):
y_pred = 1 if [Link](X[i],w)+b>0 else 0
w += lr*(y[i]-y_pred)*X[i]
b += lr*(y[i]-y_pred)
print("Weights:", w, "Bias:", b)
print('Predictions:')
for x in X: print(x, '->', 1 if [Link](x,w)+b>0 else 0)
OUTPUT:
PROGRAM NO-11
AIM : Multi-layer perceptrons (MLPs) with non-linear activations can solve non-linearly separable
problems (e.g., XOR). We'll train a small network with Keras.
SOURCE CODE:
from [Link] import Sequential
from [Link] import Dense
import numpy as np
X = [Link]([[0,0],[0,1],[1,0],[1,1]])
y = [Link]([[0],[1],[1],[0]])
model = Sequential([
Dense(4, input_dim=2, activation='relu'),
Dense(1, activation='sigmoid')
])
[Link](optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
[Link](X, y, epochs=200, verbose=0)
print([Link](X))
OUTPUT:
PROGRAM NO-12
AIM: Single-layer perceptrons implement linearly separable gates like AND/OR by choosing
appropriate weights and bias.
SOURCE CODE:
def perceptron(x1,x2,w1,w2,b):
return 1 if (x1*w1+x2*w2+b)>0 else 0
print("AND (1,1):", perceptron(1,1,1,1,-1.5))
print("OR (0,1):", perceptron(0,1,1,1,-0.5))
print("NAND(1,1):", perceptron(1,1,-2,-2,3))
OUTPUT:
PROGRAM NO-13
AIM: K-means groups similar data points into clusters. This demo shows clustering on a small
2D dataset.
SOURCE CODE:
from [Link] import KMeans
import numpy as np
X = [Link]([[1,2],[1,4],[5,8],[6,8]])
kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
print("Cluster centers:\n", kmeans.cluster_centers_)
print('Labels:', kmeans.labels_)
OUTPUT:
PROGRAM NO-14
AIM: A fuzzy controller maps linguistic inputs to outputs using fuzzy sets and rules. Here we
only show fuzzification membership values.
SOURCE CODE:
import numpy as np
import skfuzzy as fuzz
temp = [Link](0, 41, 1)
cold = [Link](temp, [0, 0, 20])
hot = [Link](temp, [20, 40, 40])
input_temp = 25
cold_level = fuzz.interp_membership(temp, cold, input_temp)
hot_level = fuzz.interp_membership(temp, hot, input_temp)
print("For input temp=25 -> Cold level:", cold_level, ", Hot level:", hot_level)
OUTPUT:
PROGRAM NO-15
AIM : Genetic algorithms search via population evolution: selection, crossover, mutation. We'll
optimize a simple function using a tiny GA.
SOURCE CODE:
import random, math
def fitness(x): return x*[Link](10*[Link]*x)+1
pop = [[Link](0,1) for _ in range(6)]
for gen in range(20):
pop = sorted(pop, key=fitness, reverse=True)
new = []
# elitism keep top2
[Link](pop[:2])
while len(new)<6:
p1,p2 = [Link](pop[:3],2)
c=(p1+p2)/2 + [Link](-0.05,0.05)
c = max(0,min(1,c))
if [Link]()<0.1: # mutation
c += [Link](-0.02,0.02)
c = max(0,min(1,c))
[Link](c)
pop = new
best = max(pop, key=fitness)
print('Best x:', best, 'Fitness:', fitness(best))
OUTPUT: