Posts

Showing posts from October, 2024

Lab 1 ai

 Dfs.pl s[a,b). s(a,c). s(b,d). s(b,e). s(c,f). s(c,g). s(d,h). s(e,i). s(e,j). s(f,k). goal(f). goal(j). solve(Start,Solution):- breadthfirst([[Start]],Solution). breadthfirst([[Node | Path] ].[Node|Path]]:- goal(Node). breadthfirst([Path | Paths] Solution):- extend(Path,NewPaths), write(NewPaths), nl, conc(Paths,NewPaths, Paths1), breadthfirst(Paths1,Solution). extend([NodePath],NewPaths):- bagof([NewNode, Node | Path),(s(Node, NewNode),not(member(NewNode, [Node | Path]))),NewPaths),!. extend([]). conc([],L,L). Scanned with OKEN Scanner bfs.pl s(a,b). s(a,c). s(b,d). s(b,e). s(c,f). s(c,g). / s(d,h). s(e,i). s(e,j). s(f,k). goal(f). goal(j). member(X,[X|_]). member(X,_|Tail]):- member(X,Tail). solve(Node,Solution):- depthfirst([],Node,Solution). depthfirst(Path, Node,[Node | Path]):- goal(Node). depthfirst(Path,Node,Sol):- s(Node,Node1), not(member(Node1,Path)), depthfirst([Node | Path], Node1,Sol). Scanned with OKEN Scanner conc([X/L1],L2,[X|L3]):- write('conc'), write(X), w...

Lab 1

 Import pandas as pd Import numpy as np #to read the data in the csv file Data = pd.read_csv(“data.csv”) Print(data,”n”) #making an array of all the attributes D = np.array(data)[:,:-1] Print(“n The attributes are: “,d) #segragating the target that has positive and negative examples Target = np.array(data)[:,-1] Print(“n The target is: “,target) #training function to implement find-s algorithm Def train(c,t): For i, val in enumerate(t): If val == “Yes”: Specific_hypothesis = c[i].copy() Break For i, val in enumerate(c): If t[i] == “Yes”: For x in range(len(specific_hypothesis)): If val[x] != specific_hypothesis[x]: Specific_hypothesis[x] = ‘?’ Else: Pass Return specific_hypothesis #obtaining the final hypothesis Print(“n The final hypothesis is:”,train(d,target))