Professional Documents
Culture Documents
lab manual
lab manual
graph = {
'5': ['3', '7'],
'3': ['2', '4'],
'7': ['10'],
'2': [],
'4': ['10'],
'10': ['1', '6'],
'1': ['2', '7'],
'8': ['6', '7'],
'9': ['11', '22'],
'11': [],
'12': ['17'],
'17': [],
'22': ['30'],
'30': ['6'],
'6': ['11', '12']
}
while queue:
m = queue.pop(0)
print(m, end=" ")
def bfs_traversal(graph):
visited = []
for node in graph:
if node not in visited:
bfs(visited, graph, node)
OUTPUT:
CODE:
graph ={
'5':['3','7'],
'3':['2','4'],
'7':['10'],
'2':[],
'4':['10'],
'10':['2','4'],
}
visited = []
queue = []
def bfs(visited,graph,node):
visited.append(node)
queue.append(node)
while queue:
m = queue.pop(0)
print(m,end=" ")
OUTPUT:
CODE:
graph ={
'5':['3','7'],
'3':['2','4'],
'7':['10'],
'2':[],
'4':['10'],
'10':['2','4'],
}
visited = []
queue = []
def bfs(visited,graph,node):
visited.append(node)
queue.append(node)
while queue:
m = queue.pop(0)
print(m,end=" ")
OUTPUT:
CODE:
import random
import itertools
POPULATION_SIZE = 50
NUM_GENERATIONS = 25
total_distance = 0
#will add all
distances
for i in range(len(path) - 1):
total_distance += distances[(path[i], path[i+1])]
#this use to return to starting city
total_distance += distances[(path[-1], path[0])]
return total_distance
#here child include the slice of one parent means some genes of one
parents
#and those genes of second parent which are not included in first parent
child1 = parent1[:crossover_point] + [gene for gene in parent2 if gene not
in parent1[:crossover_point]]
child2 = parent2[:crossover_point] + [gene for gene in parent1 if gene not
in parent2[:crossover_point]]
return child1, child2
url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-
temperatures.csv'
data = pd.read_csv(url)
print(data.head())
data['Year'] = data['Date'].dt.year
data['Month'] = data['Date'].dt.month
data['Day'] = data['Date'].dt.day
plt.figure(figsize=(10, 6))
sns.scatterplot(x=y_test, y=y_pred)
plt.xlabel('Actual Temperature')
plt.ylabel('Predicted Temperature')
plt.title('Actual vs Predicted Temperature')
plt.show()
OUTPUT:
This code analyzes MRI scans to determine whether the brain contains
a tumor or not.
Directory Strucure:
1: D:\AI LAB\tasks\brainTumor\no
2: D:\AI LAB\tasks\brainTumor\yes
NO samples:
YES Samples:
CODE:
import cv2
import os
import pandas as pd
import numpy as np
import random
from skimage.feature import hog
from sklearn import svm
import os
import cv2
from skimage.feature import hog
i=0
categories = []
imgs_names = []
features = []
if not os.path.exists(subdir_path):
print(f"Directory does not exist: {subdir_path}")
continue
len(categories)
len(features)
# Make predictions
y_pred = clf.predict(X_test)
if category=='no':
print("No evidence of tumor identified on MRI scan")
else:
print("Tumor is identified on MRI scan")
CODE:
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
import matplotlib.pyplot as plt
df = pd.DataFrame(data)
OUTPUT:
TASK#5: