├── 8puzzle ├── 8puzzle.py ├── gbfs.py ├── main.py └── state.py ├── A STAR ├── Astar.py ├── astar graph.png └── astarshort.ipynb ├── NLP ├── .ipynb_checkpoints │ ├── NLPtask-checkpoint.ipynb │ ├── Untitled-checkpoint.ipynb │ ├── nlp-checkpoint.ipynb │ └── nlpspacyone-checkpoint.ipynb ├── NLP.ipynb ├── NLPtask.ipynb └── nlpspacyone.ipynb ├── README.md ├── case studies projects ├── expertsys │ ├── Disease descriptions │ │ ├── Alzheimers.txt │ │ ├── Arthritis.txt │ │ ├── Asthma.txt │ │ ├── Coronavirus.txt │ │ ├── Diabetes.txt │ │ ├── Epilepsy.txt │ │ ├── Glaucoma.txt │ │ ├── Heart Disease.txt │ │ ├── Heat Stroke.txt │ │ ├── Hyperthyroidism.txt │ │ ├── Hypothermia.txt │ │ ├── Jaundice.txt │ │ ├── Sinusitis.txt │ │ └── Tuberculosis.txt │ ├── Disease symptoms │ │ ├── Alzheimers.txt │ │ ├── Arthritis.txt │ │ ├── Asthma.txt │ │ ├── Coronavirus.txt │ │ ├── Diabetes.txt │ │ ├── Epilepsy.txt │ │ ├── Glaucoma.txt │ │ ├── Heart Disease.txt │ │ ├── Heat Stroke.txt │ │ ├── Hyperthyroidism.txt │ │ ├── Hypothermia.txt │ │ ├── Jaundice.txt │ │ ├── Sinusitis.txt │ │ └── Tuberculosis.txt │ ├── Disease treatments │ │ ├── Alzheimers.txt │ │ ├── Arthritis.txt │ │ ├── Asthma.txt │ │ ├── Coronavirus.txt │ │ ├── Diabetes.txt │ │ ├── Epilepsy.txt │ │ ├── Glaucoma.txt │ │ ├── Heart Disease.txt │ │ ├── Heat Stroke.txt │ │ ├── Hyperthyroidism.txt │ │ ├── Hypothermia.txt │ │ ├── Jaundice.txt │ │ ├── Sinusitis.txt │ │ └── Tuberculosis.txt │ ├── diseases.txt │ ├── greetings.py │ ├── main.py │ └── requirements.txt ├── gamebot tic tac toe │ ├── GamebotTicTacToe.ipynb │ ├── TicTacToe.py │ ├── interactivegame.py │ └── readme.txt └── textclassification │ └── textclassification.ipynb ├── classifierss ├── ML │ └── ML notes │ │ └── Unit-4MLl.pptx └── programs │ ├── .ipynb_checkpoints │ ├── MLPClassifier-checkpoint.ipynb │ ├── MLPClassifierSMOTE-checkpoint.ipynb │ └── Untitled-checkpoint.ipynb │ ├── HR_comma_sep.csv │ ├── MLPClassifier.ipynb │ ├── MLPClassifierSMOTE.ipynb │ └── decisiontreesmall.ipynb ├── decisiontree ├── diabetes │ ├── .ipynb_checkpoints │ │ ├── diabetesclassf-checkpoint.ipynb │ │ └── diabetesentropyclassf-checkpoint.ipynb │ ├── diabetes.csv │ ├── diabetesclassf.ipynb │ └── diabetesentropyclassf.ipynb ├── iris │ ├── decisiontreesmall.ipynb │ └── iris.csv ├── studentt │ ├── decisiontreesmallstudent.ipynb │ └── student_dataset.csv └── weightheight │ ├── decisiontreesmallweight.ipynb │ └── weight_height_dataset.csv ├── hangman game └── manual │ ├── __pycache__ │ ├── hangman_art.cpython-312.pyc │ └── hangman_words.cpython-312.pyc │ ├── hangman_art.py │ ├── hangman_words.py │ └── hangmanv5.py ├── nqueens └── queen.py ├── numpy ├── .ipynb_checkpoints │ └── numpyml-checkpoint.ipynb └── numpyml.ipynb ├── pandas ├── pandas_d │ ├── dataset │ │ ├── car-sales.csv │ │ └── export_cars.csv │ └── pandasnotebook │ │ └── pandasfk.ipynb └── pandasprogram.ipynb ├── prolog ├── cartypes.pl ├── cartypes.pl~ ├── familytree.pl ├── familytree.pl~ ├── girlstudents.pl ├── girlstudents.pl~ ├── outputcartypes.png ├── outputgirlstudents.png ├── prolog.pptx ├── simplefacts.pl └── simplefacts.pl~ ├── pythonbasics ├── List.ipynb └── ai lab basics.ipynb ├── students_contributions ├── 1.png ├── 2.png ├── 3.png ├── 8puzzle (2).py ├── 8puzzle.py ├── A star.ipynb ├── AI_NUMPY.ipynb ├── Astar.ipynb ├── MLP Classifier.py ├── MLPClassifier.py ├── Nqueens.py ├── Pandas-Operations.py ├── Python Programming Intro.ipynb ├── TicTacToe.py ├── Waterjug_auto (2).py ├── Waterjug_auto (3).py ├── Waterjug_auto.py ├── astarshort.ipynb ├── bfs.py ├── decision tree.py ├── decision_tree.py.py ├── diabetes.csv ├── gbfs.py ├── hangman_1.py ├── hangmanv1.py ├── hangmanv5.py ├── nlp.py ├── numpy.py ├── pandas.py ├── prolog_familytree.py ├── queen (1).py ├── queen (2).py ├── queen.py ├── queens.py └── waterjugmanual.py ├── uninformed search ├── bfs.py └── dfs.py └── waterjug code ├── waterjbfs.py ├── waterjug.pptx └── waterjugmanual.py /8puzzle/8puzzle.py: -------------------------------------------------------------------------------- 1 | from queue import PriorityQueue 2 | 3 | # Define the goal state for the 8-puzzle 4 | #GOAL_STATE = (1, 2, 3, 4, 5, 6, 7, 8, 0) 5 | GOAL_STATE = (1, 2, 3, 8,0,4,7,6,5) 6 | 7 | class PuzzleState: 8 | def __init__(self, board, empty_index, path_cost=0, parent=None): 9 | self.board = board 10 | self.empty_index = empty_index # Index of the empty space (0) 11 | self.path_cost = path_cost 12 | self.parent = parent 13 | 14 | def is_goal(self): 15 | return self.board == GOAL_STATE 16 | 17 | def generate_children(self): 18 | children = [] 19 | row, col = divmod(self.empty_index, 3) 20 | directions = { 21 | "up": (-1, 0), 22 | "down": (1, 0), 23 | "left": (0, -1), 24 | "right": (0, 1) 25 | } 26 | 27 | for direction, (dr, dc) in directions.items(): 28 | new_row, new_col = row + dr, col + dc 29 | if 0 <= new_row < 3 and 0 <= new_col < 3: 30 | new_index = new_row * 3 + new_col 31 | new_board = list(self.board) 32 | new_board[self.empty_index], new_board[new_index] = new_board[new_index], new_board[self.empty_index] 33 | children.append(PuzzleState(tuple(new_board), new_index, self.path_cost + 1, self)) 34 | 35 | return children 36 | 37 | def heuristic(self): 38 | distance = 0 39 | for index, value in enumerate(self.board): 40 | if value != 0: 41 | goal_index = value - 1 42 | goal_row, goal_col = divmod(goal_index, 3) 43 | current_row, current_col = divmod(index, 3) 44 | distance += abs(goal_row - current_row) + abs(goal_col - current_col) 45 | return distance 46 | 47 | def __lt__(self, other): 48 | return self.heuristic() < other.heuristic() 49 | 50 | def greedy_best_first_search(initial_board): 51 | initial_index = initial_board.index(0) 52 | initial_state = PuzzleState(tuple(initial_board), initial_index) 53 | 54 | if initial_state.is_goal(): 55 | return initial_state 56 | 57 | frontier = PriorityQueue() 58 | frontier.put(initial_state) 59 | explored = set() 60 | 61 | while not frontier.empty(): 62 | current_state = frontier.get() 63 | 64 | if current_state.is_goal(): 65 | return current_state 66 | 67 | explored.add(current_state.board) 68 | 69 | for child in current_state.generate_children(): 70 | if child.board not in explored: 71 | frontier.put(child) 72 | 73 | return None # No solution found 74 | 75 | def print_solution(solution): 76 | path = [] 77 | current_state = solution 78 | while current_state: 79 | path.append(current_state.board) 80 | current_state = current_state.parent 81 | for state in reversed(path): 82 | print(state) 83 | 84 | # Example usage 85 | initial_board = [2,8,3,1,6,4,7,0,5] 86 | # Initial configuration initial_board = [1, 2, 3, 4, 5, 6, 0, 7, 8] 87 | solution = greedy_best_first_search(initial_board) 88 | 89 | if solution: 90 | print("Solution found:") 91 | print_solution(solution) 92 | else: 93 | print("No solution found.") 94 | -------------------------------------------------------------------------------- /8puzzle/gbfs.py: -------------------------------------------------------------------------------- 1 | from state import State 2 | from queue import PriorityQueue 3 | def Greedy(given_state , n): 4 | frontier = PriorityQueue() 5 | explored = [] 6 | counter = 0 7 | root = State(given_state, None, None, 0, 0) 8 | #root.evaluation() 9 | evaluation = root.Misplaced_Tiles(n) #we can use Misplaced_Tiles() instead. 10 | frontier.put((evaluation, counter, root)) #based on greedy evaluation 11 | 12 | while not frontier.empty(): 13 | current_node = frontier.get() 14 | current_node = current_node[2] 15 | explored.append(current_node.state) 16 | 17 | if current_node.test(): 18 | return current_node.solution(), len(explored) 19 | 20 | children = current_node.expand(n) 21 | for child in children: 22 | if child.state not in explored: 23 | counter += 1 24 | evaluation = child.Misplaced_Tiles(n) #we can use Misplaced_Tiles() instead. 25 | frontier.put((evaluation, counter, child)) #based on greedy evaluation 26 | return 27 | -------------------------------------------------------------------------------- /8puzzle/main.py: -------------------------------------------------------------------------------- 1 | from gbfs import Greedy 2 | 3 | #initial state 4 | n = int(input("Enter n\n")) 5 | print("Enter your" ,n,"*",n, "puzzle") 6 | root = [] 7 | for i in range(0,n*n): 8 | p = int(input()) 9 | root.append(p) 10 | 11 | print("The given state is:", root) 12 | 13 | 14 | #count the number of inversions 15 | def inv_num(puzzle): 16 | inv = 0 17 | for i in range(len(puzzle)-1): 18 | for j in range(i+1 , len(puzzle)): 19 | if (( puzzle[i] > puzzle[j]) and puzzle[i] and puzzle[j]): 20 | inv += 1 21 | return inv 22 | 23 | def solvable(puzzle): #check if initial state puzzle is solvable: number of inversions should be even. 24 | inv_counter = inv_num(puzzle) 25 | if (inv_counter %2 ==0): 26 | return True 27 | return False 28 | 29 | 30 | #1,8,2,0,4,3,7,6,5 is solvable 31 | #2,1,3,4,5,6,7,8,0 is not solvable 32 | 33 | from time import time 34 | 35 | if solvable(root): 36 | print("Solvable, please wait. \n") 37 | 38 | 39 | time3 = time() 40 | Greedy_solution = Greedy(root, n) 41 | Greedy_time = time() - time3 42 | print('Greedy Solution is ', Greedy_solution[0]) 43 | print('Number of explored nodes is ', Greedy_solution[1]) 44 | print('Greedy Time:', Greedy_time , "\n") 45 | 46 | 47 | 48 | 49 | else: 50 | print("Not solvable") 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /8puzzle/state.py: -------------------------------------------------------------------------------- 1 | class State: 2 | goal = [1, 2, 3, 4, 5, 6, 7, 8, 0] 3 | #this should be changed manually based on n 4 | #e.g. it should be [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] if n is 4. 5 | 6 | greedy_evaluation = None 7 | 8 | heuristic = None 9 | def __init__(self, state, parent, direction, depth, cost): 10 | self.state = state 11 | self.parent = parent 12 | self.direction = direction 13 | self.depth = depth 14 | 15 | if parent: 16 | self.cost = parent.cost + cost 17 | 18 | else: 19 | self.cost = cost 20 | 21 | 22 | 23 | def test(self): #check if the given state is goal 24 | if self.state == self.goal: 25 | return True 26 | return False 27 | 28 | 29 | 30 | 31 | #heuristic function based on number of misplaced tiles 32 | def Misplaced_Tiles(self,n): 33 | counter = 0; 34 | self.heuristic = 0 35 | for i in range(n*n): 36 | for j in range(n*n): 37 | if (self.state[i] != self.goal[j]): 38 | counter += 1 39 | self.heuristic = self.heuristic + counter 40 | 41 | self.greedy_evaluation = self.heuristic 42 | 43 | 44 | return( self.greedy_evaluation) 45 | 46 | 47 | 48 | @staticmethod 49 | 50 | #this would remove illegal moves for a given state 51 | def available_moves(x,n): 52 | moves = ['Left', 'Right', 'Up', 'Down'] 53 | if x % n == 0: 54 | moves.remove('Left') 55 | if x % n == n-1: 56 | moves.remove('Right') 57 | if x - n < 0: 58 | moves.remove('Up') 59 | if x + n > n*n - 1: 60 | moves.remove('Down') 61 | 62 | return moves 63 | 64 | #produces children of a given state 65 | def expand(self , n): 66 | x = self.state.index(0) 67 | moves = self.available_moves(x,n) 68 | 69 | children = [] 70 | for direction in moves: 71 | temp = self.state.copy() 72 | if direction == 'Left': 73 | temp[x], temp[x - 1] = temp[x - 1], temp[x] 74 | elif direction == 'Right': 75 | temp[x], temp[x + 1] = temp[x + 1], temp[x] 76 | elif direction == 'Up': 77 | temp[x], temp[x - n] = temp[x - n], temp[x] 78 | elif direction == 'Down': 79 | temp[x], temp[x + n] = temp[x + n], temp[x] 80 | 81 | 82 | children.append(State(temp, self, direction, self.depth + 1, 1)) #depth should be changed as children are produced 83 | return children 84 | 85 | 86 | #gets the given state and returns it's direction + it's parent's direction till there is no parent 87 | def solution(self): 88 | solution = [] 89 | solution.append(self.direction) 90 | path = self 91 | while path.parent != None: 92 | path = path.parent 93 | solution.append(path.direction) 94 | solution = solution[:-1] 95 | solution.reverse() 96 | return solution 97 | -------------------------------------------------------------------------------- /A STAR/Astar.py: -------------------------------------------------------------------------------- 1 | def aStarAlgo(start_node, stop_node): 2 | 3 | 4 | open_set = set(start_node) # {A}, len{open_set}=1 5 | print("open_set:",open_set) 6 | closed_set = set() 7 | g = {} # store the distance from starting node 8 | #print(type(g)) 9 | parents = {} 10 | g[start_node] = 0 #cost of starting node is 0 11 | parents[start_node] = start_node # parents['A']='A" 12 | print("len of open_set:",len(open_set)) 13 | while len(open_set) > 0 : 14 | n = None 15 | print("open_set",open_set) 16 | for v in open_set: # v='B'/'F' 17 | print(f"g[{v}]",g[v]) 18 | print("heuristic:",heuristic(v)) 19 | print("n",n) 20 | 21 | 22 | if n == None or g[v] + heuristic(v) < g[n] + heuristic(n): 23 | n = v # n='A' 24 | 25 | if n == stop_node or Graph_nodes[n] == None: 26 | pass 27 | else: 28 | for (m, weight) in get_neighbors(n): 29 | # nodes 'm' not in first and last set are added to first 30 | # n is set its parent 31 | print("m",m) 32 | print("weight:",weight) 33 | 34 | if m not in open_set and m not in closed_set: 35 | print("open_Set:",open_set) 36 | open_set.add(m) # m=B weight=6 {'F','B','A'} len{open_set}=2 37 | parents[m] = n # parents={'A':A,'B':A} len{parent}=2 38 | print("parent_node",parents[m]) 39 | g[m] = g[n] + weight # g={'A':0,'B':6, 'F':3} len{g}=2 40 | 41 | 42 | #for each node m,compare its distance from start i.e g(m) to the 43 | #from start through n node 44 | else: 45 | print(f"g[{m}]",g[m]) 46 | print(f"g[{n}]",g[n]) 47 | if g[m] > g[n] + weight: 48 | #update g(m) 49 | g[m] = g[n] + weight 50 | #change parent of m to n 51 | parents[m] = n 52 | print('dicc',g) 53 | #if m in closed set,remove and add to open 54 | if m in closed_set: 55 | closed_set.remove(m) 56 | open_set.add(m) 57 | 58 | if n == None: 59 | print('Path does not exist!') 60 | return None 61 | 62 | # if the current node is the stop_node 63 | # then we begin reconstructin the path from it to the start_node 64 | if n == stop_node: 65 | path = [] 66 | 67 | while parents[n] != n: 68 | path.append(n) 69 | n = parents[n] 70 | 71 | path.append(start_node) 72 | print(path) 73 | path.reverse() 74 | 75 | print('Path found: {}'.format(path)) 76 | return path 77 | 78 | 79 | # remove n from the open_list, and add it to closed_list 80 | # because all of his neighbors were inspected 81 | open_set.remove(n)# {'F','B'} len=2 82 | closed_set.add(n) #{A} len=1 83 | 84 | print('Path does not exist!') 85 | return None 86 | 87 | #define fuction to return neighbor and its distance 88 | #from the passed node 89 | def get_neighbors(v): 90 | if v in Graph_nodes: 91 | return Graph_nodes[v] 92 | else: 93 | return None 94 | #for simplicity we ll consider heuristic distances given 95 | #and this function returns heuristic distance for all nodes 96 | 97 | def heuristic(n): 98 | H_dist = { 99 | 'A': 11, 100 | 'B': 6, 101 | 'C': 99, 102 | 'D': 1, 103 | 'E': 7, 104 | 'G': 0, 105 | 106 | } 107 | 108 | return H_dist[n] 109 | 110 | #Describe your graph here 111 | Graph_nodes = { 112 | 'A': [('B', 2), ('E', 3)], 113 | 'B': [('C', 1),('G', 9)], 114 | 'C': None, 115 | 'E': [('D', 6)], 116 | 'D': [('G', 1)], 117 | 118 | } 119 | aStarAlgo('A', 'G') -------------------------------------------------------------------------------- /A STAR/astar graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/A STAR/astar graph.png -------------------------------------------------------------------------------- /NLP/.ipynb_checkpoints/NLPtask-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": { 7 | "colab": { 8 | "base_uri": "https://localhost:8080/" 9 | }, 10 | "id": "AYCeMR1pifkl", 11 | "outputId": "07d96970-ddcd-4b76-ca8d-37a9cc44e096" 12 | }, 13 | "outputs": [ 14 | { 15 | "name": "stderr", 16 | "output_type": "stream", 17 | "text": [ 18 | "[nltk_data] Downloading package wordnet to\n", 19 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 20 | "[nltk_data] Package wordnet is already up-to-date!\n", 21 | "[nltk_data] Downloading package stopwords to\n", 22 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 23 | "[nltk_data] Package stopwords is already up-to-date!\n", 24 | "[nltk_data] Downloading package omw-1.4 to\n", 25 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 26 | "[nltk_data] Package omw-1.4 is already up-to-date!\n", 27 | "[nltk_data] Downloading package punkt to\n", 28 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 29 | "[nltk_data] Package punkt is already up-to-date!\n" 30 | ] 31 | } 32 | ], 33 | "source": [ 34 | "import nltk\n", 35 | "nltk.download('wordnet')\n", 36 | "nltk.download('stopwords')\n", 37 | "nltk.download('omw-1.4')\n", 38 | "nltk.download('punkt')\n", 39 | "\n", 40 | "text=\"\"\"Robin loves playing football. He often plays in the park with his friends. Football keeps him fit and healthy.\"\"\"\n" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 7, 46 | "metadata": { 47 | "colab": { 48 | "base_uri": "https://localhost:8080/" 49 | }, 50 | "id": "7niUyQ9s_PhE", 51 | "outputId": "91041901-222d-4a66-8e28-4be94f563dee" 52 | }, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "['Robin loves playing football.', 'He often plays in the park with his friends.', 'Football keeps him fit and healthy.']\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "sent=nltk.sent_tokenize(text)\n", 64 | "print(sent)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 21, 70 | "metadata": { 71 | "colab": { 72 | "base_uri": "https://localhost:8080/", 73 | "height": 53 74 | }, 75 | "id": "YAcysU4fi0Ei", 76 | "outputId": "d5e979fc-f0b1-4b9c-a634-e5d03a547a38" 77 | }, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "robin loves playing football.\n", 84 | "he often plays in the park with his friends.\n", 85 | "football keeps him fit and healthy.\n" 86 | ] 87 | }, 88 | { 89 | "data": { 90 | "text/plain": [ 91 | "'robin loves playing football he often plays in the park with his friends football keeps him fit and healthy '" 92 | ] 93 | }, 94 | "execution_count": 21, 95 | "metadata": {}, 96 | "output_type": "execute_result" 97 | } 98 | ], 99 | "source": [ 100 | "import re\n", 101 | "f_text=[]\n", 102 | "for sentence in sent:\n", 103 | " print(sentence.lower())\n", 104 | " cleaned_text = re.sub(r\"[^a-z\\'A-Z]\", \" \", sentence.lower())\n", 105 | " f_text.append(cleaned_text)\n", 106 | "fin_text=' '.join(f_text)\n", 107 | "fin_text\n" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 23, 113 | "metadata": { 114 | "colab": { 115 | "base_uri": "https://localhost:8080/" 116 | }, 117 | "id": "pob6k8i8fPuY", 118 | "outputId": "a7fdabf7-ddda-4005-af84-c8492f589980" 119 | }, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "['robin', 'loves', 'playing', 'football', 'he', 'often', 'plays', 'in', 'the', 'park', 'with', 'his', 'friends', 'football', 'keeps', 'him', 'fit', 'and', 'healthy']\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "words= fin_text.split()\n", 131 | "\n", 132 | "print(words)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 25, 138 | "metadata": { 139 | "colab": { 140 | "base_uri": "https://localhost:8080/" 141 | }, 142 | "id": "NRtDK6J1i09Y", 143 | "outputId": "c6379d6b-5180-4a91-e58b-11089b75442a" 144 | }, 145 | "outputs": [ 146 | { 147 | "name": "stdout", 148 | "output_type": "stream", 149 | "text": [ 150 | "['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', \"you're\", \"you've\", \"you'll\", \"you'd\", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', \"she's\", 'her', 'hers', 'herself', 'it', \"it's\", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', \"that'll\", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', \"don't\", 'should', \"should've\", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', \"aren't\", 'couldn', \"couldn't\", 'didn', \"didn't\", 'doesn', \"doesn't\", 'hadn', \"hadn't\", 'hasn', \"hasn't\", 'haven', \"haven't\", 'isn', \"isn't\", 'ma', 'mightn', \"mightn't\", 'mustn', \"mustn't\", 'needn', \"needn't\", 'shan', \"shan't\", 'shouldn', \"shouldn't\", 'wasn', \"wasn't\", 'weren', \"weren't\", 'won', \"won't\", 'wouldn', \"wouldn't\"]\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "from nltk.corpus import stopwords\n", 156 | "print(stopwords.words(\"english\"))" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 27, 162 | "metadata": { 163 | "colab": { 164 | "base_uri": "https://localhost:8080/" 165 | }, 166 | "id": "PsJ7PZuHi5MU", 167 | "outputId": "48c00dd4-999a-41bf-8000-dbabc4e619bf" 168 | }, 169 | "outputs": [ 170 | { 171 | "name": "stdout", 172 | "output_type": "stream", 173 | "text": [ 174 | "['robin', 'loves', 'playing', 'football', 'often', 'plays', 'park', 'friends', 'football', 'keeps', 'fit', 'healthy']\n" 175 | ] 176 | } 177 | ], 178 | "source": [ 179 | "words = [w for w in words if w not in stopwords.words(\"english\")]\n", 180 | "print(words)\n", 181 | "\n", 182 | "#for k in words:\n", 183 | " # for l in k:\n", 184 | " # if l not in stopwords.words(\"english\"):\n", 185 | "\n", 186 | " # print(l)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 29, 192 | "metadata": { 193 | "colab": { 194 | "base_uri": "https://localhost:8080/" 195 | }, 196 | "id": "WH_B-GlQi91J", 197 | "outputId": "fd3c12f9-2955-4e24-d6fc-f5a4795ed584" 198 | }, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "['robin', 'love', 'play', 'footbal', 'often', 'play', 'park', 'friend', 'footbal', 'keep', 'fit', 'healthi']\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "from nltk.stem.porter import PorterStemmer\n", 210 | "# Reduce words to their stems\n", 211 | "stemmed = [PorterStemmer().stem(w) for w in words]\n", 212 | "print(stemmed)\n" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 31, 218 | "metadata": { 219 | "colab": { 220 | "base_uri": "https://localhost:8080/" 221 | }, 222 | "id": "wrjeBSHsjBwh", 223 | "outputId": "5ef76bcc-94d7-42de-e493-3e181947fa49" 224 | }, 225 | "outputs": [ 226 | { 227 | "name": "stdout", 228 | "output_type": "stream", 229 | "text": [ 230 | "['robin', 'love', 'playing', 'football', 'often', 'play', 'park', 'friend', 'football', 'keep', 'fit', 'healthy']\n" 231 | ] 232 | } 233 | ], 234 | "source": [ 235 | "from nltk.stem.wordnet import WordNetLemmatizer\n", 236 | "# Reduce words to their root form\n", 237 | "lemmed = [WordNetLemmatizer().lemmatize(w) for w in words]\n", 238 | "print(lemmed)" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 35, 244 | "metadata": { 245 | "colab": { 246 | "base_uri": "https://localhost:8080/", 247 | "height": 588 248 | }, 249 | "id": "DuSwQpx8kgyz", 250 | "outputId": "82007f28-bff2-4b10-b8c5-bbf5d345c663" 251 | }, 252 | "outputs": [ 253 | { 254 | "ename": "NameError", 255 | "evalue": "name 'ne_chunk' is not defined", 256 | "output_type": "error", 257 | "traceback": [ 258 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 259 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 260 | "Cell \u001b[1;32mIn[35], line 5\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mnltk\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pos_tag,RegexpParser\n\u001b[0;32m 3\u001b[0m tagged\u001b[38;5;241m=\u001b[39mpos_tag(lemmed)\n\u001b[1;32m----> 5\u001b[0m named_entities\u001b[38;5;241m=\u001b[39mne_chunk(tagged)\n\u001b[0;32m 6\u001b[0m chunker\u001b[38;5;241m=\u001b[39mRegexpParser(\u001b[38;5;124m\"\"\"\u001b[39m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;124mNP:\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\n\u001b[0;32m 8\u001b[0m \u001b[38;5;124mP:\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 12\u001b[0m \n\u001b[0;32m 13\u001b[0m \u001b[38;5;124m\"\"\"\u001b[39m)\n\u001b[0;32m 14\u001b[0m output \u001b[38;5;241m=\u001b[39m chunker\u001b[38;5;241m.\u001b[39mparse(tagged)\n", 261 | "\u001b[1;31mNameError\u001b[0m: name 'ne_chunk' is not defined" 262 | ] 263 | } 264 | ], 265 | "source": [ 266 | "from nltk import pos_tag,RegexpParser,ne_chunk\n", 267 | "\n", 268 | "tagged=pos_tag(lemmed)\n", 269 | "\n", 270 | "named_entities=ne_chunk(tagged)\n", 271 | "chunker=RegexpParser(\"\"\"\n", 272 | "NP:{}\n", 273 | "P:{}\n", 274 | "V:{}\n", 275 | "PP:{}\n", 276 | "VP:{}\n", 277 | "\n", 278 | "\"\"\")\n", 279 | "output = chunker.parse(tagged)\n", 280 | "print(\"pos tagged:\", tagged)\n", 281 | "print(\"named entities\",named_entities)\n", 282 | "print(\"After Extracting\", output)\n", 283 | "\n" 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "execution_count": null, 289 | "metadata": {}, 290 | "outputs": [], 291 | "source": [] 292 | } 293 | ], 294 | "metadata": { 295 | "colab": { 296 | "provenance": [] 297 | }, 298 | "kernelspec": { 299 | "display_name": "Python 3 (ipykernel)", 300 | "language": "python", 301 | "name": "python3" 302 | }, 303 | "language_info": { 304 | "codemirror_mode": { 305 | "name": "ipython", 306 | "version": 3 307 | }, 308 | "file_extension": ".py", 309 | "mimetype": "text/x-python", 310 | "name": "python", 311 | "nbconvert_exporter": "python", 312 | "pygments_lexer": "ipython3", 313 | "version": "3.11.7" 314 | } 315 | }, 316 | "nbformat": 4, 317 | "nbformat_minor": 4 318 | } 319 | -------------------------------------------------------------------------------- /NLP/.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /NLP/.ipynb_checkpoints/nlp-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 21, 6 | "metadata": { 7 | "colab": { 8 | "base_uri": "https://localhost:8080/" 9 | }, 10 | "id": "AYCeMR1pifkl", 11 | "outputId": "07d96970-ddcd-4b76-ca8d-37a9cc44e096" 12 | }, 13 | "outputs": [ 14 | { 15 | "name": "stderr", 16 | "output_type": "stream", 17 | "text": [ 18 | "[nltk_data] Downloading package wordnet to\n", 19 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 20 | "[nltk_data] Package wordnet is already up-to-date!\n", 21 | "[nltk_data] Downloading package stopwords to\n", 22 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 23 | "[nltk_data] Package stopwords is already up-to-date!\n", 24 | "[nltk_data] Downloading package omw-1.4 to\n", 25 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 26 | "[nltk_data] Package omw-1.4 is already up-to-date!\n", 27 | "[nltk_data] Downloading package punkt to\n", 28 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 29 | "[nltk_data] Package punkt is already up-to-date!\n" 30 | ] 31 | } 32 | ], 33 | "source": [ 34 | "import nltk\n", 35 | "nltk.download('wordnet')\n", 36 | "nltk.download('stopwords')\n", 37 | "nltk.download('omw-1.4')\n", 38 | "nltk.download('punkt')\n", 39 | "\n", 40 | "text=\"\"\"Hello Mr. Smith, how are you doing today? The weather is great, and city is awesome. The sky is pinkish-blue. You shouldn\\'t eat cardboard\"\"\"\n" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "metadata": { 47 | "colab": { 48 | "base_uri": "https://localhost:8080/" 49 | }, 50 | "id": "7niUyQ9s_PhE", 51 | "outputId": "91041901-222d-4a66-8e28-4be94f563dee" 52 | }, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "['Hello Mr. Smith, how are you doing today?', 'The weather is great, and city is awesome.', 'The sky is pinkish-blue.', \"You shouldn't eat cardboard\"]\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "sent=nltk.sent_tokenize(text)\n", 64 | "print(sent)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 5, 70 | "metadata": { 71 | "colab": { 72 | "base_uri": "https://localhost:8080/", 73 | "height": 53 74 | }, 75 | "id": "YAcysU4fi0Ei", 76 | "outputId": "d5e979fc-f0b1-4b9c-a634-e5d03a547a38" 77 | }, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "hello mr. smith, how are you doing today? the weather is great, and city is awesome. the sky is pinkish-blue. you shouldn't eat cardboard\n" 84 | ] 85 | }, 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "\"hello mr smith how are you doing today the weather is great and city is awesome the sky is pinkish blue you shouldn't eat cardboard\"" 90 | ] 91 | }, 92 | "execution_count": 5, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "import re\n", 99 | "#text=\"SaaaaMMM\"\n", 100 | "print(text.lower())\n", 101 | "text = re.sub(r\"[^a-z\\'A-Z]\", \" \", text.lower())\n", 102 | "text\n" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 7, 108 | "metadata": { 109 | "colab": { 110 | "base_uri": "https://localhost:8080/" 111 | }, 112 | "id": "pob6k8i8fPuY", 113 | "outputId": "a7fdabf7-ddda-4005-af84-c8492f589980" 114 | }, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "['hello', 'mr', 'smith', 'how', 'are', 'you', 'doing', 'today', 'the', 'weather', 'is', 'great', 'and', 'city', 'is', 'awesome', 'the', 'sky', 'is', 'pinkish', 'blue', 'you', \"shouldn't\", 'eat', 'cardboard']\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "words= text.split()\n", 126 | "\n", 127 | "print(words)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 9, 133 | "metadata": { 134 | "colab": { 135 | "base_uri": "https://localhost:8080/" 136 | }, 137 | "id": "NRtDK6J1i09Y", 138 | "outputId": "c6379d6b-5180-4a91-e58b-11089b75442a" 139 | }, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', \"you're\", \"you've\", \"you'll\", \"you'd\", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', \"she's\", 'her', 'hers', 'herself', 'it', \"it's\", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', \"that'll\", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', \"don't\", 'should', \"should've\", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', \"aren't\", 'couldn', \"couldn't\", 'didn', \"didn't\", 'doesn', \"doesn't\", 'hadn', \"hadn't\", 'hasn', \"hasn't\", 'haven', \"haven't\", 'isn', \"isn't\", 'ma', 'mightn', \"mightn't\", 'mustn', \"mustn't\", 'needn', \"needn't\", 'shan', \"shan't\", 'shouldn', \"shouldn't\", 'wasn', \"wasn't\", 'weren', \"weren't\", 'won', \"won't\", 'wouldn', \"wouldn't\"]\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "from nltk.corpus import stopwords\n", 151 | "print(stopwords.words(\"english\"))" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 11, 157 | "metadata": { 158 | "colab": { 159 | "base_uri": "https://localhost:8080/" 160 | }, 161 | "id": "PsJ7PZuHi5MU", 162 | "outputId": "48c00dd4-999a-41bf-8000-dbabc4e619bf" 163 | }, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "['hello', 'mr', 'smith', 'today', 'weather', 'great', 'city', 'awesome', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "words = [w for w in words if w not in stopwords.words(\"english\")]\n", 175 | "print(words)\n", 176 | "\n", 177 | "#for k in words:\n", 178 | " # for l in k:\n", 179 | " # if l not in stopwords.words(\"english\"):\n", 180 | "\n", 181 | " # print(l)" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 13, 187 | "metadata": { 188 | "colab": { 189 | "base_uri": "https://localhost:8080/" 190 | }, 191 | "id": "WH_B-GlQi91J", 192 | "outputId": "fd3c12f9-2955-4e24-d6fc-f5a4795ed584" 193 | }, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "['hello', 'mr', 'smith', 'today', 'weather', 'great', 'citi', 'awesom', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "from nltk.stem.porter import PorterStemmer\n", 205 | "# Reduce words to their stems\n", 206 | "stemmed = [PorterStemmer().stem(w) for w in words]\n", 207 | "print(stemmed)\n" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 15, 213 | "metadata": { 214 | "colab": { 215 | "base_uri": "https://localhost:8080/" 216 | }, 217 | "id": "wrjeBSHsjBwh", 218 | "outputId": "5ef76bcc-94d7-42de-e493-3e181947fa49" 219 | }, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "['hello', 'mr', 'smith', 'today', 'weather', 'great', 'city', 'awesome', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 226 | ] 227 | } 228 | ], 229 | "source": [ 230 | "from nltk.stem.wordnet import WordNetLemmatizer\n", 231 | "# Reduce words to their root form\n", 232 | "lemmed = [WordNetLemmatizer().lemmatize(w) for w in words]\n", 233 | "print(lemmed)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 27, 239 | "metadata": { 240 | "colab": { 241 | "base_uri": "https://localhost:8080/", 242 | "height": 588 243 | }, 244 | "id": "DuSwQpx8kgyz", 245 | "outputId": "82007f28-bff2-4b10-b8c5-bbf5d345c663" 246 | }, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "[('hello', 'NN'), ('mr', 'NN'), ('smith', 'NN'), ('today', 'NN'), ('weather', 'VBP'), ('great', 'JJ'), ('city', 'NN'), ('awesome', 'VBP'), ('sky', 'JJ'), ('pinkish', 'JJ'), ('blue', 'NN'), ('eat', 'NN'), ('cardboard', 'NN')]\n", 253 | "After Extracting (S\n", 254 | " hello/NN\n", 255 | " mr/NN\n", 256 | " smith/NN\n", 257 | " today/NN\n", 258 | " weather/NN\n", 259 | " great/JJ\n", 260 | " city/NN\n", 261 | " awesome/VBP\n", 262 | " sky/JJ\n", 263 | " pinkish/JJ\n", 264 | " blue/NN\n", 265 | " eat/VB\n", 266 | " cardboard/NN)\n" 267 | ] 268 | } 269 | ], 270 | "source": [ 271 | "from nltk import pos_tag,RegexpParser\n", 272 | "\n", 273 | "tagged=pos_tag(lemmed)\n", 274 | "print(tagged)\n", 275 | "for i, (word, tag) in enumerate(tagged):\n", 276 | " if word == \"weather\":\n", 277 | " tagged[i] = (word, \"NN\") \n", 278 | " if word == \"eat\":\n", 279 | " tagged[i] = (word, \"VB\")\n", 280 | "'''chunker = RegexpParser(\"\"\"\n", 281 | "NP: {
?*} # Noun Phrases ?-MAKES THE determiner optional ,the noun phrase could be just an adjective and a noun\n", 282 | " P: {} # Prepositions- regexp looks for a word tagged as an in preposition\n", 283 | " V: {} # Verbs -this regexp matches any form of a verb\n", 284 | " PP: {

} # Prepositional Phrases

preposition and noun phrase\n", 285 | " VP: {*} # Verb Phrases- * indicates 0 or more noun or prepositional phrase after verb\"\"\")'''\n", 286 | "chunker=RegexpParser(\"\"\"\n", 287 | "NP:{}\n", 288 | "P:{}\n", 289 | "V:{}\n", 290 | "PP:{}\n", 291 | "VP:{}\n", 292 | "\n", 293 | "\"\"\")\n", 294 | "output = chunker.parse(tagged)\n", 295 | "print(\"After Extracting\", output)\n" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": null, 301 | "metadata": {}, 302 | "outputs": [], 303 | "source": [] 304 | } 305 | ], 306 | "metadata": { 307 | "colab": { 308 | "provenance": [] 309 | }, 310 | "kernelspec": { 311 | "display_name": "Python 3 (ipykernel)", 312 | "language": "python", 313 | "name": "python3" 314 | }, 315 | "language_info": { 316 | "codemirror_mode": { 317 | "name": "ipython", 318 | "version": 3 319 | }, 320 | "file_extension": ".py", 321 | "mimetype": "text/x-python", 322 | "name": "python", 323 | "nbconvert_exporter": "python", 324 | "pygments_lexer": "ipython3", 325 | "version": "3.11.7" 326 | } 327 | }, 328 | "nbformat": 4, 329 | "nbformat_minor": 4 330 | } 331 | -------------------------------------------------------------------------------- /NLP/NLP.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 21, 6 | "metadata": { 7 | "colab": { 8 | "base_uri": "https://localhost:8080/" 9 | }, 10 | "id": "AYCeMR1pifkl", 11 | "outputId": "07d96970-ddcd-4b76-ca8d-37a9cc44e096" 12 | }, 13 | "outputs": [ 14 | { 15 | "name": "stderr", 16 | "output_type": "stream", 17 | "text": [ 18 | "[nltk_data] Downloading package wordnet to\n", 19 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 20 | "[nltk_data] Package wordnet is already up-to-date!\n", 21 | "[nltk_data] Downloading package stopwords to\n", 22 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 23 | "[nltk_data] Package stopwords is already up-to-date!\n", 24 | "[nltk_data] Downloading package omw-1.4 to\n", 25 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 26 | "[nltk_data] Package omw-1.4 is already up-to-date!\n", 27 | "[nltk_data] Downloading package punkt to\n", 28 | "[nltk_data] C:\\Users\\HP\\AppData\\Roaming\\nltk_data...\n", 29 | "[nltk_data] Package punkt is already up-to-date!\n" 30 | ] 31 | } 32 | ], 33 | "source": [ 34 | "import nltk\n", 35 | "nltk.download('wordnet')\n", 36 | "nltk.download('stopwords')\n", 37 | "nltk.download('omw-1.4')\n", 38 | "nltk.download('punkt')\n", 39 | "\n", 40 | "text=\"\"\"Hello Mr. Smith, how are you doing today? The weather is great, and city is awesome. The sky is pinkish-blue. You shouldn\\'t eat cardboard\"\"\"\n" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "metadata": { 47 | "colab": { 48 | "base_uri": "https://localhost:8080/" 49 | }, 50 | "id": "7niUyQ9s_PhE", 51 | "outputId": "91041901-222d-4a66-8e28-4be94f563dee" 52 | }, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "['Hello Mr. Smith, how are you doing today?', 'The weather is great, and city is awesome.', 'The sky is pinkish-blue.', \"You shouldn't eat cardboard\"]\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "sent=nltk.sent_tokenize(text)\n", 64 | "print(sent)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 5, 70 | "metadata": { 71 | "colab": { 72 | "base_uri": "https://localhost:8080/", 73 | "height": 53 74 | }, 75 | "id": "YAcysU4fi0Ei", 76 | "outputId": "d5e979fc-f0b1-4b9c-a634-e5d03a547a38" 77 | }, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "hello mr. smith, how are you doing today? the weather is great, and city is awesome. the sky is pinkish-blue. you shouldn't eat cardboard\n" 84 | ] 85 | }, 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "\"hello mr smith how are you doing today the weather is great and city is awesome the sky is pinkish blue you shouldn't eat cardboard\"" 90 | ] 91 | }, 92 | "execution_count": 5, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "import re\n", 99 | "#text=\"SaaaaMMM\"\n", 100 | "print(text.lower())\n", 101 | "text = re.sub(r\"[^a-z\\'A-Z]\", \" \", text.lower())\n", 102 | "text\n" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 7, 108 | "metadata": { 109 | "colab": { 110 | "base_uri": "https://localhost:8080/" 111 | }, 112 | "id": "pob6k8i8fPuY", 113 | "outputId": "a7fdabf7-ddda-4005-af84-c8492f589980" 114 | }, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "['hello', 'mr', 'smith', 'how', 'are', 'you', 'doing', 'today', 'the', 'weather', 'is', 'great', 'and', 'city', 'is', 'awesome', 'the', 'sky', 'is', 'pinkish', 'blue', 'you', \"shouldn't\", 'eat', 'cardboard']\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "words= text.split()\n", 126 | "\n", 127 | "print(words)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 9, 133 | "metadata": { 134 | "colab": { 135 | "base_uri": "https://localhost:8080/" 136 | }, 137 | "id": "NRtDK6J1i09Y", 138 | "outputId": "c6379d6b-5180-4a91-e58b-11089b75442a" 139 | }, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', \"you're\", \"you've\", \"you'll\", \"you'd\", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', \"she's\", 'her', 'hers', 'herself', 'it', \"it's\", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', \"that'll\", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', \"don't\", 'should', \"should've\", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', \"aren't\", 'couldn', \"couldn't\", 'didn', \"didn't\", 'doesn', \"doesn't\", 'hadn', \"hadn't\", 'hasn', \"hasn't\", 'haven', \"haven't\", 'isn', \"isn't\", 'ma', 'mightn', \"mightn't\", 'mustn', \"mustn't\", 'needn', \"needn't\", 'shan', \"shan't\", 'shouldn', \"shouldn't\", 'wasn', \"wasn't\", 'weren', \"weren't\", 'won', \"won't\", 'wouldn', \"wouldn't\"]\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "from nltk.corpus import stopwords\n", 151 | "print(stopwords.words(\"english\"))" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 11, 157 | "metadata": { 158 | "colab": { 159 | "base_uri": "https://localhost:8080/" 160 | }, 161 | "id": "PsJ7PZuHi5MU", 162 | "outputId": "48c00dd4-999a-41bf-8000-dbabc4e619bf" 163 | }, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "['hello', 'mr', 'smith', 'today', 'weather', 'great', 'city', 'awesome', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "words = [w for w in words if w not in stopwords.words(\"english\")]\n", 175 | "print(words)\n", 176 | "\n", 177 | "#for k in words:\n", 178 | " # for l in k:\n", 179 | " # if l not in stopwords.words(\"english\"):\n", 180 | "\n", 181 | " # print(l)" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 13, 187 | "metadata": { 188 | "colab": { 189 | "base_uri": "https://localhost:8080/" 190 | }, 191 | "id": "WH_B-GlQi91J", 192 | "outputId": "fd3c12f9-2955-4e24-d6fc-f5a4795ed584" 193 | }, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "['hello', 'mr', 'smith', 'today', 'weather', 'great', 'citi', 'awesom', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "from nltk.stem.porter import PorterStemmer\n", 205 | "# Reduce words to their stems\n", 206 | "stemmed = [PorterStemmer().stem(w) for w in words]\n", 207 | "print(stemmed)\n" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 15, 213 | "metadata": { 214 | "colab": { 215 | "base_uri": "https://localhost:8080/" 216 | }, 217 | "id": "wrjeBSHsjBwh", 218 | "outputId": "5ef76bcc-94d7-42de-e493-3e181947fa49" 219 | }, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "['hello', 'mr', 'smith', 'today', 'weather', 'great', 'city', 'awesome', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 226 | ] 227 | } 228 | ], 229 | "source": [ 230 | "from nltk.stem.wordnet import WordNetLemmatizer\n", 231 | "# Reduce words to their root form\n", 232 | "lemmed = [WordNetLemmatizer().lemmatize(w) for w in words]\n", 233 | "print(lemmed)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 27, 239 | "metadata": { 240 | "colab": { 241 | "base_uri": "https://localhost:8080/", 242 | "height": 588 243 | }, 244 | "id": "DuSwQpx8kgyz", 245 | "outputId": "82007f28-bff2-4b10-b8c5-bbf5d345c663" 246 | }, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "[('hello', 'NN'), ('mr', 'NN'), ('smith', 'NN'), ('today', 'NN'), ('weather', 'VBP'), ('great', 'JJ'), ('city', 'NN'), ('awesome', 'VBP'), ('sky', 'JJ'), ('pinkish', 'JJ'), ('blue', 'NN'), ('eat', 'NN'), ('cardboard', 'NN')]\n", 253 | "After Extracting (S\n", 254 | " hello/NN\n", 255 | " mr/NN\n", 256 | " smith/NN\n", 257 | " today/NN\n", 258 | " weather/NN\n", 259 | " great/JJ\n", 260 | " city/NN\n", 261 | " awesome/VBP\n", 262 | " sky/JJ\n", 263 | " pinkish/JJ\n", 264 | " blue/NN\n", 265 | " eat/VB\n", 266 | " cardboard/NN)\n" 267 | ] 268 | } 269 | ], 270 | "source": [ 271 | "from nltk import pos_tag,RegexpParser\n", 272 | "\n", 273 | "tagged=pos_tag(lemmed)\n", 274 | "print(tagged)\n", 275 | "for i, (word, tag) in enumerate(tagged):\n", 276 | " if word == \"weather\":\n", 277 | " tagged[i] = (word, \"NN\") \n", 278 | " if word == \"eat\":\n", 279 | " tagged[i] = (word, \"VB\")\n", 280 | "'''chunker = RegexpParser(\"\"\"\n", 281 | "NP: {

?*} # Noun Phrases ?-MAKES THE determiner optional ,the noun phrase could be just an adjective and a noun\n", 282 | " P: {} # Prepositions- regexp looks for a word tagged as an in preposition\n", 283 | " V: {} # Verbs -this regexp matches any form of a verb\n", 284 | " PP: {

} # Prepositional Phrases

preposition and noun phrase\n", 285 | " VP: {*} # Verb Phrases- * indicates 0 or more noun or prepositional phrase after verb\"\"\")'''\n", 286 | "chunker=RegexpParser(\"\"\"\n", 287 | "NP:{}\n", 288 | "P:{}\n", 289 | "V:{}\n", 290 | "PP:{}\n", 291 | "VP:{}\n", 292 | "\n", 293 | "\"\"\")\n", 294 | "output = chunker.parse(tagged)\n", 295 | "print(\"After Extracting\", output)\n" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": null, 301 | "metadata": {}, 302 | "outputs": [], 303 | "source": [] 304 | } 305 | ], 306 | "metadata": { 307 | "colab": { 308 | "provenance": [] 309 | }, 310 | "kernelspec": { 311 | "display_name": "Python 3 (ipykernel)", 312 | "language": "python", 313 | "name": "python3" 314 | }, 315 | "language_info": { 316 | "codemirror_mode": { 317 | "name": "ipython", 318 | "version": 3 319 | }, 320 | "file_extension": ".py", 321 | "mimetype": "text/x-python", 322 | "name": "python", 323 | "nbconvert_exporter": "python", 324 | "pygments_lexer": "ipython3", 325 | "version": "3.11.7" 326 | } 327 | }, 328 | "nbformat": 4, 329 | "nbformat_minor": 4 330 | } 331 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # AI Algorithms 3 | This repository is focused on Artificial Intelligence Searching strategies,Machine Learning algorithm such as Decision Tree, MultiLayer perceptron along with Natural Language Processing. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ## Contributing 12 | 13 | Contributions are always welcome! 14 | 15 | - Create a personal fork of the project on Github.This will create a copy of this repository in your account. 16 | 17 | - Clone the fork on your local machine. Your remote repo on Github is called origin. 18 | 19 | ``` 20 | git clone "url u just copied" 21 | ``` 22 | 23 | - Make necessary changes and commit using 24 | ``` 25 | git add filename 26 | ``` 27 | ``` 28 | git commit -m "msg" 29 | ``` 30 | - Push your changes to github forked repository. 31 | ``` 32 | git push -u origin your-branch-name 33 | ``` 34 | - Submit your changes for a review 35 | ``` 36 | If you go to your repository on GitHub, you'll see a Compare & pull request button. Click on that button. 37 | ``` 38 | - Open a pull request 39 | -Soon I'll be merging all your changes into the main branch of this project. You will get a notification email once the changes have been merged. 40 | 41 | 42 | 43 | 44 | ## Authors 45 | - [@Sana Mateen](https://github.com/mssanamateen) 46 | 47 | ## Special Contribution by Students 48 | - [@Robin Thomas Antony](https://github.com/Rt1818) 49 | 50 | ## Student Contributions 51 | -[@Anushka088](https://github.com/Anushka088) 52 | -[@AshwinDivakaruni](https://github.com/Divk-Ashwin) 53 | -[@Sainath Ch](https://github.com/sainathch45) 54 | 55 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Alzheimers.txt: -------------------------------------------------------------------------------- 1 | Alzheimer’s disease is an irreversible, progressive brain disorder that slowly destroys memory and thinking skills and, eventually, the ability to carry out the simplest tasks. 2 | 3 | In most people with the disease—those with the late-onset type—symptoms first appear in their mid-60s. 4 | 5 | Early-onset Alzheimer’s occurs between a person’s 30s and mid-60s and is very rare. 6 | 7 | Alzheimer’s disease is the most common cause of dementia among older adults. 8 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Arthritis.txt: -------------------------------------------------------------------------------- 1 | Arthritis is inflammation of one or more of your joints. Pain, swelling, and stiffness are the primary symptoms of arthritis. Any joint in the body may be affected by the disease, but it is particularly common in the knee. 2 | 3 | Knee arthritis can make it hard to do many everyday activities, such as walking or climbing stairs. It is a major cause of lost work time and a serious disability for many people. 4 | 5 | The most common types of arthritis are osteoarthritis and rheumatoid arthritis, but there are more than 100 different forms. While arthritis is mainly an adult disease, some forms affect children. 6 | 7 | Although there is no cure for arthritis, there are many treatment options available to help manage pain and keep people staying active. 8 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Asthma.txt: -------------------------------------------------------------------------------- 1 | Asthma is a major noncommunicable disease characterized by recurrent attacks of breathlessness and wheezing, which vary in severity and frequency from person to person. 2 | 3 | Symptoms may occur several times in a day or week in affected individuals, and for some people become worse during physical activity or at night. 4 | 5 | During an asthma attack, the lining of the bronchial tubes swell, causing the airways to narrow and reducing the flow of air into and out of the lungs. 6 | 7 | Recurrent asthma symptoms frequently cause sleeplessness, daytime fatigue, reduced activity levels and school and work absenteeism. 8 | 9 | Asthma has a relatively low fatality rate compared to other chronic diseases. 10 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Coronavirus.txt: -------------------------------------------------------------------------------- 1 | Coronavirus disease (COVID-19) is an infectious disease caused by a newly discovered coronavirus. 2 | 3 | Most people infected with the COVID-19 virus will experience mild to moderate respiratory illness and recover without requiring special treatment. Older people, and those with underlying medical problems like cardiovascular disease, diabetes, chronic respiratory disease, and cancer are more likely to develop serious illness. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Diabetes.txt: -------------------------------------------------------------------------------- 1 | Diabetes is a disease in which your blood glucose, or blood sugar, levels are too high. 2 | 3 | Glucose comes from the foods you eat. 4 | 5 | Insulin is a hormone that helps the glucose get into your cells to give them energy. 6 | 7 | With type 1 diabetes, your body does not make insulin. 8 | 9 | With type 2 diabetes, the more common type, your body does not make or use insulin well. 10 | 11 | Without enough insulin, the glucose stays in your blood. 12 | 13 | You can also have prediabetes. This means that your blood sugar is higher than normal but not high enough to be called diabetes. Having prediabetes puts you at a higher risk of getting type 2 diabetes. 14 | 15 | Over time, having too much glucose in your blood can cause serious problems. It can damage your eyes, kidneys, and nerves. Diabetes can also cause heart disease, stroke and even the need to remove a limb. Pregnant women can also get diabetes, called gestational diabetes. 16 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Epilepsy.txt: -------------------------------------------------------------------------------- 1 | Epilepsy is defined as a brain disorder characterized by an enduring predisposition to generate epileptic seizures and by the neurobiologic, cognitive, psychological, and social consequences of this condition. 2 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Glaucoma.txt: -------------------------------------------------------------------------------- 1 | Glaucoma is a group of eye disorders that lead to progressive damage to the nerve that connects the eye to the brain called the optic nerve. People with glaucoma can lose nerve tissue, resulting in vision loss. 2 | 3 | The optic nerve is a bundle of about 1 million individual nerve fibers that transmits the visual signals from the eye to the brain. In the most common form of glaucoma, primary open-angle glaucoma, the fluid pressure inside the eye increases. This increase in pressure may cause progressive damage to the optic nerve and loss of nerve fibers. Advanced glaucoma may even lead to blindness. 4 | 5 | Not everyone with high eye pressure will develop glaucoma, and some people with normal eye pressure will develop glaucoma. When the pressure inside a person's eye is too high for a particular optic nerve, whatever that pressure measurement may be, glaucoma will develop. 6 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Heart Disease.txt: -------------------------------------------------------------------------------- 1 | Heart disease describes a range of conditions that affect your heart. Diseases under the heart disease umbrella include blood vessel diseases, such as coronary artery disease; heart rhythm problems (arrhythmias); and heart defects you're born with (congenital heart defects), among others. 2 | 3 | The term "heart disease" is often used interchangeably with the term "cardiovascular disease." Cardiovascular disease generally refers to conditions that involve narrowed or blocked blood vessels that can lead to a heart attack, chest pain (angina) or stroke. Other heart conditions, such as those that affect your heart's muscle, valves or rhythm, also are considered forms of heart disease. 4 | 5 | Many forms of heart disease can be prevented or treated with healthy lifestyle choices. 6 | 7 | Cardiovascular disease symptoms may be different for men and women. 8 | 9 | Causes: 10 | 11 | While cardiovascular disease can refer to different heart or blood vessel problems, the term is often used to mean damage to your heart or blood vessels by atherosclerosis, a buildup of fatty plaques in your arteries. 12 | 13 | Plaque buildup thickens and stiffens artery walls, which can inhibit blood flow through your arteries to your organs and tissues. 14 | 15 | Atherosclerosis is also the most common cause of cardiovascular disease. It can be caused by correctable problems, such as an unhealthy diet, lack of exercise, being overweight and smoking 16 | 17 | Common causes of abnormal heart rhythms (arrhythmias) or conditions that can lead to arrhythmias include: 18 | 19 | Heart defects since birth 20 | Coronary artery disease 21 | High blood pressure 22 | Diabetes 23 | Smoking 24 | Excessive use of alcohol or caffeine 25 | Drug abuse 26 | Stress 27 | Some over-the-counter medications, prescription medications, dietary supplements and herbal remedies 28 | Valvular heart disease -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Heat Stroke.txt: -------------------------------------------------------------------------------- 1 | Heatstroke generally occurs when an individual has been too hot for too long, whether working, exercising, or simply sitting in a hot environment. 2 | 3 | Also known as sunstroke, heatstroke is a serious condition and must be considered an emergency. 4 | 5 | If the body temperature rises above 40° Celsius, and the body loses the ability to cool down, it is considered to be heatstroke. 6 | 7 | If left untreated, damage to internal organs can occur. The longer it is left, the more serious heatstroke can become. In some cases, heatstroke can be fatal. 8 | 9 | Heatstroke can be brought on by physical exertion in hot conditions, or simply by being in a hot environment 10 | 11 | Treating heatstroke centers around bringing body temperature down. 12 | 13 | Heatstroke can occur as a result of: 14 | 15 | Exposure to a hot environment. 16 | 17 | In a type of heatstroke, called nonexertional (classic) heatstroke, being in a hot environment leads to a rise in core body temperature. This type of heatstroke typically occurs after exposure to hot, humid weather, especially for prolonged periods. 18 | 19 | It occurs most often in older adults and in people with chronic illness. 20 | 21 | Strenuous activity. Exertional heatstroke is caused by an increase in core body temperature brought on by intense physical activity in hot weather. 22 | 23 | Anyone exercising or working in hot weather can get exertional heatstroke, but it's most likely to occur if you're not used to high temperatures. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Hyperthyroidism.txt: -------------------------------------------------------------------------------- 1 | Hyperthyroidism is a condition of the thyroid. The thyroid is a small, butterfly-shaped gland located at the front of your neck. It produces tetraiodothyronine (T4) and triiodothyronine (T3), which are two primary hormones that control how your cells use energy. Your thyroid gland regulates your metabolism through the release of these hormones. 2 | 3 | Hyperthyroidism occurs when the thyroid makes too much T4, T3, or both. Diagnosis of overactive thyroid and treatment of the underlying cause can relieve symptoms and prevent complications. 4 | 5 | A variety of conditions can cause hyperthyroidism. Graves' disease, an autoimmune disorder, is the most common cause of hyperthyroidism. It causes antibodies to stimulate the thyroid to secrete too much hormone. Graves’ disease occurs more often in women than in men. It tends to run in families, which suggests a genetic link. You should tell your doctor if your relatives have had the condition. 6 | 7 | Other causes of hyperthyroidism include: 8 | 9 | Excess iodine, a key ingredient in T4 and T3 10 | 11 | Thyroiditis, or inflammation of the thyroid, which causes T4 and T3 to leak out of the gland 12 | 13 | Tumors of the ovaries or testes 14 | 15 | Benign tumors of the thyroid or pituitary gland 16 | 17 | Large amounts of tetraiodothyronine taken through dietary supplements or medication 18 | 19 | Diagnosis: 20 | 21 | Cholesterol test 22 | T4, free T4, T3 tests 23 | Thyroid stimulating hormone level test 24 | Triglyceride test 25 | Thyroid scan and uptake 26 | Ultrasound 27 | CT or MRI scans 28 | Radio Iodine Uptake test 29 | 30 | Physical Exam 31 | Blood Tests 32 | Checking for weight loss 33 | Checking for protruding eyes 34 | Checking for enlarged thyroid gland 35 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Hypothermia.txt: -------------------------------------------------------------------------------- 1 | Hypothermia is a medical emergency that occurs when your body loses heat faster than it can produce heat, causing a dangerously low body temperature. Normal body temperature is around 98.6 F (37 C). Hypothermia (hi-poe-THUR-me-uh) occurs as your body temperature falls below 95 F (35 C). 2 | 3 | When your body temperature drops, your heart, nervous system and other organs can't work normally. Left untreated, hypothermia can eventually lead to complete failure of your heart and respiratory system and eventually to death. 4 | 5 | Hypothermia is often caused by exposure to cold weather or immersion in cold water. Primary treatments for hypothermia are methods to warm the body back to a normal temperature. 6 | 7 | Hypothermia has two main types of causes. It classically occurs from exposure to extreme cold. 8 | 9 | It may also occur from any condition that decreases heat production or increases heat loss. 10 | Commonly this includes alcohol intoxication but may also include low blood sugar, anorexia, and advanced age. 11 | 12 | Body temperature is usually maintained near a constant level of 36.5–37.5 °C (97.7–99.5 °F) through thermoregulation. 13 | 14 | Efforts to increase body temperature involve shivering, increased voluntary activity, and putting on warmer clothing. 15 | 16 | Diagnosis: 17 | 18 | The diagnosis of hypothermia is usually apparent based on a person's physical signs and the conditions in which the person with hypothermia became ill or was found. Blood tests also can help confirm hypothermia and its severity. 19 | 20 | A diagnosis may not be readily apparent, however, if the symptoms are mild, as when an older person who is indoors has symptoms of confusion, lack of coordination and speech problems. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Jaundice.txt: -------------------------------------------------------------------------------- 1 | Jaundice causes your skin and the whites of your eyes to turn yellow. 2 | Too much bilirubin causes jaundice. 3 | Bilirubin is a yellow chemical in hemoglobin, the substance that carries oxygen in your red blood cells. 4 | As red blood cells break down, your body builds new cells to replace them. The old ones are processed by the liver. If the liver cannot handle the blood cells as they break down, bilirubin builds up in the body and your skin may look yellow. 5 | 6 | Many healthy babies have some jaundice during the first week of life. It usually goes away. However, jaundice can happen at any age and may be a sign of a problem. Jaundice can happen for many reasons, such as 7 | 8 | Blood diseases 9 | Genetic syndromes 10 | Liver diseases, such as hepatitis or cirrhosis 11 | Blockage of bile ducts 12 | Infections 13 | Medicines 14 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Sinusitis.txt: -------------------------------------------------------------------------------- 1 | Sinusitis is generally triggered by a viral upper respiratory tract infection, with only 2% of cases being complicated by bacterial sinusitis.2 About 90% of patients in the United States are estimated to receive an antibiotic from their general practitioner, yet in most cases the condition resolves without antibiotics, even if it is bacterial in origin.3 Most general practitioners rely on clinical findings to make the diagnosis. Signs and symptoms of acute bacterial sinusitis and those of a prolonged viral upper respiratory tract infection are closely similar, resulting in frequent misclassification of viral cases as bacterial sinusitis. Boxes 1 and 2 list common and rarer causes of rhinosinusitis. 2 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease descriptions/Tuberculosis.txt: -------------------------------------------------------------------------------- 1 | Tuberculosis (TB) is a potentially serious infectious disease that mainly affects your lungs. The bacteria that cause tuberculosis are spread from one person to another through tiny droplets released into the air via coughs and sneezes. 2 | 3 | Many strains of tuberculosis resist the drugs most used to treat the disease. People with active tuberculosis must take several types of medications for many months to eradicate the infection and prevent development of antibiotic resistance. 4 | 5 | Although your body may harbor the bacteria that cause tuberculosis, your immune system usually can prevent you from becoming sick. For this reason, doctors make a distinction between: 6 | 7 | Latent TB. In this condition, you have a TB infection, but the bacteria remain in your body in an inactive state and cause no symptoms. Latent TB, also called inactive TB or TB infection, isn't contagious. It can turn into active TB, so treatment is important for the person with latent TB and to help control the spread of TB. An estimated 2 billion people have latent TB. 8 | 9 | Active TB. This condition makes you sick and can spread to others. It can occur in the first few weeks after infection with the TB bacteria, or it might occur years later. 10 | 11 | Although tuberculosis is contagious, it's not easy to catch. You're much more likely to get tuberculosis from someone you live with or work with than from a stranger. Most people with active TB who've had appropriate drug treatment for at least two weeks are no longer contagious. 12 | 13 | The most commonly used diagnostic tool for tuberculosis is a simple skin test, though blood tests are becoming more commonplace. A small amount of a substance called PPD tuberculin is injected just below the skin of your inside forearm. You should feel only a slight needle prick. 14 | 15 | Within 48 to 72 hours, a health care professional will check your arm for swelling at the injection site. A hard, raised red bump means you're likely to have TB infection. The size of the bump determines whether the test results are significant. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Alzheimers.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | no 8 | high 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Arthritis.txt: -------------------------------------------------------------------------------- 1 | no 2 | high 3 | no 4 | no 5 | no 6 | no 7 | low 8 | no 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Asthma.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | high 4 | high 5 | no 6 | no 7 | no 8 | low 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Coronavirus.txt: -------------------------------------------------------------------------------- 1 | high 2 | no 3 | high 4 | high 5 | no 6 | high 7 | high 8 | no 9 | no 10 | high 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Diabetes.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | high 8 | no 9 | no 10 | no 11 | no 12 | low 13 | low -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Epilepsy.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | low 8 | no 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Glaucoma.txt: -------------------------------------------------------------------------------- 1 | low 2 | no 3 | no 4 | no 5 | no 6 | no 7 | no 8 | no 9 | no 10 | no 11 | no 12 | high 13 | low -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Heart Disease.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | high 4 | no 5 | no 6 | no 7 | no 8 | no 9 | no 10 | no 11 | no 12 | high 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Heat Stroke.txt: -------------------------------------------------------------------------------- 1 | high 2 | no 3 | no 4 | no 5 | no 6 | no 7 | no 8 | no 9 | no 10 | high 11 | no 12 | high 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Hyperthyroidism.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | high 8 | no 9 | no 10 | no 11 | no 12 | low 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Hypothermia.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | yes 6 | no 7 | no 8 | no 9 | high 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Jaundice.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | high 8 | no 9 | no 10 | low 11 | no 12 | high 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Sinusitis.txt: -------------------------------------------------------------------------------- 1 | low 2 | no 3 | no 4 | high 5 | no 6 | high 7 | no 8 | no 9 | no 10 | low 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease symptoms/Tuberculosis.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | high 4 | low 5 | no 6 | no 7 | no 8 | no 9 | no 10 | high 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Alzheimers.txt: -------------------------------------------------------------------------------- 1 | No treatments stop or reverse its progression, though some may temporarily improve symptoms but medication and management strategies may temporarily improve symptoms. 2 | 3 | Medication: 4 | 5 | Cognition-enhancing medication 6 | Improves mental function, lowers blood pressure and may balance mood. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Arthritis.txt: -------------------------------------------------------------------------------- 1 | Arthritis treatment focuses on relieving symptoms and improving joint function. You may need to try several different treatments, or combinations of treatments, before you determine what works best for you. 2 | 3 | Medications 4 | The medications used to treat arthritis vary depending on the type of arthritis. Commonly used arthritis medications include: 5 | 6 | Analgesics. These medications help reduce pain, but have no effect on inflammation. 7 | 8 | Nonsteroidal anti-inflammatory drugs (NSAIDs). NSAIDs reduce both pain and inflammation. Over-the-counter NSAIDs include ibuprofen and naproxen sodium. Oral NSAIDs can cause stomach irritation, and some may increase your risk of heart attack or stroke. 9 | 10 | Disease-modifying antirheumatic drugs (DMARDs). Often used to treat rheumatoid arthritis, DMARDs slow or stop your immune system from attacking your joints. 11 | 12 | Therapy 13 | Physical therapy can be helpful for some types of arthritis. Exercises can improve range of motion and strengthen the muscles surrounding joints. In some cases, splints or braces may be warranted. 14 | 15 | Surgery 16 | 17 | If conservative measures don't help, your doctor may suggest surgery, such as: 18 | 19 | Joint repair. In some instances, joint surfaces can be smoothed or realigned to reduce pain and improve function. These types of procedures can often be performed arthroscopically — through small incisions over the joint. 20 | 21 | Joint replacement. This procedure removes your damaged joint and replaces it with an artificial one. Joints most commonly replaced are hips and knees. 22 | 23 | Joint fusion. This procedure is more often used for smaller joints, such as those in the wrist, ankle and fingers. It removes the ends of the two bones in the joint and then locks those ends together until they heal into one rigid unit. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Asthma.txt: -------------------------------------------------------------------------------- 1 | There is no cure for asthma. 2 | 3 | Symptoms can be prevented by avoiding triggers, such as allergens and irritants, and by the use of inhaled corticosteroids. 4 | 5 | Anti-inflammatory drugs, particularly inhaled steroids, are the most important treatment for most people with asthma. 6 | 7 | Bronchodilators relieve the symptoms of asthma by relaxing the muscles that can tighten around the airways. This helps to open up the airways. 8 | 9 | Short-acting bronchodilator inhalers are often referred to as rescue inhalers and are used to quickly relieve the cough, wheeze, chest tightness, and shortness of breath caused by asthma 10 | 11 | Long-acting beta agonists (LABA) or antileukotriene agents may be used in addition to inhaled corticosteroids if asthma symptoms remain uncontrolled. 12 | 13 | Treatment of rapidly worsening symptoms is usually with an inhaled short-acting beta-2 agonist such as salbutamol and corticosteroids taken by mouth. In very severe cases, intravenous corticosteroids, magnesium sulfate, and hospitalization may be required. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Coronavirus.txt: -------------------------------------------------------------------------------- 1 | The disease will last around 14 days during which you must quarantine yourself to prevent others from being infected. 2 | 3 | Prevention: 4 | The best way to prevent and slow down transmission is to be well informed about the COVID-19 virus, the disease it causes and how it spreads. Protect yourself and others from infection by washing your hands or using an alcohol based rub frequently and not touching your face. 5 | 6 | Vaccines have also been produced which protects you from few common variants of the disease. Getting yourself vaccinated also prevents the infection. 7 | 8 | Treatments for this disease include: 9 | 10 | Medicines: 11 | Remdesvir 12 | Bamlanivimab 13 | Etesevimab 14 | Casirivimab 15 | Imdevimab 16 | 17 | This disease affects your lungs and might give you trouble breathing. Hence, supplemental oxygen and mechanical ventilatory support will also help in case you have difficulties in breathing. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Diabetes.txt: -------------------------------------------------------------------------------- 1 | Patients with type 1 diabetes will need to take insulin injections for the rest of their life. They must also ensure proper blood-glucose levels by carrying out regular blood tests and following a special diet. 2 | 3 | Type 2 patients need to eat healthily, be physically active, and test their blood glucose. They may also need to take oral medication, and/or insulin to control blood glucose levels. 4 | 5 | Treatment for type 1 diabetes includes: 6 | 7 | Taking insulin 8 | Carbohydrate, fat and protein counting 9 | Frequent blood sugar monitoring 10 | Eating healthy foods 11 | Exercising regularly and maintaining a healthy weight 12 | 13 | Types of insulin are many and include: 14 | 15 | Short-acting (regular) insulin 16 | Rapid-acting insulin 17 | Intermediate-acting (NPH) insulin 18 | Long-acting insulin 19 | 20 | Other Medications: 21 | 22 | High blood pressure medications 23 | Aspirin 24 | Cholesterol-lowering drugs 25 | 26 | Treatment for type 2 diabetes includes: 27 | 28 | Healthy eating 29 | Regular exercise 30 | Possibly, diabetes medication or insulin therapy 31 | Blood sugar monitoring 32 | 33 | Examples of possible treatments for type 2 diabetes include: 34 | 35 | Metformin (Glucophage, Glumetza, others) 36 | Sulfonylureas 37 | Meglitinides 38 | Thiazolidinediones 39 | Insulin therapy -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Epilepsy.txt: -------------------------------------------------------------------------------- 1 | Treatment with medications or sometimes surgery can control seizures for the majority of people with epilepsy. 2 | 3 | Some people require lifelong treatment to control seizures, but for others, the seizures eventually go away. Some children with epilepsy may outgrow the condition with age. 4 | 5 | Medication: 6 | 7 | Epilepsy medications, sometimes called anti-seizure or anticonvulsant medications, change the way your brain cells work and send messages to each other. 8 | 9 | The kind of medication depends on: 10 | 11 | The type of seizures 12 | Frequency of seizures 13 | Age 14 | Sex 15 | Other medical conditions 16 | 17 | General Medications are: 18 | 19 | Carbamazepine (Tegretol or Carbatrol) 20 | Divalproex (depakote, Depakote ER) 21 | Diazepam (Valium and similar tranquilizers) 22 | Ethosuximide (Zarontin) 23 | Phenytoin (Dilantin or Phenytek) 24 | Phenobarbital 25 | Primidone (Mysoline) 26 | Valproic acid (Depakene) -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Glaucoma.txt: -------------------------------------------------------------------------------- 1 | Vision loss due to glaucoma can't be recovered. 2 | 3 | Prevention: 4 | Get regular eye exams that include measurements of your eye pressure. 5 | If glaucoma is recognized early, vision loss can be slowed or prevented. life. 6 | 7 | Treatments for Glaucoma include: 8 | 9 | Medicines: 10 | 11 | Medicines, in the form of eyedrops or pills, are the most common early treatment for glaucoma. 12 | 13 | Taken regularly, these eyedrops lower eye pressure. Some medicines cause the eye to make less fluid. Others lower pressure by helping fluid drain from the eye. 14 | 15 | Laser trabeculoplasty: 16 | 17 | Laser trabeculoplasty helps fluid drain out of the eye. Your doctor may suggest this step at any time. In many cases, medicines still need to be taken after the procedure. 18 | 19 | If glaucoma is present in both eyes, usually only one eye will be treated at a time. Laser treatments for each eye will be scheduled several days to several weeks apart. 20 | 21 | Conventional surgery: 22 | Conventional surgery makes a new opening for the fluid to leave the eye. Conventional surgery often is done after medicines and laser surgery have failed to control pressure -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Heart Disease.txt: -------------------------------------------------------------------------------- 1 | Prevention: 2 | 3 | Certain types of heart disease, such as heart defects, can't be prevented. However, you can help prevent many other types of heart disease by making the same lifestyle changes that can improve your heart disease, such as: 4 | 5 | Quit smoking 6 | Control other health conditions, such as high blood pressure, high cholesterol and diabetes 7 | Exercise at least 30 minutes a day on most days of the week 8 | Eat a diet that's low in salt and saturated fat 9 | Maintain a healthy weight 10 | Reduce and manage stress 11 | Practice good hygiene 12 | 13 | Medications: 14 | 15 | ACE Inhibitors 16 | Antiarrhythmics 17 | Beta-Blocker Therapy 18 | Digoxin 19 | Diuretics -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Heat Stroke.txt: -------------------------------------------------------------------------------- 1 | Prevention: 2 | 3 | Heatstroke is predictable and preventable. 4 | 5 | Wearing excess clothing or clothing that fits tightly won't allow your body to cool properly. 6 | 7 | Protect against sunburn. Sunburn affects the body's ability to cool itself, so protect yourself outdoors with a wide-brimmed hat and sunglasses and use a broad-spectrum sunscreen with an SPF of at least 15. 8 | 9 | Drink plenty of fluids. Staying hydrated will help your body sweat and maintain a normal body temperature.. 10 | 11 | Treatments: 12 | 13 | The underlying cause must be removed. Mild hyperthemia caused by exertion on a hot day may be adequately treated through self-care measures, such as increased water consumption and resting in a cool place. 14 | 15 | Heat stroke that results from drug exposure requires prompt cessation of that drug, and occasionally the use of other drugs as counter measures. Antipyretics (e.g., acetaminophen, aspirin, other nonsteroidal anti-inflammatory drugs) have no role in the treatment of heatstroke because antipyretics interrupt the change in the hypothalamic set point caused by pyrogens; they are not expected to work on a healthy hypothalamus that has been overloaded, as in the case of heatstroke. 16 | 17 | In this situation, antipyretics actually may be harmful in patients who develop hepatic, hematologic, and renal complications because they may aggravate bleeding tendencies. 18 | 19 | When body temperature is significantly elevated, mechanical cooling methods are used to remove heat and to restore the body's ability to regulate its own temperatures. 20 | 21 | Passive cooling techniques, such as resting in a cool, shady area and removing clothing can be applied immediately. Active cooling methods, such as sponging the head, neck, and trunk with cool water, remove heat from the body and thereby speed the body's return to normal temperatures. Drinking water and turning a fan or dehumidifying air conditioning unit on the affected person may improve the effectiveness of the body's evaporative cooling mechanisms (sweating). -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Hyperthyroidism.txt: -------------------------------------------------------------------------------- 1 | Treatment 2 | 3 | Several treatments for hyperthyroidism exist. The best approach depends on age, physical condition, the underlying cause of the hyperthyroidism, personal preference and the severity of disorder: 4 | 5 | Radioactive iodine. Taken by mouth, radioactive iodine is absorbed by thyroid gland, where it causes the gland to shrink and symptoms to subside, usually within three to six months. Because this treatment causes thyroid activity to slow considerably, causing the thyroid gland to be underactive (hypothyroidism), you may eventually need to take medication every day to replace thyroxine. 6 | 7 | Anti-thyroid medications. These medications gradually reduce symptoms of hyperthyroidism by preventing thyroid gland from producing excess amounts of hormones. They include propylthiouracil and methimazole (Tapazole). Both drugs can cause serious liver damage, sometimes leading to death. 8 | 9 | Beta blockers. These drugs are commonly used to treat high blood pressure. They won't reduce thyroid levels, but they can reduce a rapid heart rate and help prevent palpitations. 10 | 11 | Surgery (thyroidectomy). If patients can't tolerate anti-thyroid drugs and don't want to or can't have radioactive iodine therapy, they may be a candidate for thyroid surgery. 12 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Hypothermia.txt: -------------------------------------------------------------------------------- 1 | Depending on the severity of hypothermia, emergency medical care for hypothermia may include one of the following interventions to raise the body temperature: 2 | 3 | Passive rewarming: For someone with mild hypothermia, it is enough to cover them with heated blankets and offer warm fluids to drink. 4 | 5 | Blood rewarming : Blood may be drawn, warmed and recirculated in the body. A common method of warming blood is the use of a hemodialysis machine, which is normally used to filter blood in people with poor kidney function. Heart bypass machines also may need to be used. 6 | 7 | Warm intravenous fluids: A warmed intravenous solution of salt water may be put into a vein to help warm the blood. 8 | 9 | Airway rewarming: The use of humidified oxygen administered with a mask or nasal tube can warm the airways and help raise the temperature of the body. 10 | 11 | Irrigation: A warm saltwater solution may be used to warm certain areas of the body, such as the area around the lungs (pleura) or the abdominal cavity (peritoneal cavity). The warm liquid is introduced into the affected area with catheters. 12 | 13 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Jaundice.txt: -------------------------------------------------------------------------------- 1 | Jaundice is treated by managing the underlying cause. 2 | 3 | Medication: 4 | 5 | Medication or supplements can help jaundice depending on the cause. 6 | Treatment will depend on the underlying cause. 7 | 8 | Jaundice treatment targets the cause rather than the jaundice symptoms. 9 | 10 | The following treatments are used: 11 | 12 | Anemia-induced jaundice may be treated by boosting the amount of iron in the blood by either taking iron supplements or eating more iron-rich foods. 13 | Hepatitis-induced jaundice requires antiviral or steroid medications. 14 | Doctors can treat obstruction-induced jaundice by surgically removing the obstruction. 15 | 16 | If the jaundice has been caused by use of a medication, treatment for involves changing to an alternative medication. -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Sinusitis.txt: -------------------------------------------------------------------------------- 1 | Prevention: 2 | 3 | Take these steps to help reduce your risk of getting acute sinusitis: 4 | 5 | Avoid upper respiratory infections. Minimize contact with people who have colds. Wash your hands frequently with soap and water, especially before your meals. 6 | 7 | Manage your allergies. 8 | 9 | Avoid cigarette smoke and polluted air. Tobacco smoke and other pollutants can irritate and inflame your lungs and nasal passages. 10 | 11 | Use a humidifier. If the air in your home is dry, such as it is if you have forced-air heat, adding moisture to the air may help prevent sinusitis. Be sure the humidifier stays clean and free of mold with regular, thorough cleaning. 12 | 13 | Treatment: 14 | 15 | Using a nasal decongestant spray, such as oxymetazoline, can help relieve sinus infection symptoms short-term. 16 | 17 | Other over-the-counter medicines that contain antihistamines and decongestants can help with sinus infections, particularly if you also suffer from allergies. 18 | 19 | Medications: 20 | 21 | Sudafed 22 | Zyrtec 23 | Allegra 24 | Claritin 25 | 26 | -------------------------------------------------------------------------------- /case studies projects/expertsys/Disease treatments/Tuberculosis.txt: -------------------------------------------------------------------------------- 1 | Medications are the cornerstone of tuberculosis treatment. 2 | 3 | Medications are the cornerstone of tuberculosis treatment. But treating TB takes much longer than treating other types of bacterial infections. 4 | 5 | With tuberculosis, you must take antibiotics for at least six to nine months. The exact drugs and length of treatment depend on your age, overall health, possible drug resistance, the form of TB (latent or active) and the infection's location in the body. 6 | 7 | Four months instead of nine — with combined medication may be effective in keeping latent TB from becoming active TB. With the shorter course of treatment, people are more likely to take all their medication, and the risk of side effects is lessened. 8 | 9 | The most common medications used to treat tuberculosis include: 10 | Isoniazid 11 | Rifampin (Rifadin, Rimactane) 12 | Ethambutol (Myambutol) 13 | Pyrazinamide 14 | 15 | If you have drug-resistant TB, a combination of antibiotics called fluoroquinolones and injectable medications, such as amikacin, kanamycin or capreomycin, are generally used for 20 to 30 months. Some types of TB are developing resistance to these medications as well. -------------------------------------------------------------------------------- /case studies projects/expertsys/diseases.txt: -------------------------------------------------------------------------------- 1 | Jaundice 2 | Alzheimers 3 | Arthritis 4 | Tuberculosis 5 | Asthma 6 | Sinusitis 7 | Epilepsy 8 | Heart Disease 9 | Diabetes 10 | Glaucoma 11 | Hyperthyroidism 12 | Heat Stroke 13 | Hypothermia 14 | Coronavirus -------------------------------------------------------------------------------- /case studies projects/expertsys/main.py: -------------------------------------------------------------------------------- 1 | from greetings import Greetings 2 | diseases_list = [] 3 | diseases_symptoms = [] 4 | symptom_map = {} 5 | d_desc_map = {} 6 | d_treatment_map = {} 7 | 8 | #loads the knowledge from .txt files into variables to allow the code to use it 9 | def preprocess(): 10 | #global diseases_list, diseases_symptoms, symptom_map, d_desc_map, d_treatment_map 11 | diseases = open("diseases.txt") 12 | diseases_t = diseases.read() 13 | diseases_list = diseases_t.split("\n") 14 | diseases.close() 15 | 16 | for disease in diseases_list: 17 | disease_s_file = open("Disease symptoms/" + disease + ".txt") 18 | disease_s_data = disease_s_file.read() 19 | s_list = disease_s_data.split("\n") 20 | diseases_symptoms.append(s_list) 21 | symptom_map[str(s_list)] = disease 22 | disease_s_file.close() 23 | 24 | disease_s_file = open("Disease descriptions/" + disease + ".txt") 25 | disease_s_data = disease_s_file.read() 26 | d_desc_map[disease] = disease_s_data 27 | disease_s_file.close() 28 | 29 | disease_s_file = open("Disease treatments/" + disease + ".txt") 30 | disease_s_data = disease_s_file.read() 31 | d_treatment_map[disease] = disease_s_data 32 | disease_s_file.close() 33 | 34 | 35 | def identify_disease(*arguments): 36 | symptom_list = [] 37 | for symptom in arguments: 38 | symptom_list.append(symptom) 39 | 40 | return symptom_map[str(symptom_list)] 41 | 42 | 43 | def get_details(disease): 44 | return d_desc_map[disease] 45 | 46 | 47 | def get_treatments(disease): 48 | return d_treatment_map[disease] 49 | 50 | 51 | def if_not_matched(disease): 52 | print("") 53 | id_disease = disease 54 | disease_details = get_details(id_disease) 55 | treatments = get_treatments(id_disease) 56 | print("") 57 | print("The most probable disease that you have is %s\n" % (id_disease)) 58 | print("A short description of the disease is given below :\n") 59 | print(disease_details + "\n") 60 | print( 61 | "The common medications and procedures suggested by other real doctors are: \n" 62 | ) 63 | print(treatments + "\n") 64 | 65 | 66 | if __name__ == "__main__": 67 | preprocess() 68 | #creating class object 69 | engine = Greetings(symptom_map, if_not_matched, get_treatments, get_details) 70 | #loop to keep running the code until user says no when asked for another diagnosis 71 | while 1: 72 | engine.reset() 73 | engine.run() 74 | print("Would you like to diagnose some other symptoms?\n Reply yes or no") 75 | if input() == "no": 76 | exit() 77 | -------------------------------------------------------------------------------- /case studies projects/expertsys/requirements.txt: -------------------------------------------------------------------------------- 1 | experta 2 | -------------------------------------------------------------------------------- /case studies projects/gamebot tic tac toe/GamebotTicTacToe.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 10, 20 | "metadata": { 21 | "id": "gAj13mtMLNl7" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "import numpy as np\n", 26 | "import random\n", 27 | "\n", 28 | "class TicTacToe:\n", 29 | " def __init__(self, state=None):\n", 30 | " self.board = np.zeros((3, 3)) if state is None else np.array(state)\n", 31 | " self.players = [\"X\", \"O\"]\n", 32 | " self.current_player = self.players[0]\n", 33 | " self.winner = None\n", 34 | " self.game_over = False\n", 35 | "\n", 36 | " def make_move(self, move):\n", 37 | " if self.board[move[0]][move[1]] != 0:\n", 38 | " return self.board, -10, self.game_over # Invalid move penalty\n", 39 | " self.board[move[0]][move[1]] = self.players.index(self.current_player) + 1\n", 40 | " self.check_winner()\n", 41 | " reward = 1 if self.winner else 0\n", 42 | " self.switch_player()\n", 43 | " return self.board, reward, self.game_over\n", 44 | "\n", 45 | " def reset(self):\n", 46 | " self.board = np.zeros((3, 3))\n", 47 | " self.current_player = self.players[0]\n", 48 | " self.winner = None\n", 49 | " self.game_over = False\n", 50 | "\n", 51 | " def available_moves(self):\n", 52 | " return [(i, j) for i in range(3) for j in range(3) if self.board[i][j] == 0]\n", 53 | "\n", 54 | " def switch_player(self):\n", 55 | " self.current_player = self.players[1] if self.current_player == self.players[0] else self.players[0]\n", 56 | "\n", 57 | " def check_winner(self):\n", 58 | " for i in range(3):\n", 59 | " if self.board[i][0] == self.board[i][1] == self.board[i][2] != 0:\n", 60 | " self.winner = self.players[int(self.board[i][0] - 1)]\n", 61 | " self.game_over = True\n", 62 | " for j in range(3):\n", 63 | " if self.board[0][j] == self.board[1][j] == self.board[2][j] != 0:\n", 64 | " self.winner = self.players[int(self.board[0][j] - 1)]\n", 65 | " self.game_over = True\n", 66 | " if self.board[0][0] == self.board[1][1] == self.board[2][2] != 0:\n", 67 | " self.winner = self.players[int(self.board[0][0] - 1)]\n", 68 | " self.game_over = True\n", 69 | " if self.board[0][2] == self.board[1][1] == self.board[2][0] != 0:\n", 70 | " self.winner = self.players[int(self.board[0][2] - 1)]\n", 71 | " self.game_over = True\n", 72 | " if not any(0 in row for row in self.board):\n", 73 | " self.game_over = True\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "source": [ 79 | "class QLearningAgent:\n", 80 | " def __init__(self, alpha, epsilon, discount_factor):\n", 81 | " self.Q = {}\n", 82 | " self.alpha = alpha\n", 83 | " self.epsilon = epsilon\n", 84 | " self.discount_factor = discount_factor\n", 85 | "\n", 86 | " def get_Q_value(self, state, action):\n", 87 | " if (tuple(state.flatten()), action) not in self.Q:\n", 88 | " self.Q[(tuple(state.flatten()), action)] = 0.0\n", 89 | " return self.Q[(tuple(state.flatten()), action)]\n", 90 | "\n", 91 | " def choose_action(self, state, available_moves):\n", 92 | " if random.uniform(0, 1) < self.epsilon:\n", 93 | " return random.choice(available_moves)\n", 94 | " else:\n", 95 | " Q_values = [self.get_Q_value(state, action) for action in available_moves]\n", 96 | " max_Q = max(Q_values)\n", 97 | " best_moves = [action for action, Q_value in zip(available_moves, Q_values) if Q_value == max_Q]\n", 98 | " return random.choice(best_moves)\n", 99 | "\n", 100 | " def update_Q_value(self, state, action, reward, next_state, next_available_moves):\n", 101 | " current_Q = self.get_Q_value(state, action)\n", 102 | " if next_available_moves:\n", 103 | " next_Q = max([self.get_Q_value(next_state, next_action) for next_action in next_available_moves])\n", 104 | " else:\n", 105 | " next_Q = 0\n", 106 | " self.Q[(tuple(state.flatten()), action)] = current_Q + self.alpha * (reward + self.discount_factor * next_Q - current_Q)\n" 107 | ], 108 | "metadata": { 109 | "id": "EnfOad8bLQH3" 110 | }, 111 | "execution_count": 6, 112 | "outputs": [] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "source": [ 117 | "def train(num_episodes, alpha, epsilon, discount_factor):\n", 118 | " agent = QLearningAgent(alpha, epsilon, discount_factor)\n", 119 | " for _ in range(num_episodes):\n", 120 | " game = TicTacToe()\n", 121 | " state = game.board\n", 122 | " while not game.game_over:\n", 123 | " available_moves = game.available_moves()\n", 124 | " action = agent.choose_action(state, available_moves)\n", 125 | " next_state, reward, game_over = game.make_move(action)\n", 126 | " agent.update_Q_value(state, action, reward, next_state, game.available_moves())\n", 127 | " state = next_state\n", 128 | " return agent\n" 129 | ], 130 | "metadata": { 131 | "id": "EQffk0u3LSiJ" 132 | }, 133 | "execution_count": 7, 134 | "outputs": [] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "source": [ 139 | "def test(agent, num_games):\n", 140 | " num_wins = 0\n", 141 | " num_draws = 0\n", 142 | " num_losses = 0\n", 143 | "\n", 144 | " for _ in range(num_games):\n", 145 | " game = TicTacToe()\n", 146 | " state = game.board\n", 147 | " while not game.game_over:\n", 148 | " if game.current_player == \"X\": # Assume agent is always \"X\"\n", 149 | " action = agent.choose_action(state, game.available_moves())\n", 150 | " else:\n", 151 | " action = random.choice(game.available_moves()) # Random opponent\n", 152 | "\n", 153 | " state, reward, game_over = game.make_move(action)\n", 154 | "\n", 155 | " if game.winner == \"X\": # Agent wins\n", 156 | " num_wins += 1\n", 157 | " elif game.winner == \"O\": # Agent loses\n", 158 | " num_losses += 1\n", 159 | " else: # No winner (draw)\n", 160 | " num_draws += 1\n", 161 | "\n", 162 | " win_rate = num_wins / num_games * 100\n", 163 | " draw_rate = num_draws / num_games * 100\n", 164 | " loss_rate = num_losses / num_games * 100\n", 165 | "\n", 166 | " return win_rate, draw_rate, loss_rate\n" 167 | ], 168 | "metadata": { 169 | "id": "CHzLofYFLUkY" 170 | }, 171 | "execution_count": 8, 172 | "outputs": [] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "source": [ 177 | "# Parameters\n", 178 | "num_episodes = 100000\n", 179 | "alpha = 0.5\n", 180 | "epsilon = 0.1\n", 181 | "discount_factor = 1.0\n", 182 | "num_games = 1000\n", 183 | "\n", 184 | "# Train the Q-learning agent\n", 185 | "agent = train(num_episodes, alpha, epsilon, discount_factor)\n", 186 | "\n", 187 | "# Test the Q-learning agent\n", 188 | "win_rate, draw_rate, loss_rate = test(agent, num_games)\n", 189 | "\n", 190 | "# Display results\n", 191 | "print(f\"Win Rate: {win_rate:.2f}%\")\n", 192 | "print(f\"Draw Rate: {draw_rate:.2f}%\")\n", 193 | "print(f\"Loss Rate: {loss_rate:.2f}%\")\n" 194 | ], 195 | "metadata": { 196 | "colab": { 197 | "base_uri": "https://localhost:8080/" 198 | }, 199 | "id": "jEhMoQ9lLWgQ", 200 | "outputId": "8ac64294-5680-414e-ad8b-0a708fcb067a" 201 | }, 202 | "execution_count": 11, 203 | "outputs": [ 204 | { 205 | "output_type": "stream", 206 | "name": "stdout", 207 | "text": [ 208 | "Win Rate: 59.50%\n", 209 | "Draw Rate: 13.70%\n", 210 | "Loss Rate: 26.80%\n" 211 | ] 212 | } 213 | ] 214 | } 215 | ] 216 | } -------------------------------------------------------------------------------- /case studies projects/gamebot tic tac toe/TicTacToe.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import random 4 | class TicTacToe: 5 | def __init__(self): 6 | self.board = np.zeros((3, 3)) 7 | self.players = ["X", "O"] 8 | self.current_player = None 9 | self.winner = None 10 | self.game_over = False 11 | 12 | def reset(self): 13 | self.board = np.zeros((3, 3)) 14 | self.current_player = None 15 | self.winner = None 16 | self.game_over = False 17 | 18 | def available_moves(self): 19 | moves = [] 20 | for i in range(3): 21 | for j in range(3): 22 | if self.board[i][j] == 0: 23 | moves.append((i, j)) 24 | return moves 25 | 26 | def make_move(self, move): 27 | if self.board[move[0]][move[1]] != 0: 28 | return False 29 | self.board[move[0]][move[1]] = self.players.index(self.current_player) + 1 30 | self.check_winner() 31 | self.switch_player() 32 | return True 33 | 34 | def switch_player(self): 35 | if self.current_player == self.players[0]: 36 | self.current_player = self.players[1] 37 | else: 38 | self.current_player = self.players[0] 39 | 40 | def check_winner(self): 41 | # Check rows 42 | for i in range(3): 43 | if self.board[i][0] == self.board[i][1] == self.board[i][2] != 0: 44 | self.winner = self.players[int(self.board[i][0] - 1)] 45 | self.game_over = True 46 | # Check columns 47 | for j in range(3): 48 | if self.board[0][j] == self.board[1][j] == self.board[2][j] != 0: 49 | self.winner = self.players[int(self.board[0][j] - 1)] 50 | self.game_over = True 51 | # Check diagonals 52 | if self.board[0][0] == self.board[1][1] == self.board[2][2] != 0: 53 | self.winner = self.players[int(self.board[0][0] - 1)] 54 | self.game_over = True 55 | if self.board[0][2] == self.board[1][1] == self.board[2][0] != 0: 56 | self.winner = self.players[int(self.board[0][2] - 1)] 57 | self.game_over = True 58 | 59 | def print_board(self): 60 | print("-------------") 61 | for i in range(3): 62 | print("|", end=" ") 63 | for j in range(3): 64 | print(self.players[int(self.board[i][j] - 1)] if self.board[i][j] != 0 else " ", end="|") 65 | print() 66 | print("-------------") 67 | 68 | 69 | game = TicTacToe() 70 | game.current_player = game.players[0] 71 | game.print_board() 72 | 73 | while not game.game_over: 74 | move = input(f"{game.current_player}''s turn. Enter row and column (e.g. 0 0): ") 75 | move = tuple(map(int, move.split())) 76 | while move not in game.available_moves(): 77 | move = input("Invalid move. Try again: ") 78 | move = tuple(map(int, move.split())) 79 | game.make_move(move) 80 | game.print_board() 81 | 82 | if game.winner: 83 | print(f"{game.winner} wins!") 84 | else: 85 | print("It''s a tie!") 86 | -------------------------------------------------------------------------------- /case studies projects/gamebot tic tac toe/interactivegame.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import random 3 | 4 | # TicTacToe Class 5 | class TicTacToe: 6 | def __init__(self, state=None): 7 | self.board = np.zeros((3, 3)) if state is None else np.array(state) 8 | self.players = ["X", "O"] 9 | self.current_player = self.players[0] 10 | self.winner = None 11 | self.game_over = False 12 | 13 | def make_move(self, move): 14 | if self.board[move[0]][move[1]] != 0: 15 | return self.board, -10, self.game_over # Invalid move penalty 16 | self.board[move[0]][move[1]] = self.players.index(self.current_player) + 1 17 | self.check_winner() 18 | reward = 1 if self.winner else 0 19 | self.switch_player() 20 | return self.board, reward, self.game_over 21 | 22 | def reset(self): 23 | self.board = np.zeros((3, 3)) 24 | self.current_player = self.players[0] 25 | self.winner = None 26 | self.game_over = False 27 | 28 | def available_moves(self): 29 | return [(i, j) for i in range(3) for j in range(3) if self.board[i][j] == 0] 30 | 31 | def switch_player(self): 32 | self.current_player = self.players[1] if self.current_player == self.players[0] else self.players[0] 33 | 34 | def check_winner(self): 35 | for i in range(3): 36 | if self.board[i][0] == self.board[i][1] == self.board[i][2] != 0: 37 | self.winner = self.players[int(self.board[i][0] - 1)] 38 | self.game_over = True 39 | for j in range(3): 40 | if self.board[0][j] == self.board[1][j] == self.board[2][j] != 0: 41 | self.winner = self.players[int(self.board[0][j] - 1)] 42 | self.game_over = True 43 | if self.board[0][0] == self.board[1][1] == self.board[2][2] != 0: 44 | self.winner = self.players[int(self.board[0][0] - 1)] 45 | self.game_over = True 46 | if self.board[0][2] == self.board[1][1] == self.board[2][0] != 0: 47 | self.winner = self.players[int(self.board[0][2] - 1)] 48 | self.game_over = True 49 | if not any(0 in row for row in self.board): 50 | self.game_over = True 51 | 52 | def print_board(self): 53 | print("-------------") 54 | for i in range(3): 55 | print("|", end=" ") 56 | for j in range(3): 57 | print(self.players[int(self.board[i][j] - 1)] if self.board[i][j] != 0 else " ", end=" | ") 58 | print("\n-------------") 59 | 60 | # Q-Learning Agent 61 | class QLearningAgent: 62 | def __init__(self, alpha, epsilon, discount_factor): 63 | self.Q = {} 64 | self.alpha = alpha 65 | self.epsilon = epsilon 66 | self.discount_factor = discount_factor 67 | 68 | def get_Q_value(self, state, action): 69 | if (tuple(state.flatten()), action) not in self.Q: 70 | self.Q[(tuple(state.flatten()), action)] = 0.0 71 | return self.Q[(tuple(state.flatten()), action)] 72 | 73 | def choose_action(self, state, available_moves): 74 | if random.uniform(0, 1) < self.epsilon: 75 | return random.choice(available_moves) 76 | else: 77 | Q_values = [self.get_Q_value(state, action) for action in available_moves] 78 | max_Q = max(Q_values) 79 | best_moves = [action for action, Q_value in zip(available_moves, Q_values) if Q_value == max_Q] 80 | return random.choice(best_moves) 81 | 82 | def update_Q_value(self, state, action, reward, next_state, next_available_moves): 83 | current_Q = self.get_Q_value(state, action) 84 | if next_available_moves: 85 | next_Q = max([self.get_Q_value(next_state, next_action) for next_action in next_available_moves]) 86 | else: 87 | next_Q = 0 88 | self.Q[(tuple(state.flatten()), action)] = current_Q + self.alpha * (reward + self.discount_factor * next_Q - current_Q) 89 | 90 | # Train the Q-learning Agent 91 | def train(num_episodes, alpha, epsilon, discount_factor): 92 | agent = QLearningAgent(alpha, epsilon, discount_factor) 93 | for _ in range(num_episodes): 94 | game = TicTacToe() 95 | state = game.board 96 | while not game.game_over: 97 | available_moves = game.available_moves() 98 | action = agent.choose_action(state, available_moves) 99 | next_state, reward, game_over = game.make_move(action) 100 | agent.update_Q_value(state, action, reward, next_state, game.available_moves()) 101 | state = next_state 102 | return agent 103 | 104 | # Play with the Agent 105 | def play_with_agent(agent): 106 | game = TicTacToe() 107 | print("Let's play Tic Tac Toe!") 108 | print("You are 'O'. The agent is 'X'.") 109 | game.print_board() 110 | 111 | while not game.game_over: 112 | if game.current_player == "O": # Your turn 113 | try: 114 | move = input("Enter your move (row col, e.g., 0 0): ") 115 | move = tuple(map(int, move.split())) 116 | while move not in game.available_moves(): 117 | print("Invalid move. Try again.") 118 | move = input("Enter your move (row col, e.g., 0 0): ") 119 | move = tuple(map(int, move.split())) 120 | _, _, _ = game.make_move(move) 121 | except ValueError: 122 | print("Invalid input. Please enter row and column numbers separated by a space.") 123 | continue 124 | else: # Agent's turn 125 | print("Agent's turn...") 126 | action = agent.choose_action(game.board, game.available_moves()) 127 | _, _, _ = game.make_move(action) 128 | 129 | game.print_board() 130 | 131 | if game.winner: 132 | if game.winner == "X": 133 | print("The agent wins! Better luck next time.") 134 | else: 135 | print("Congratulations! You win!") 136 | else: 137 | print("It's a draw!") 138 | 139 | # Main Program 140 | if __name__ == "__main__": 141 | # Train the Q-learning agent 142 | trained_agent = train(num_episodes=100000, alpha=0.5, epsilon=0.1, discount_factor=1.0) 143 | 144 | # Play interactively with the trained agent 145 | play_with_agent(trained_agent) 146 | -------------------------------------------------------------------------------- /case studies projects/gamebot tic tac toe/readme.txt: -------------------------------------------------------------------------------- 1 | Open your terminal or command prompt and run the following commands: 2 | 3 | pip install tensorflow 4 | pip install numpy 5 | 6 | import them into our Python script. Open your Python IDE or text editor and create a new Python file. Start by importing the required libraries: 7 | 8 | import tensorflow as tf 9 | import numpy as np 10 | import random -------------------------------------------------------------------------------- /classifierss/ML/ML notes/Unit-4MLl.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/classifierss/ML/ML notes/Unit-4MLl.pptx -------------------------------------------------------------------------------- /classifierss/programs/.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /decisiontree/iris/iris.csv: -------------------------------------------------------------------------------- 1 | sepal_length,sepal_width,petal_length,petal_width,species 2 | 5.1,3.5,1.4,0.2,setosa 3 | 4.9,3,1.4,0.2,setosa 4 | 4.7,3.2,1.3,0.2,setosa 5 | 4.6,3.1,1.5,0.2,setosa 6 | 5,3.6,1.4,0.2,setosa 7 | 5.4,3.9,1.7,0.4,setosa 8 | 4.6,3.4,1.4,0.3,setosa 9 | 5,3.4,1.5,0.2,setosa 10 | 4.4,2.9,1.4,0.2,setosa 11 | 4.9,3.1,1.5,0.1,setosa 12 | 5.4,3.7,1.5,0.2,setosa 13 | 4.8,3.4,1.6,0.2,setosa 14 | 4.8,3,1.4,0.1,setosa 15 | 4.3,3,1.1,0.1,setosa 16 | 5.8,4,1.2,0.2,setosa 17 | 5.7,4.4,1.5,0.4,setosa 18 | 5.4,3.9,1.3,0.4,setosa 19 | 5.1,3.5,1.4,0.3,setosa 20 | 5.7,3.8,1.7,0.3,setosa 21 | 5.1,3.8,1.5,0.3,setosa 22 | 5.4,3.4,1.7,0.2,setosa 23 | 5.1,3.7,1.5,0.4,setosa 24 | 4.6,3.6,1,0.2,setosa 25 | 5.1,3.3,1.7,0.5,setosa 26 | 4.8,3.4,1.9,0.2,setosa 27 | 5,3,1.6,0.2,setosa 28 | 5,3.4,1.6,0.4,setosa 29 | 5.2,3.5,1.5,0.2,setosa 30 | 5.2,3.4,1.4,0.2,setosa 31 | 4.7,3.2,1.6,0.2,setosa 32 | 4.8,3.1,1.6,0.2,setosa 33 | 5.4,3.4,1.5,0.4,setosa 34 | 5.2,4.1,1.5,0.1,setosa 35 | 5.5,4.2,1.4,0.2,setosa 36 | 4.9,3.1,1.5,0.1,setosa 37 | 5,3.2,1.2,0.2,setosa 38 | 5.5,3.5,1.3,0.2,setosa 39 | 4.9,3.1,1.5,0.1,setosa 40 | 4.4,3,1.3,0.2,setosa 41 | 5.1,3.4,1.5,0.2,setosa 42 | 5,3.5,1.3,0.3,setosa 43 | 4.5,2.3,1.3,0.3,setosa 44 | 4.4,3.2,1.3,0.2,setosa 45 | 5,3.5,1.6,0.6,setosa 46 | 5.1,3.8,1.9,0.4,setosa 47 | 4.8,3,1.4,0.3,setosa 48 | 5.1,3.8,1.6,0.2,setosa 49 | 4.6,3.2,1.4,0.2,setosa 50 | 5.3,3.7,1.5,0.2,setosa 51 | 5,3.3,1.4,0.2,setosa 52 | 7,3.2,4.7,1.4,versicolor 53 | 6.4,3.2,4.5,1.5,versicolor 54 | 6.9,3.1,4.9,1.5,versicolor 55 | 5.5,2.3,4,1.3,versicolor 56 | 6.5,2.8,4.6,1.5,versicolor 57 | 5.7,2.8,4.5,1.3,versicolor 58 | 6.3,3.3,4.7,1.6,versicolor 59 | 4.9,2.4,3.3,1,versicolor 60 | 6.6,2.9,4.6,1.3,versicolor 61 | 5.2,2.7,3.9,1.4,versicolor 62 | 5,2,3.5,1,versicolor 63 | 5.9,3,4.2,1.5,versicolor 64 | 6,2.2,4,1,versicolor 65 | 6.1,2.9,4.7,1.4,versicolor 66 | 5.6,2.9,3.6,1.3,versicolor 67 | 6.7,3.1,4.4,1.4,versicolor 68 | 5.6,3,4.5,1.5,versicolor 69 | 5.8,2.7,4.1,1,versicolor 70 | 6.2,2.2,4.5,1.5,versicolor 71 | 5.6,2.5,3.9,1.1,versicolor 72 | 5.9,3.2,4.8,1.8,versicolor 73 | 6.1,2.8,4,1.3,versicolor 74 | 6.3,2.5,4.9,1.5,versicolor 75 | 6.1,2.8,4.7,1.2,versicolor 76 | 6.4,2.9,4.3,1.3,versicolor 77 | 6.6,3,4.4,1.4,versicolor 78 | 6.8,2.8,4.8,1.4,versicolor 79 | 6.7,3,5,1.7,versicolor 80 | 6,2.9,4.5,1.5,versicolor 81 | 5.7,2.6,3.5,1,versicolor 82 | 5.5,2.4,3.8,1.1,versicolor 83 | 5.5,2.4,3.7,1,versicolor 84 | 5.8,2.7,3.9,1.2,versicolor 85 | 6,2.7,5.1,1.6,versicolor 86 | 5.4,3,4.5,1.5,versicolor 87 | 6,3.4,4.5,1.6,versicolor 88 | 6.7,3.1,4.7,1.5,versicolor 89 | 6.3,2.3,4.4,1.3,versicolor 90 | 5.6,3,4.1,1.3,versicolor 91 | 5.5,2.5,4,1.3,versicolor 92 | 5.5,2.6,4.4,1.2,versicolor 93 | 6.1,3,4.6,1.4,versicolor 94 | 5.8,2.6,4,1.2,versicolor 95 | 5,2.3,3.3,1,versicolor 96 | 5.6,2.7,4.2,1.3,versicolor 97 | 5.7,3,4.2,1.2,versicolor 98 | 5.7,2.9,4.2,1.3,versicolor 99 | 6.2,2.9,4.3,1.3,versicolor 100 | 5.1,2.5,3,1.1,versicolor 101 | 5.7,2.8,4.1,1.3,versicolor 102 | 6.3,3.3,6,2.5,virginica 103 | 5.8,2.7,5.1,1.9,virginica 104 | 7.1,3,5.9,2.1,virginica 105 | 6.3,2.9,5.6,1.8,virginica 106 | 6.5,3,5.8,2.2,virginica 107 | 7.6,3,6.6,2.1,virginica 108 | 4.9,2.5,4.5,1.7,virginica 109 | 7.3,2.9,6.3,1.8,virginica 110 | 6.7,2.5,5.8,1.8,virginica 111 | 7.2,3.6,6.1,2.5,virginica 112 | 6.5,3.2,5.1,2,virginica 113 | 6.4,2.7,5.3,1.9,virginica 114 | 6.8,3,5.5,2.1,virginica 115 | 5.7,2.5,5,2,virginica 116 | 5.8,2.8,5.1,2.4,virginica 117 | 6.4,3.2,5.3,2.3,virginica 118 | 6.5,3,5.5,1.8,virginica 119 | 7.7,3.8,6.7,2.2,virginica 120 | 7.7,2.6,6.9,2.3,virginica 121 | 6,2.2,5,1.5,virginica 122 | 6.9,3.2,5.7,2.3,virginica 123 | 5.6,2.8,4.9,2,virginica 124 | 7.7,2.8,6.7,2,virginica 125 | 6.3,2.7,4.9,1.8,virginica 126 | 6.7,3.3,5.7,2.1,virginica 127 | 7.2,3.2,6,1.8,virginica 128 | 6.2,2.8,4.8,1.8,virginica 129 | 6.1,3,4.9,1.8,virginica 130 | 6.4,2.8,5.6,2.1,virginica 131 | 7.2,3,5.8,1.6,virginica 132 | 7.4,2.8,6.1,1.9,virginica 133 | 7.9,3.8,6.4,2,virginica 134 | 6.4,2.8,5.6,2.2,virginica 135 | 6.3,2.8,5.1,1.5,virginica 136 | 6.1,2.6,5.6,1.4,virginica 137 | 7.7,3,6.1,2.3,virginica 138 | 6.3,3.4,5.6,2.4,virginica 139 | 6.4,3.1,5.5,1.8,virginica 140 | 6,3,4.8,1.8,virginica 141 | 6.9,3.1,5.4,2.1,virginica 142 | 6.7,3.1,5.6,2.4,virginica 143 | 6.9,3.1,5.1,2.3,virginica 144 | 5.8,2.7,5.1,1.9,virginica 145 | 6.8,3.2,5.9,2.3,virginica 146 | 6.7,3.3,5.7,2.5,virginica 147 | 6.7,3,5.2,2.3,virginica 148 | 6.3,2.5,5,1.9,virginica 149 | 6.5,3,5.2,2,virginica 150 | 6.2,3.4,5.4,2.3,virginica 151 | 5.9,3,5.1,1.8,virginica 152 | -------------------------------------------------------------------------------- /decisiontree/studentt/student_dataset.csv: -------------------------------------------------------------------------------- 1 | Grades,Attendance,Study Hours,Label 2 | 46,0.62,2,Weak 3 | 59,0.71,3,Weak 4 | 54,0.67,3,Weak 5 | 50,0.62,3,Weak 6 | 47,0.6,4,Weak 7 | 46,0.62,4,Weak 8 | 58,0.64,3,Weak 9 | 50,0.74,4,Weak 10 | 50,0.73,1,Weak 11 | 43,0.62,1,Weak 12 | 47,0.6,4,Weak 13 | 42,0.64,4,Weak 14 | 41,0.73,3,Weak 15 | 51,0.66,2,Weak 16 | 45,0.68,4,Weak 17 | 41,0.74,1,Weak 18 | 40,0.74,3,Weak 19 | 51,0.69,4,Weak 20 | 51,0.72,1,Weak 21 | 56,0.78,1,Weak 22 | 49,0.66,2,Weak 23 | 55,0.76,3,Weak 24 | 54,0.79,3,Weak 25 | 54,0.63,2,Weak 26 | 58,0.64,2,Weak 27 | 51,0.66,3,Weak 28 | 59,0.72,3,Weak 29 | 42,0.74,4,Weak 30 | 44,0.7,4,Weak 31 | 58,0.63,2,Weak 32 | 46,0.72,4,Weak 33 | 48,0.66,1,Weak 34 | 46,0.78,4,Weak 35 | 57,0.61,4,Weak 36 | 43,0.69,1,Weak 37 | 53,0.72,2,Weak 38 | 57,0.65,1,Weak 39 | 48,0.71,4,Weak 40 | 41,0.71,2,Weak 41 | 59,0.79,4,Weak 42 | 54,0.7,1,Weak 43 | 46,0.66,1,Weak 44 | 51,0.6,4,Weak 45 | 47,0.6,3,Weak 46 | 54,0.79,3,Weak 47 | 42,0.72,1,Weak 48 | 53,0.68,1,Weak 49 | 56,0.62,3,Weak 50 | 43,0.66,3,Weak 51 | 57,0.65,4,Weak 52 | 47,0.67,4,Weak 53 | 43,0.68,3,Weak 54 | 41,0.64,4,Weak 55 | 45,0.6,4,Weak 56 | 49,0.78,2,Weak 57 | 43,0.69,4,Weak 58 | 57,0.71,1,Weak 59 | 51,0.74,4,Weak 60 | 41,0.68,4,Weak 61 | 49,0.79,3,Weak 62 | 43,0.76,1,Weak 63 | 53,0.76,4,Weak 64 | 55,0.79,4,Weak 65 | 54,0.71,2,Weak 66 | 47,0.66,4,Weak 67 | 53,0.61,4,Weak 68 | 47,0.62,2,Weak 69 | 55,0.76,3,Weak 70 | 52,0.64,4,Weak 71 | 57,0.76,2,Weak 72 | 54,0.76,1,Weak 73 | 52,0.76,3,Weak 74 | 48,0.61,1,Weak 75 | 54,0.61,1,Weak 76 | 52,0.64,2,Weak 77 | 40,0.6,4,Weak 78 | 46,0.6,2,Weak 79 | 48,0.78,2,Weak 80 | 40,0.61,2,Weak 81 | 51,0.71,2,Weak 82 | 47,0.65,3,Weak 83 | 50,0.63,4,Weak 84 | 58,0.7,1,Weak 85 | 56,0.76,1,Weak 86 | 47,0.65,4,Weak 87 | 42,0.64,1,Weak 88 | 42,0.79,4,Weak 89 | 40,0.61,1,Weak 90 | 44,0.65,2,Weak 91 | 49,0.7,1,Weak 92 | 46,0.75,4,Weak 93 | 48,0.75,4,Weak 94 | 46,0.6,4,Weak 95 | 48,0.68,4,Weak 96 | 47,0.65,4,Weak 97 | 51,0.75,3,Weak 98 | 41,0.62,3,Weak 99 | 40,0.79,1,Weak 100 | 55,0.63,4,Weak 101 | 44,0.78,1,Weak 102 | 95,0.8,5,Advanced 103 | 91,0.8,8,Advanced 104 | 98,0.94,5,Advanced 105 | 93,0.81,9,Advanced 106 | 85,0.95,7,Advanced 107 | 85,0.87,7,Advanced 108 | 92,0.92,5,Advanced 109 | 98,0.8,8,Advanced 110 | 87,0.95,8,Advanced 111 | 81,0.86,9,Advanced 112 | 80,0.84,5,Advanced 113 | 94,0.82,7,Advanced 114 | 80,0.91,8,Advanced 115 | 84,0.95,5,Advanced 116 | 95,0.98,8,Advanced 117 | 98,0.84,8,Advanced 118 | 83,0.93,7,Advanced 119 | 82,0.84,6,Advanced 120 | 96,0.94,9,Advanced 121 | 96,0.96,9,Advanced 122 | 91,0.93,7,Advanced 123 | 93,0.99,8,Advanced 124 | 85,0.84,5,Advanced 125 | 82,0.91,8,Advanced 126 | 88,0.95,7,Advanced 127 | 84,0.95,9,Advanced 128 | 96,0.86,8,Advanced 129 | 93,0.83,9,Advanced 130 | 82,0.8,5,Advanced 131 | 80,0.84,9,Advanced 132 | 99,0.89,9,Advanced 133 | 80,0.84,6,Advanced 134 | 82,0.83,6,Advanced 135 | 97,0.81,6,Advanced 136 | 89,0.99,9,Advanced 137 | 82,0.89,7,Advanced 138 | 87,0.98,9,Advanced 139 | 93,0.8,7,Advanced 140 | 97,0.84,7,Advanced 141 | 94,0.92,6,Advanced 142 | 81,0.83,8,Advanced 143 | 89,0.95,5,Advanced 144 | 81,0.95,6,Advanced 145 | 96,0.81,6,Advanced 146 | 87,0.96,8,Advanced 147 | 80,0.99,5,Advanced 148 | 88,0.91,9,Advanced 149 | 90,0.97,9,Advanced 150 | 95,0.82,6,Advanced 151 | 86,0.8,5,Advanced 152 | 89,0.8,6,Advanced 153 | 82,0.98,7,Advanced 154 | 97,0.9,6,Advanced 155 | 92,0.84,6,Advanced 156 | 86,0.91,9,Advanced 157 | 83,0.82,9,Advanced 158 | 92,0.8,9,Advanced 159 | 99,0.8,7,Advanced 160 | 80,0.87,9,Advanced 161 | 87,0.89,5,Advanced 162 | 93,0.9,8,Advanced 163 | 95,0.91,5,Advanced 164 | 93,0.92,5,Advanced 165 | 91,0.91,9,Advanced 166 | 98,0.93,8,Advanced 167 | 94,0.81,8,Advanced 168 | 81,0.98,8,Advanced 169 | 81,0.97,7,Advanced 170 | 98,0.82,9,Advanced 171 | 96,0.96,8,Advanced 172 | 99,0.87,7,Advanced 173 | 89,0.89,6,Advanced 174 | 85,0.81,6,Advanced 175 | 94,0.98,7,Advanced 176 | 90,0.88,7,Advanced 177 | 84,0.86,9,Advanced 178 | 80,0.83,9,Advanced 179 | 87,0.97,6,Advanced 180 | 91,0.92,8,Advanced 181 | 91,0.9,6,Advanced 182 | 84,0.83,8,Advanced 183 | 86,0.83,8,Advanced 184 | 83,0.89,9,Advanced 185 | 85,0.84,5,Advanced 186 | 92,0.88,5,Advanced 187 | 99,0.82,7,Advanced 188 | 94,0.96,9,Advanced 189 | 82,0.82,8,Advanced 190 | 87,0.95,5,Advanced 191 | 99,0.83,8,Advanced 192 | 95,0.97,5,Advanced 193 | 92,0.96,5,Advanced 194 | 97,0.86,5,Advanced 195 | 89,0.84,9,Advanced 196 | 98,0.91,6,Advanced 197 | 96,0.96,8,Advanced 198 | 98,0.92,9,Advanced 199 | 84,0.82,9,Advanced 200 | 88,0.88,9,Advanced 201 | 91,0.96,9,Advanced 202 | 75,0.86,5,Average 203 | 70,0.76,6,Average 204 | 64,0.81,4,Average 205 | 63,0.86,7,Average 206 | 62,0.82,4,Average 207 | 78,0.89,3,Average 208 | 79,0.73,3,Average 209 | 77,0.79,6,Average 210 | 74,0.72,5,Average 211 | 68,0.78,6,Average 212 | 76,0.82,6,Average 213 | 73,0.87,6,Average 214 | 74,0.84,6,Average 215 | 60,0.73,7,Average 216 | 62,0.84,7,Average 217 | 75,0.71,4,Average 218 | 70,0.84,3,Average 219 | 71,0.77,6,Average 220 | 69,0.77,4,Average 221 | 75,0.86,3,Average 222 | 67,0.81,5,Average 223 | 65,0.88,7,Average 224 | 71,0.79,3,Average 225 | 67,0.78,5,Average 226 | 63,0.74,3,Average 227 | 67,0.75,7,Average 228 | 77,0.89,7,Average 229 | 64,0.71,4,Average 230 | 68,0.82,6,Average 231 | 63,0.75,3,Average 232 | 76,0.74,3,Average 233 | 68,0.7,5,Average 234 | 60,0.75,7,Average 235 | 79,0.75,3,Average 236 | 72,0.85,7,Average 237 | 75,0.73,3,Average 238 | 72,0.8,4,Average 239 | 73,0.78,6,Average 240 | 62,0.72,3,Average 241 | 65,0.88,7,Average 242 | 77,0.77,4,Average 243 | 78,0.74,3,Average 244 | 64,0.73,5,Average 245 | 74,0.75,6,Average 246 | 61,0.71,3,Average 247 | 69,0.89,4,Average 248 | 77,0.8,5,Average 249 | 72,0.73,4,Average 250 | 64,0.84,4,Average 251 | 60,0.75,5,Average 252 | 60,0.86,4,Average 253 | 77,0.75,5,Average 254 | 74,0.88,3,Average 255 | 76,0.71,5,Average 256 | 70,0.84,5,Average 257 | 76,0.8,6,Average 258 | 72,0.77,5,Average 259 | 60,0.88,5,Average 260 | 61,0.82,3,Average 261 | 68,0.81,6,Average 262 | 62,0.74,7,Average 263 | 60,0.75,3,Average 264 | 75,0.73,3,Average 265 | 65,0.88,7,Average 266 | 76,0.89,5,Average 267 | 64,0.7,4,Average 268 | 64,0.89,6,Average 269 | 65,0.86,4,Average 270 | 62,0.81,7,Average 271 | 64,0.84,3,Average 272 | 64,0.7,3,Average 273 | 69,0.83,6,Average 274 | 69,0.75,3,Average 275 | 78,0.74,3,Average 276 | 76,0.8,6,Average 277 | 73,0.73,6,Average 278 | 68,0.82,7,Average 279 | 73,0.8,3,Average 280 | 60,0.72,3,Average 281 | 78,0.7,7,Average 282 | 72,0.75,5,Average 283 | 72,0.87,5,Average 284 | 63,0.79,5,Average 285 | 60,0.74,7,Average 286 | 76,0.79,3,Average 287 | 67,0.81,7,Average 288 | 61,0.71,7,Average 289 | 67,0.82,5,Average 290 | 66,0.77,4,Average 291 | 61,0.71,3,Average 292 | 62,0.89,5,Average 293 | 77,0.7,4,Average 294 | 71,0.74,4,Average 295 | 60,0.78,6,Average 296 | 71,0.86,3,Average 297 | 64,0.78,4,Average 298 | 76,0.8,5,Average 299 | 75,0.84,6,Average 300 | 74,0.75,3,Average 301 | 74,0.72,7,Average 302 | -------------------------------------------------------------------------------- /decisiontree/weightheight/weight_height_dataset.csv: -------------------------------------------------------------------------------- 1 | Height(cm),Weight(kg),Class 2 | 171.40842141405886,69.03793522418515,Normal 3 | 153.9356883748205,47.79750816218935,Underweight 4 | 176.5739605465234,78.87143757172358,Overweight 5 | 170.66309293452898,70.26371396688934,Normal 6 | 164.00991158352414,68.73092188134976,Normal 7 | 173.44241859624879,88.91073884868632,Overweight 8 | 163.74920615999537,50.765359854718305,Underweight 9 | 168.18508809416036,86.63466041920044,Overweight 10 | 176.46837222371582,94.48210900033776,Overweight 11 | 179.19893243003716,89.62551210259333,Overweight 12 | 160.6763726935085,54.375691156050706,Underweight 13 | 167.42811141946825,73.0143671453471,Overweight 14 | 176.29959819572287,89.70929285260712,Overweight 15 | 178.0929214774563,84.0105972470539,Overweight 16 | 179.17950293765037,73.92747510295575,Overweight 17 | 174.7015908552763,65.51753332837743,Normal 18 | 169.70103175214368,67.85839774940663,Normal 19 | 149.8235823314591,47.54574199801973,Underweight 20 | 156.64726061790495,51.33501568836588,Underweight 21 | 163.49009177813255,56.483631585023204,Underweight 22 | 175.92672590462342,90.02912227177642,Overweight 23 | 176.78619940643966,80.25518294981622,Overweight 24 | 174.74124701776603,76.43102519692924,Normal 25 | 155.75788390844104,58.2110953172147,Underweight 26 | 169.81707679208472,63.566726640049815,Normal 27 | 155.91766500624024,57.52736788905408,Underweight 28 | 164.02112789722804,73.49798234498755,Normal 29 | 161.62187889141128,61.06206644411448,Underweight 30 | 171.6508610367146,80.31854012189005,Normal 31 | 164.58206476005057,52.487562701302075,Underweight 32 | 172.34181224674202,78.37365643227365,Overweight 33 | 177.74052724115106,83.35217598359992,Overweight 34 | 176.02951157887244,87.21837051555906,Overweight 35 | 172.47630504897015,72.15234661733227,Normal 36 | 157.5739499235026,54.05477557647265,Underweight 37 | 165.7001368763758,75.4966454580681,Overweight 38 | 159.92421056492907,56.15337775131157,Underweight 39 | 158.3755095370378,58.46730067547198,Underweight 40 | 171.2405715879198,78.05587339394478,Overweight 41 | 178.80352145871564,78.96728306999789,Overweight 42 | 183.4530104304701,91.59540889848857,Overweight 43 | 176.98449931394606,73.46520436877996,Normal 44 | 172.1363972120299,74.38036976900261,Normal 45 | 178.7289549543317,88.05476013622345,Overweight 46 | 152.90595999074503,47.15876631240174,Underweight 47 | 164.18063100657278,76.22278601054832,Normal 48 | 164.41430531040547,67.0210196557641,Normal 49 | 162.39629054580354,58.6704856758808,Underweight 50 | 165.7153396398932,75.05365396874456,Normal 51 | 161.73707851333305,56.62133263077524,Underweight 52 | 162.4783342243884,56.19855741097601,Underweight 53 | 181.25867938737062,84.57916928295525,Overweight 54 | 168.40826349190468,85.27504182513367,Overweight 55 | 162.42543374354153,84.40788409013139,Overweight 56 | 149.28707126718763,52.88996268896349,Underweight 57 | 163.7418877784345,70.11308016321095,Normal 58 | 165.33654012395525,58.20604741195168,Underweight 59 | 168.22146971088148,64.1902401741075,Normal 60 | 170.91665483841646,78.38732340700841,Normal 61 | 163.1381875637279,68.49356681391482,Normal 62 | 183.99713192663788,81.74955428024067,Overweight 63 | 165.37378374913433,67.43270182644882,Normal 64 | 178.9174774717409,78.60497952058643,Overweight 65 | 181.0864988404095,81.01912456863327,Overweight 66 | 179.09816867647893,82.62936509548688,Overweight 67 | 178.81655777647816,74.59926247055799,Normal 68 | 174.90234347916285,80.13741853753817,Overweight 69 | 175.3194460992977,71.8105403566319,Normal 70 | 160.64871894379638,66.32700498026745,Normal 71 | 166.18355931955745,63.980636673706236,Normal 72 | 161.55655300228906,60.59962083454077,Underweight 73 | 167.68680538183213,70.32412408680035,Normal 74 | 166.24561600348142,75.30138703958129,Normal 75 | 167.99419229364617,76.50515360322176,Normal 76 | 160.87906907486632,50.71429490094916,Underweight 77 | 160.40065101688714,56.59619556222087,Underweight 78 | 171.38971981084688,68.77971957677816,Normal 79 | 166.25814786910712,71.75188510258884,Normal 80 | 169.96848569003492,73.90236290544661,Normal 81 | 167.04634566025086,72.40199190141377,Normal 82 | 172.88401677722388,77.3035986047819,Normal 83 | 174.1053837254244,82.96229336096873,Overweight 84 | 161.58688697358733,58.771700262086355,Underweight 85 | 174.7327601064552,62.695648105808345,Normal 86 | 179.74756995910064,68.89605142019884,Normal 87 | 161.5004104393108,62.33863895978806,Underweight 88 | 166.56614458049836,85.57250887255644,Overweight 89 | 153.53851565157154,53.333701700191845,Underweight 90 | 175.67835366117563,71.28954573632464,Normal 91 | 168.4648865959548,69.79340080873259,Normal 92 | 169.93166011006738,72.36111854091838,Normal 93 | 174.08679986430178,82.0233250757889,Overweight 94 | 175.3821698955031,90.03312901616759,Overweight 95 | 167.57751184035004,58.65516975322794,Underweight 96 | 167.93170718953814,76.30925142832601,Normal 97 | 155.28324309371436,60.973368862891796,Underweight 98 | 181.74454726140377,84.01863192504192,Overweight 99 | 154.5648666054243,65.0061305023216,Underweight 100 | 154.0387857658006,54.26362888352178,Underweight 101 | 159.6063870272737,44.449245519610926,Underweight 102 | 161.69991119571355,49.07026886428267,Underweight 103 | 164.53793065739848,52.75970261723595,Underweight 104 | 172.34733824158172,87.54532583981764,Overweight 105 | 164.08472448062165,50.906790746104335,Underweight 106 | 162.299133535788,69.27038479262654,Normal 107 | 166.03280394580827,89.23587444265618,Overweight 108 | 175.88442218064435,67.42049018636372,Normal 109 | 176.8141631470423,68.85005824965872,Normal 110 | 180.5386244684511,84.0702031583978,Overweight 111 | 157.74502078720343,46.9242848091674,Underweight 112 | 168.89097960522628,70.71671972914699,Normal 113 | 154.21804125243304,55.956514480764994,Underweight 114 | 167.10446855782547,63.629718436898564,Normal 115 | 171.81167728121352,82.2186145903011,Overweight 116 | 161.01720662786445,52.08543573171027,Underweight 117 | 167.53295343934533,90.41900545030555,Overweight 118 | 161.21521756716118,57.499162685980735,Underweight 119 | 151.98335797846877,59.47717192367854,Underweight 120 | 171.33392000943758,70.91290092577128,Normal 121 | 157.68010045334614,58.489886926603866,Underweight 122 | 167.18825788440108,72.8132552172219,Normal 123 | 157.3421056968414,60.0236875374849,Underweight 124 | 167.7454004486107,69.29138107363387,Normal 125 | 174.67324671640188,84.70585292341968,Overweight 126 | 159.94610555687603,62.654241725284024,Underweight 127 | 176.001961514746,96.25086403818688,Overweight 128 | 168.35713870094315,58.12581544359125,Underweight 129 | 165.9241124205252,66.63227682241427,Normal 130 | 161.80682965094587,62.9636574363919,Underweight 131 | 173.98034708456058,84.16231779237023,Overweight 132 | 153.86461657254378,58.24355606771714,Underweight 133 | 175.38251161545287,84.69894490155798,Overweight 134 | 179.3220714108819,96.83958410216694,Overweight 135 | 159.48586304133528,66.91255902878228,Normal 136 | 188.47592541859666,84.2193548248987,Overweight 137 | 172.43748965070412,85.87054460857944,Overweight 138 | 160.94944913133097,54.4995072368211,Underweight 139 | 171.45488728452023,73.0542144777422,Normal 140 | 155.1654130851605,60.403649548848946,Underweight 141 | 165.78244707012678,48.324324110844564,Underweight 142 | 158.46514326560495,56.11078569998022,Underweight 143 | 174.60406952405657,92.5926327724097,Overweight 144 | 179.5491292785509,81.26289004363545,Overweight 145 | 156.2018786546893,49.35552652311076,Underweight 146 | 178.53579583991774,83.1486430072168,Overweight 147 | 181.93316061060858,85.66030562293648,Overweight 148 | 166.0077582720072,73.99769918950743,Normal 149 | 158.38339633337836,55.46406471569268,Underweight 150 | 174.59690116346712,86.13027611862047,Overweight 151 | 176.32344043245718,89.02096199174483,Overweight 152 | -------------------------------------------------------------------------------- /hangman game/manual/__pycache__/hangman_art.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/hangman game/manual/__pycache__/hangman_art.cpython-312.pyc -------------------------------------------------------------------------------- /hangman game/manual/__pycache__/hangman_words.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/hangman game/manual/__pycache__/hangman_words.cpython-312.pyc -------------------------------------------------------------------------------- /hangman game/manual/hangman_art.py: -------------------------------------------------------------------------------- 1 | stages = [''' 2 | +---+ 3 | | | 4 | O | 5 | /|\ | 6 | / \ | 7 | | 8 | ========= 9 | ''', ''' 10 | +---+ 11 | | | 12 | O | 13 | /|\ | 14 | / | 15 | | 16 | ========= 17 | ''', ''' 18 | +---+ 19 | | | 20 | O | 21 | /|\ | 22 | | 23 | | 24 | ========= 25 | ''', ''' 26 | +---+ 27 | | | 28 | O | 29 | /| | 30 | | 31 | | 32 | =========''', ''' 33 | +---+ 34 | | | 35 | O | 36 | | | 37 | | 38 | | 39 | ========= 40 | ''', ''' 41 | +---+ 42 | | | 43 | O | 44 | | 45 | | 46 | | 47 | ========= 48 | ''', ''' 49 | +---+ 50 | | | 51 | | 52 | | 53 | | 54 | | 55 | ========= 56 | '''] 57 | 58 | logo = ''' 59 | _ 60 | | | 61 | | |__ __ _ _ __ __ _ _ __ ___ __ _ _ __ 62 | | '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ 63 | | | | | (_| | | | | (_| | | | | | | (_| | | | | 64 | |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| 65 | __/ | 66 | |___/ ''' 67 | 68 | 69 | -------------------------------------------------------------------------------- /hangman game/manual/hangman_words.py: -------------------------------------------------------------------------------- 1 | word_list = [ 2 | 'abruptly', 3 | 'absurd', 4 | 'abyss', 5 | 'affix', 6 | 'askew', 7 | 'avenue', 8 | 'awkward', 9 | 'axiom', 10 | 'azure', 11 | 'bagpipes', 12 | 'bandwagon', 13 | 'banjo', 14 | 'bayou', 15 | 'beekeeper', 16 | 'blitz', 17 | 'blizzard', 18 | 'boggle', 19 | 'bookworm', 20 | 'boxcar', 21 | 'boxful', 22 | 'buckaroo', 23 | 'buffalo', 24 | 'buffoon', 25 | 'buxom', 26 | 'buzzard', 27 | 'buzzing', 28 | 'buzzwords', 29 | 'caliph', 30 | 'cobweb', 31 | 'cockiness', 32 | 'croquet', 33 | 'crypt', 34 | 'curacao', 35 | 'cycle', 36 | 'daiquiri', 37 | 'dirndl', 38 | 'disavow', 39 | 'dizzying', 40 | 'duplex', 41 | 'dwarves', 42 | 'embezzle', 43 | 'equip', 44 | 'espionage', 45 | 'euouae', 46 | 'exodus', 47 | 'faking', 48 | 'fishhook', 49 | 'fixable', 50 | 'fjord', 51 | 'flapjack', 52 | 'flopping', 53 | 'fluffiness', 54 | 'flyby', 55 | 'foxglove', 56 | 'frazzled', 57 | 'frizzled', 58 | 'fuchsia', 59 | 'funny', 60 | 'gabby', 61 | 'galaxy', 62 | 'galvanize', 63 | 'gazebo', 64 | 'giaour', 65 | 'gizmo', 66 | 'glowworm', 67 | 'glyph', 68 | 'gnarly', 69 | 'gnostic', 70 | 'gossip', 71 | 'grogginess', 72 | 'haiku', 73 | 'haphazard', 74 | 'hyphen', 75 | 'iatrogenic', 76 | 'icebox', 77 | 'injury', 78 | 'ivory', 79 | 'ivy', 80 | 'jackpot', 81 | 'jaundice', 82 | 'jawbreaker', 83 | 'jaywalk', 84 | 'jazziest', 85 | 'jazzy', 86 | 'jelly', 87 | 'jigsaw', 88 | 'jinx', 89 | 'jiujitsu', 90 | 'jockey', 91 | 'jogging', 92 | 'joking', 93 | 'jovial', 94 | 'joyful', 95 | 'juicy', 96 | 'jukebox', 97 | 'jumbo', 98 | 'kayak', 99 | 'kazoo', 100 | 'keyhole', 101 | 'khaki', 102 | 'kilobyte', 103 | 'kiosk', 104 | 'kitsch', 105 | 'kiwifruit', 106 | 'klutz', 107 | 'knapsack', 108 | 'larynx', 109 | 'lengths', 110 | 'lucky', 111 | 'luxury', 112 | 'lymph', 113 | 'marquis', 114 | 'matrix', 115 | 'megahertz', 116 | 'microwave', 117 | 'mnemonic', 118 | 'mystify', 119 | 'naphtha', 120 | 'nightclub', 121 | 'nowadays', 122 | 'numbskull', 123 | 'nymph', 124 | 'onyx', 125 | 'ovary', 126 | 'oxidize', 127 | 'oxygen', 128 | 'pajama', 129 | 'peekaboo', 130 | 'phlegm', 131 | 'pixel', 132 | 'pizazz', 133 | 'pneumonia', 134 | 'polka', 135 | 'pshaw', 136 | 'psyche', 137 | 'puppy', 138 | 'puzzling', 139 | 'quartz', 140 | 'queue', 141 | 'quips', 142 | 'quixotic', 143 | 'quiz', 144 | 'quizzes', 145 | 'quorum', 146 | 'razzmatazz', 147 | 'rhubarb', 148 | 'rhythm', 149 | 'rickshaw', 150 | 'schnapps', 151 | 'scratch', 152 | 'shiv', 153 | 'snazzy', 154 | 'sphinx', 155 | 'spritz', 156 | 'squawk', 157 | 'staff', 158 | 'strength', 159 | 'strengths', 160 | 'stretch', 161 | 'stronghold', 162 | 'stymied', 163 | 'subway', 164 | 'swivel', 165 | 'syndrome', 166 | 'thriftless', 167 | 'thumbscrew', 168 | 'topaz', 169 | 'transcript', 170 | 'transgress', 171 | 'transplant', 172 | 'triphthong', 173 | 'twelfth', 174 | 'twelfths', 175 | 'unknown', 176 | 'unworthy', 177 | 'unzip', 178 | 'uptown', 179 | 'vaporize', 180 | 'vixen', 181 | 'vodka', 182 | 'voodoo', 183 | 'vortex', 184 | 'voyeurism', 185 | 'walkway', 186 | 'waltz', 187 | 'wave', 188 | 'wavy', 189 | 'waxy', 190 | 'wellspring', 191 | 'wheezy', 192 | 'whiskey', 193 | 'whizzing', 194 | 'whomever', 195 | 'wimpy', 196 | 'witchcraft', 197 | 'wizard', 198 | 'woozy', 199 | 'wristwatch', 200 | 'wyvern', 201 | 'xylophone', 202 | 'yachtsman', 203 | 'yippee', 204 | 'yoked', 205 | 'youthful', 206 | 'yummy', 207 | 'zephyr', 208 | 'zigzag', 209 | 'zigzagging', 210 | 'zilch', 211 | 'zipper', 212 | 'zodiac', 213 | 'zombie', 214 | ] 215 | -------------------------------------------------------------------------------- /hangman game/manual/hangmanv5.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | from hangman_words import word_list 4 | from hangman_art import stages,logo 5 | chosen_word=random.choice(word_list) 6 | #lives=6 if len(chosen_word) >= 6 else 6 7 | lives=6 8 | print(f'Pssst, the solution is {chosen_word}.') 9 | print(logo) 10 | print(len(stages)) 11 | display=[] 12 | guessed=[] 13 | for i in range(len(chosen_word)): 14 | 15 | display.append("_") 16 | while "_" in display and lives >0: 17 | guess=input("Guess a letter:").lower() 18 | if len(guess)==1 and guess.isalpha(): 19 | if guess in guessed: 20 | print("letter already present") 21 | continue 22 | guessed.append(guess) 23 | for i in range(len(chosen_word)): 24 | 25 | letter=chosen_word[i] 26 | 27 | if letter==guess: 28 | display[i]=letter 29 | if guess not in chosen_word: 30 | if lives > 0: 31 | lives=lives-1 32 | if lives==0: 33 | print(stages[lives]) 34 | print(f'the solution is {chosen_word}.') 35 | print("You loose") 36 | exit(1) 37 | print(f"{' '.join(display)}") 38 | print(lives) 39 | print(stages[lives]) 40 | else: 41 | print("guess should be a character rather than a word") 42 | 43 | else: 44 | print("You have won") 45 | 46 | -------------------------------------------------------------------------------- /nqueens/queen.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX = 20 # size of array 4 | self.A = [0]*self.MAX 5 | 6 | def placement(self,i,j): # to check if queen can be placed 7 | for k in range(1,i): 8 | if (self.A[k] == j) or abs(self.A[k] - j) == abs(k - i): 9 | return False 10 | print(self.A) 11 | return True 12 | 13 | def printplacedqueen(self,N): # method for print the placed Queen 14 | print('Arrangment--->') 15 | print() 16 | 17 | for i in range(1,N+1): 18 | for j in range(1,N+1): 19 | if self.A[i] != j: 20 | print('\t_',end =' ') 21 | else: 22 | print('\tQ',end =' ') 23 | print() 24 | print() 25 | 26 | def N_Queens(self,i,j): 27 | for k in range(1,N+1): 28 | if self.placement(i,k): 29 | self.A[i] = k 30 | if i == N: 31 | self.printplacedqueen(N) 32 | else: 33 | self.N_Queens(i+1,N) 34 | 35 | 36 | N = int(input("enter the queens value")) 37 | obj = solution() 38 | obj.N_Queens(1,N) -------------------------------------------------------------------------------- /pandas/pandas_d/dataset/car-sales.csv: -------------------------------------------------------------------------------- 1 | Make,Colour,Odometer (KM),Doors,Price 2 | Toyota,White,150043,4,"$4,000.00" 3 | Honda,Red,87899,4,"$5,000.00" 4 | Toyota,Blue,32549,3,"$7,000.00" 5 | BMW,Black,11179,5,"$22,000.00" 6 | Nissan,White,213095,4,"$3,500.00" 7 | Toyota,Green,99213,4,"$4,500.00" 8 | Honda,Blue,45698,4,"$7,500.00" 9 | Honda,Blue,54738,4,"$7,000.00" 10 | Toyota,White,60000,4,"$6,250.00" 11 | Nissan,White,31600,4,"$9,700.00" -------------------------------------------------------------------------------- /pandas/pandas_d/dataset/export_cars.csv: -------------------------------------------------------------------------------- 1 | Make,Colour,Odometer (KM),Doors,Price 2 | Toyota,White,150043,4,"$4,000.00" 3 | Honda,Red,87899,4,"$5,000.00" 4 | Toyota,Blue,32549,3,"$7,000.00" 5 | BMW,Black,11179,5,"$22,000.00" 6 | Nissan,White,213095,4,"$3,500.00" 7 | Toyota,Green,99213,4,"$4,500.00" 8 | Honda,Blue,45698,4,"$7,500.00" 9 | Honda,Blue,54738,4,"$7,000.00" 10 | Toyota,White,60000,4,"$6,250.00" 11 | Nissan,White,31600,4,"$9,700.00" 12 | -------------------------------------------------------------------------------- /prolog/cartypes.pl: -------------------------------------------------------------------------------- 1 | %facts 2 | owns(ashwin,car(bmw)). 3 | owns(hasan,car(toyota_camry)). 4 | owns(varshith,car(honda_civic)). 5 | owns(sainath,car(ford_focus)). 6 | owns(trishal,car(chevrolet_cruze)). 7 | owns(aryan,car(tesla_model_s)). 8 | 9 | 10 | %car types 11 | sedan(car(toyota_camry)). 12 | sedan(car(honda_civic)). 13 | sedan(car(chevrolet_cruze)). 14 | hatchback(car(ford_focus)). 15 | electric(car(tesla_model_s)). 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /prolog/cartypes.pl~: -------------------------------------------------------------------------------- 1 | %facts 2 | owns(ashwin,car(bmw)). 3 | owns(hasan,car(toyota_camry)). 4 | owns(varshith,car(honda_civic)). 5 | owns(sainath,car(ford_focus)). 6 | owns(trishal,car(chevrolet_cruze)). 7 | owns(aryan,car(tesla_model_s)). 8 | 9 | 10 | %car types 11 | sedan(car(toyota_camry)). 12 | sedan(car(honda_civic)). 13 | hatchback(car(ford_focus)). 14 | sedan(car(chevrolet_cruze)). 15 | electric(car(tesla_model_s)). 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /prolog/familytree.pl: -------------------------------------------------------------------------------- 1 | male(harivansh). 2 | male(amitabh). 3 | male(abhishek). 4 | female(teji). 5 | female(jaya). 6 | female(shweta). 7 | female(aishwarya). 8 | female(aradhya). 9 | 10 | parent(harivansh,amitabh). 11 | parent(teji,amitabh). 12 | parent(amitabh,abhishek). 13 | parent(amitabh,shweta). 14 | parent(jaya,abhishek). 15 | parent(jaya,shweta). 16 | parent(abhishek,aradhya). 17 | parent(aishwarya,aradhya). 18 | 19 | mother(M,C):-female(M),parent(M,C). 20 | father(F,C):-male(F),parent(F,C). 21 | son(S,P):-male(S),parent(P,S). 22 | daughter(D,P):-female(D), parent(P,D). 23 | brother(B,S):-male(B),parent(P,B),parent(P,S). 24 | sister(S,B):-female(S), parent(P,S), parent(P,B). 25 | grandfather(G,C):-male(G),parent(G,M),parent(M,C). 26 | grandmother(GM,C):-female(GM),parent(GM,M),parent(M,C). 27 | 28 | 29 | -------------------------------------------------------------------------------- /prolog/familytree.pl~: -------------------------------------------------------------------------------- 1 | male(harivansh). 2 | male(amitabh). 3 | male(abhishek). 4 | female(teji). 5 | female(jaya). 6 | female(shweta). 7 | female(aishwarya). 8 | female(aradhya). 9 | 10 | parent(harivansh,amitabh). 11 | parent(teji,amitabh). 12 | parent(amitabh,abhishek). 13 | parent(amitabh,shweta). 14 | parent(jaya,abhishek). 15 | parent(jaya,shweta). 16 | parent(abhishek,aradhya). 17 | parent(aishwarya,aradhya). 18 | 19 | mother(M,C):-female(M),parent(M,C). 20 | father(F,C):-male(F),parent(F,C). 21 | son(S,P):-male(S),parent(P,S). 22 | daughter(D,P):-female(D), parent(P,D). 23 | brother(B,S):-male(B),parent(P,B),parent(P,S). 24 | sister(S,B):-female(S), parent(P,S), parent(P,B). 25 | 26 | 27 | -------------------------------------------------------------------------------- /prolog/girlstudents.pl: -------------------------------------------------------------------------------- 1 | female(afreen). 2 | female(pranati). 3 | female(srivalli). 4 | 5 | student(afreen). 6 | student(pranati). 7 | student(srivalli). 8 | 9 | 10 | friend(afreen,pranati). 11 | friend(pranati,srivalli). 12 | friend(srivalli,afreen). 13 | friend(srivalli,pranati). 14 | 15 | 16 | friendly(Student):-female(Student),friend(Student,_). 17 | 18 | 19 | social(Student):- 20 | female(Student), 21 | findall(Friend,friend(Student, Friend),Friends), 22 | length(Friends,Count), 23 | Count>1. 24 | -------------------------------------------------------------------------------- /prolog/girlstudents.pl~: -------------------------------------------------------------------------------- 1 | female(afreen). 2 | female(pranati). 3 | female(srivalli). 4 | 5 | student(afreen). 6 | student(pranati). 7 | student(srivalli). 8 | 9 | 10 | friend(afreen,pranati). 11 | friend(pranati,srivalli). 12 | friend(srivalli,afreen). 13 | 14 | 15 | friendly(Student):-female(Student),friend(Student,_). 16 | 17 | 18 | social(Student):- 19 | female(Student), 20 | findall(Friend,friend(Student, Friend),Friends), 21 | length(Friends,Count), 22 | Count>1. 23 | -------------------------------------------------------------------------------- /prolog/outputcartypes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/prolog/outputcartypes.png -------------------------------------------------------------------------------- /prolog/outputgirlstudents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/prolog/outputgirlstudents.png -------------------------------------------------------------------------------- /prolog/prolog.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/prolog/prolog.pptx -------------------------------------------------------------------------------- /prolog/simplefacts.pl: -------------------------------------------------------------------------------- 1 | owns(hasan,car(bmw)). 2 | owns(sameer,car(chevy)). 3 | owns(mujeeb,car(civic)). 4 | owns(afzal,car(chevy)). 5 | sedan(car(bmw)). 6 | sedan(car(civic)). 7 | truck(car(chevy)). 8 | -------------------------------------------------------------------------------- /prolog/simplefacts.pl~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/prolog/simplefacts.pl~ -------------------------------------------------------------------------------- /pythonbasics/List.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "65bd71fd-ad1f-45cc-8137-4502756a841a", 6 | "metadata": {}, 7 | "source": [ 8 | "**list can store the data of any type. Lists are ordered and mutable(can be changed), which means you can change their contents (add, remove, or modify elements) after they are created.\n", 9 | "Python lists are defined using square brackets [] and can contain items separated by commas.**" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "id": "8dd913bb-4a8b-46a0-848c-2792c7f8f65b", 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "#mutable- can bechanged\n", 20 | "#immutable -- cant be changed" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "id": "fb9520e1-9c0c-408a-bcc6-c6bd9bf003e6", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "marks=[23,24,22,21]" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "id": "bfe5b8dc-87ea-4039-a637-c6313b2b9d92", 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "print(type(marks))" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "id": "944785bd-51ad-48b3-a997-cb224c777c4b", 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "data": { 59 | "text/plain": [ 60 | "24" 61 | ] 62 | }, 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "output_type": "execute_result" 66 | } 67 | ], 68 | "source": [ 69 | "marks[1]" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 4, 75 | "id": "8bf4f192-785a-4a3d-85b6-acef1416e4c1", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "23" 82 | ] 83 | }, 84 | "execution_count": 4, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "marks[0]" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 5, 96 | "id": "91922da1-0a6d-4844-a57d-a5ef10cdea17", 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "23\n", 104 | "24\n", 105 | "22\n", 106 | "21\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "for i in range(len(marks)):\n", 112 | " print(marks[i])" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 6, 118 | "id": "bc322851-8eab-49cd-bd73-48a6c7d22473", 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "ename": "IndexError", 123 | "evalue": "list assignment index out of range", 124 | "output_type": "error", 125 | "traceback": [ 126 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 127 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 128 | "Cell \u001b[1;32mIn[6], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m marks[\u001b[38;5;241m5\u001b[39m]\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m24\u001b[39m\n", 129 | "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" 130 | ] 131 | } 132 | ], 133 | "source": [ 134 | "marks[5]=24" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 8, 140 | "id": "0b5d2252-3ef6-4721-942c-0d841cdffdb2", 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "marks[3]=20" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 9, 150 | "id": "486885ec-5047-42e5-94dd-56a793a0d47b", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "[23, 24, 22, 20]" 157 | ] 158 | }, 159 | "execution_count": 9, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "marks" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 10, 171 | "id": "b4ac86be-0458-4e93-a4aa-cbda14a6cf0a", 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "marks[2]='AB'" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 11, 181 | "id": "293d1119-3022-4bbf-8b74-c702e1923370", 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "data": { 186 | "text/plain": [ 187 | "[23, 24, 'AB', 20]" 188 | ] 189 | }, 190 | "execution_count": 11, 191 | "metadata": {}, 192 | "output_type": "execute_result" 193 | } 194 | ], 195 | "source": [ 196 | "marks" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "id": "8b81d867-258c-49ee-becf-b8e77493734f", 202 | "metadata": {}, 203 | "source": [ 204 | "**In Python you can use list slicing to extract a section of a list by specifying a range of indices. The basic format, for list slicing is as follows;\n", 205 | "new_list = my_list[start:stop:step]\n", 206 | "start; This indicates the index at which the slicing begins (inclusive). If not provided it will start from the beginning of the list. stop; This indicates the index at which the slicing ends (exclusive). If not provided it will go until the end of the list. step; This specifies how much to increment or step through during slicing. If not provided it defaults to 1.\n", 207 | "This way you can easily extract subsets of data from a list using Pythons list slicing feature.**" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 13, 213 | "id": "bd554c6f-482b-443e-a5ef-f00b2341f645", 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "[23, 24, 'AB', 20]\n", 221 | "[24, 'AB']\n" 222 | ] 223 | } 224 | ], 225 | "source": [ 226 | "#Slicing\n", 227 | "print(marks)\n", 228 | "print(marks[1:3])" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 16, 234 | "id": "ce6abcf4-88d9-458b-8daf-1a4535b149f0", 235 | "metadata": {}, 236 | "outputs": [ 237 | { 238 | "name": "stdout", 239 | "output_type": "stream", 240 | "text": [ 241 | "[24, 'AB']\n" 242 | ] 243 | } 244 | ], 245 | "source": [ 246 | "print(marks[-3:-1])" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 17, 252 | "id": "18aacd9c-aa73-403d-bf35-0f62aa974705", 253 | "metadata": {}, 254 | "outputs": [ 255 | { 256 | "name": "stdout", 257 | "output_type": "stream", 258 | "text": [ 259 | "\n" 260 | ] 261 | } 262 | ], 263 | "source": [ 264 | "print(type(marks))" 265 | ] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "execution_count": 18, 270 | "id": "83bebe54-6884-4ff1-8271-e280524279ee", 271 | "metadata": {}, 272 | "outputs": [], 273 | "source": [ 274 | "subjects=[\"AI\",\"SE\",\"IRS\",\"DIP\"]" 275 | ] 276 | }, 277 | { 278 | "cell_type": "markdown", 279 | "id": "8d4ecdd5-ce0f-4df6-ab9c-48f558710407", 280 | "metadata": {}, 281 | "source": [ 282 | "**append() adds the list at the end of first list**" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 19, 288 | "id": "4959c835-5deb-4919-8d8f-dbb75ba80b84", 289 | "metadata": {}, 290 | "outputs": [], 291 | "source": [ 292 | "subjects.append(marks)" 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": 20, 298 | "id": "5a8303e7-4384-4c52-9880-3f8d0d7d5d34", 299 | "metadata": {}, 300 | "outputs": [ 301 | { 302 | "data": { 303 | "text/plain": [ 304 | "['AI', 'SE', 'IRS', 'DIP', [23, 24, 'AB', 20]]" 305 | ] 306 | }, 307 | "execution_count": 20, 308 | "metadata": {}, 309 | "output_type": "execute_result" 310 | } 311 | ], 312 | "source": [ 313 | "subjects" 314 | ] 315 | }, 316 | { 317 | "cell_type": "markdown", 318 | "id": "7284937b-8bc5-44ff-b68c-fc188b0f5939", 319 | "metadata": {}, 320 | "source": [ 321 | "**index() displays the index of the given element in the list**" 322 | ] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "execution_count": 21, 327 | "id": "6f0a949b-a278-4868-8b15-28ff71294597", 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "name": "stdout", 332 | "output_type": "stream", 333 | "text": [ 334 | "[23, 24, 'AB', 20]\n" 335 | ] 336 | } 337 | ], 338 | "source": [ 339 | "print(subjects[4])" 340 | ] 341 | }, 342 | { 343 | "cell_type": "markdown", 344 | "id": "8254bc46-58e0-41c9-b91f-6dbce7c239b9", 345 | "metadata": {}, 346 | "source": [ 347 | "**pop() removes the lasst element that has been added to the list**" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": 22, 353 | "id": "ad8685be-bfad-4431-a884-7a0ad5e54472", 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "name": "stdout", 358 | "output_type": "stream", 359 | "text": [ 360 | "[23, 24, 'AB', 20]\n" 361 | ] 362 | } 363 | ], 364 | "source": [ 365 | "print(subjects.pop())" 366 | ] 367 | }, 368 | { 369 | "cell_type": "code", 370 | "execution_count": 23, 371 | "id": "57b692e7-9aa7-45bf-a0ae-da86b0535a6d", 372 | "metadata": {}, 373 | "outputs": [ 374 | { 375 | "data": { 376 | "text/plain": [ 377 | "['AI', 'SE', 'IRS', 'DIP']" 378 | ] 379 | }, 380 | "execution_count": 23, 381 | "metadata": {}, 382 | "output_type": "execute_result" 383 | } 384 | ], 385 | "source": [ 386 | "subjects" 387 | ] 388 | }, 389 | { 390 | "cell_type": "markdown", 391 | "id": "0ef1cc4d-a7bd-4e08-8b8b-49c403419ff7", 392 | "metadata": {}, 393 | "source": [ 394 | "**count() counts the number of occurrence of the given element**" 395 | ] 396 | }, 397 | { 398 | "cell_type": "code", 399 | "execution_count": 24, 400 | "id": "272a964b-1887-4943-80f8-1bb0c39dc043", 401 | "metadata": {}, 402 | "outputs": [ 403 | { 404 | "name": "stdout", 405 | "output_type": "stream", 406 | "text": [ 407 | "1\n" 408 | ] 409 | } 410 | ], 411 | "source": [ 412 | "print(subjects.count('SE'))" 413 | ] 414 | }, 415 | { 416 | "cell_type": "code", 417 | "execution_count": null, 418 | "id": "afa0715a-d1f3-44f2-b9c1-01deaafae80d", 419 | "metadata": {}, 420 | "outputs": [], 421 | "source": [] 422 | } 423 | ], 424 | "metadata": { 425 | "kernelspec": { 426 | "display_name": "Python 3 (ipykernel)", 427 | "language": "python", 428 | "name": "python3" 429 | }, 430 | "language_info": { 431 | "codemirror_mode": { 432 | "name": "ipython", 433 | "version": 3 434 | }, 435 | "file_extension": ".py", 436 | "mimetype": "text/x-python", 437 | "name": "python", 438 | "nbconvert_exporter": "python", 439 | "pygments_lexer": "ipython3", 440 | "version": "3.11.7" 441 | } 442 | }, 443 | "nbformat": 4, 444 | "nbformat_minor": 5 445 | } 446 | -------------------------------------------------------------------------------- /students_contributions/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/students_contributions/1.png -------------------------------------------------------------------------------- /students_contributions/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/students_contributions/2.png -------------------------------------------------------------------------------- /students_contributions/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/students_contributions/3.png -------------------------------------------------------------------------------- /students_contributions/8puzzle (2).py: -------------------------------------------------------------------------------- 1 | from queue import PriorityQueue 2 | 3 | # Define the goal state for the 8-puzzle 4 | #GOAL_STATE = (1, 2, 3, 4, 5, 6, 7, 8, 0) 5 | GOAL_STATE = (1, 2, 3, 8,0,4,7,6,5) 6 | 7 | class PuzzleState: 8 | def __init__(self, board, empty_index, path_cost=0, parent=None): 9 | self.board = board 10 | self.empty_index = empty_index # Index of the empty space (0) 11 | self.path_cost = path_cost 12 | self.parent = parent 13 | 14 | def is_goal(self): 15 | return self.board == GOAL_STATE 16 | 17 | def generate_children(self): 18 | children = [] 19 | row, col = divmod(self.empty_index, 3) 20 | directions = { 21 | "up": (-1, 0), 22 | "down": (1, 0), 23 | "left": (0, -1), 24 | "right": (0, 1) 25 | } 26 | 27 | for direction, (dr, dc) in directions.items(): 28 | new_row, new_col = row + dr, col + dc 29 | if 0 <= new_row < 3 and 0 <= new_col < 3: 30 | new_index = new_row * 3 + new_col 31 | new_board = list(self.board) 32 | new_board[self.empty_index], new_board[new_index] = new_board[new_index], new_board[self.empty_index] 33 | children.append(PuzzleState(tuple(new_board), new_index, self.path_cost + 1, self)) 34 | 35 | return children 36 | 37 | def heuristic(self): 38 | distance = 0 39 | for index, value in enumerate(self.board): 40 | if value != 0: 41 | goal_index = value - 1 42 | goal_row, goal_col = divmod(goal_index, 3) 43 | current_row, current_col = divmod(index, 3) 44 | distance += abs(goal_row - current_row) + abs(goal_col - current_col) 45 | return distance 46 | 47 | def __lt__(self, other): 48 | return self.heuristic() < other.heuristic() 49 | 50 | def greedy_best_first_search(initial_board): 51 | initial_index = initial_board.index(0) 52 | initial_state = PuzzleState(tuple(initial_board), initial_index) 53 | 54 | if initial_state.is_goal(): 55 | return initial_state 56 | 57 | frontier = PriorityQueue() 58 | frontier.put(initial_state) 59 | explored = set() 60 | 61 | while not frontier.empty(): 62 | current_state = frontier.get() 63 | 64 | if current_state.is_goal(): 65 | return current_state 66 | 67 | explored.add(current_state.board) 68 | 69 | for child in current_state.generate_children(): 70 | if child.board not in explored: 71 | frontier.put(child) 72 | 73 | return None # No solution found 74 | 75 | def print_solution(solution): 76 | path = [] 77 | current_state = solution 78 | while current_state: 79 | path.append(current_state.board) 80 | current_state = current_state.parent 81 | for state in reversed(path): 82 | print(state) 83 | 84 | # Example usage 85 | initial_board = [2,8,3,1,6,4,7,0,5] 86 | # Initial configuration initial_board = [1, 2, 3, 4, 5, 6, 0, 7, 8] 87 | solution = greedy_best_first_search(initial_board) 88 | 89 | if solution: 90 | print("Solution found:") 91 | print_solution(solution) 92 | else: 93 | print("No solution found.") 94 | -------------------------------------------------------------------------------- /students_contributions/8puzzle.py: -------------------------------------------------------------------------------- 1 | from queue import PriorityQueue 2 | 3 | # Define the goal state for the 8-puzzle 4 | #GOAL_STATE = (1, 2, 3, 4, 5, 6, 7, 8, 0) 5 | GOAL_STATE = (1, 2, 3, 8,0,4,7,6,5) 6 | 7 | class PuzzleState: 8 | def __init__(self, board, empty_index, path_cost=0, parent=None): 9 | self.board = board 10 | self.empty_index = empty_index # Index of the empty space (0) 11 | self.path_cost = path_cost 12 | self.parent = parent 13 | 14 | def is_goal(self): 15 | return self.board == GOAL_STATE 16 | 17 | def generate_children(self): 18 | children = [] 19 | row, col = divmod(self.empty_index, 3) 20 | directions = { 21 | "up": (-1, 0), 22 | "down": (1, 0), 23 | "left": (0, -1), 24 | "right": (0, 1) 25 | } 26 | 27 | for direction, (dr, dc) in directions.items(): 28 | new_row, new_col = row + dr, col + dc 29 | if 0 <= new_row < 3 and 0 <= new_col < 3: 30 | new_index = new_row * 3 + new_col 31 | new_board = list(self.board) 32 | new_board[self.empty_index], new_board[new_index] = new_board[new_index], new_board[self.empty_index] 33 | children.append(PuzzleState(tuple(new_board), new_index, self.path_cost + 1, self)) 34 | 35 | return children 36 | 37 | def heuristic(self): 38 | distance = 0 39 | for index, value in enumerate(self.board): 40 | if value != 0: 41 | goal_index = value - 1 42 | goal_row, goal_col = divmod(goal_index, 3) 43 | current_row, current_col = divmod(index, 3) 44 | distance += abs(goal_row - current_row) + abs(goal_col - current_col) 45 | return distance 46 | 47 | def __lt__(self, other): 48 | return self.heuristic() < other.heuristic() 49 | 50 | def greedy_best_first_search(initial_board): 51 | initial_index = initial_board.index(0) 52 | initial_state = PuzzleState(tuple(initial_board), initial_index) 53 | 54 | if initial_state.is_goal(): 55 | return initial_state 56 | 57 | frontier = PriorityQueue() 58 | frontier.put(initial_state) 59 | explored = set() 60 | 61 | while not frontier.empty(): 62 | current_state = frontier.get() 63 | 64 | if current_state.is_goal(): 65 | return current_state 66 | 67 | explored.add(current_state.board) 68 | 69 | for child in current_state.generate_children(): 70 | if child.board not in explored: 71 | frontier.put(child) 72 | 73 | return None # No solution found 74 | 75 | def print_solution(solution): 76 | path = [] 77 | current_state = solution 78 | while current_state: 79 | path.append(current_state.board) 80 | current_state = current_state.parent 81 | for state in reversed(path): 82 | print(state) 83 | 84 | # Example usage 85 | initial_board = [2,8,3,1,6,4,7,0,5] 86 | # Initial configuration initial_board = [1, 2, 3, 4, 5, 6, 0, 7, 8] 87 | solution = greedy_best_first_search(initial_board) 88 | 89 | if solution: 90 | print("Solution found:") 91 | print_solution(solution) 92 | else: 93 | print("No solution found.") 94 | -------------------------------------------------------------------------------- /students_contributions/A star.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "fb25d436", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "graph=[['A','B',1,3],\n", 11 | " ['A','C',2,4],\n", 12 | " ['A','H',7,0],\n", 13 | " ['B','D',4,2],\n", 14 | " ['B','E',6,6],\n", 15 | " ['C','F',3,3],\n", 16 | " ['C','G',2,1],\n", 17 | " ['D','E',7,6],\n", 18 | " ['D','H',5,0],\n", 19 | " ['F','H',1,0],\n", 20 | " ['G','H',2,0]]" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "id": "5196a3c2", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "temp=[]\n", 31 | "temp1=[]\n", 32 | "for i in graph:\n", 33 | " temp.append(i[0])\n", 34 | " temp1.append(i[1])" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 4, 40 | "id": "292608a3", 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'F', 'G']\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "print(temp)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 6, 58 | "id": "9cde49e4", 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "['B', 'C', 'H', 'D', 'E', 'F', 'G', 'E', 'H', 'H', 'H']\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "print(temp1)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 8, 76 | "id": "67593824", 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "nodes=set(temp).union(set(temp1))" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 10, 86 | "id": "5670af8b", 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'}" 93 | ] 94 | }, 95 | "execution_count": 10, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "nodes" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 18, 107 | "id": "96d67253", 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [ 111 | "def A_star(graph, costs, open, closed, cur_node):\n", 112 | " if cur_node in open:\n", 113 | " open.remove(cur_node)\n", 114 | " closed.add(cur_node)\n", 115 | " for i in graph:\n", 116 | " #print(costs)\n", 117 | " if(i[0]==cur_node and costs[i[0]]+i[2]+i[3]'+i[1]\n", 121 | " costs[cur_node]=999999\n", 122 | " small=min(costs, key=costs.get)\n", 123 | " if small not in closed:\n", 124 | " A_star(graph, costs, open, closed, small)\n", 125 | "costs=dict()\n", 126 | "temp_cost=dict()\n", 127 | "path=dict()\n", 128 | "for i in nodes:\n", 129 | " costs[i]=999999\n", 130 | " path[i]=' '" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 21, 136 | "id": "73d769c4", 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "Enter the Start Node: A\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "open=set()\n", 149 | "closed=set()\n", 150 | "start_node=input(\"Enter the Start Node: \")\n", 151 | "open.add(start_node)" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 22, 157 | "id": "44720d44", 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "path[start_node]=start_node\n", 162 | "costs[start_node]=0" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 23, 168 | "id": "0d422c77", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "Enter the Goal Node: H\n", 176 | "Path with least cost is: A->C->G->H\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "A_star(graph, costs, open, closed, start_node)\n", 182 | "goal_node=input(\"Enter the Goal Node: \")\n", 183 | "print(\"Path with least cost is: \",path[goal_node])" 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "kernelspec": { 189 | "display_name": "Python 3 (ipykernel)", 190 | "language": "python", 191 | "name": "python3" 192 | }, 193 | "language_info": { 194 | "codemirror_mode": { 195 | "name": "ipython", 196 | "version": 3 197 | }, 198 | "file_extension": ".py", 199 | "mimetype": "text/x-python", 200 | "name": "python", 201 | "nbconvert_exporter": "python", 202 | "pygments_lexer": "ipython3", 203 | "version": "3.11.4" 204 | } 205 | }, 206 | "nbformat": 4, 207 | "nbformat_minor": 5 208 | } 209 | -------------------------------------------------------------------------------- /students_contributions/Astar.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "id": "DiQW0hJGeKQJ" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "graph=[['A','B',1,3],\n", 26 | " ['A','C',2,4],\n", 27 | " ['A','H',7,0],\n", 28 | " ['B','D',4,2],\n", 29 | " ['B','E',6,6],\n", 30 | " ['C','F',3,3],\n", 31 | " ['C','G',2,1],\n", 32 | " ['D','E',7,6],\n", 33 | " ['D','H',5,0],\n", 34 | " ['F','H',1,0],\n", 35 | " ['G','H',2,0]]" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "source": [ 41 | "temp=[]\n", 42 | "temp1=[]\n", 43 | "for i in graph:\n", 44 | " temp.append(i[0])\n", 45 | " temp1.append(i[1])\n", 46 | "print(temp)\n", 47 | "print(temp1)" 48 | ], 49 | "metadata": { 50 | "colab": { 51 | "base_uri": "https://localhost:8080/" 52 | }, 53 | "id": "y--FWldCiIp3", 54 | "outputId": "74bad633-fe9f-479d-be0e-dbcb5758106f" 55 | }, 56 | "execution_count": null, 57 | "outputs": [ 58 | { 59 | "output_type": "stream", 60 | "name": "stdout", 61 | "text": [ 62 | "['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'F', 'G']\n", 63 | "['B', 'C', 'H', 'D', 'E', 'F', 'G', 'E', 'H', 'H', 'H']\n" 64 | ] 65 | } 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "source": [ 71 | "nodes=set(temp+temp1)\n", 72 | "print(nodes)\n", 73 | "def A_star(graph,costs,open,closed,cur_node):\n", 74 | " if cur_node in open:\n", 75 | " open.remove(cur_node)\n", 76 | " closed.add(cur_node)\n", 77 | " for i in graph:\n", 78 | " if(i[0]==cur_node and costs[i[0]]+i[2]+i[3] < costs[i[1]]):\n", 79 | " open.add(i[1])\n", 80 | " costs[i[1]]=costs[i[0]]+i[2]+i[3]\n", 81 | " path[i[1]]=path[i[0]]+ '-->' + i[1]\n", 82 | " costs[cur_node]=999999\n", 83 | " small=min(costs, key=costs.get)\n", 84 | " if small not in closed:\n", 85 | " A_star(graph,costs,open,closed,small)\n", 86 | "costs=dict()\n", 87 | "path=dict()\n", 88 | "for i in nodes:\n", 89 | " costs[i]=9999999\n", 90 | " path[i]=' '\n" 91 | ], 92 | "metadata": { 93 | "id": "ctqtAToIilHJ", 94 | "colab": { 95 | "base_uri": "https://localhost:8080/" 96 | }, 97 | "outputId": "e51c14e1-f75a-436a-eaa4-fd32d1179bf6" 98 | }, 99 | "execution_count": null, 100 | "outputs": [ 101 | { 102 | "output_type": "stream", 103 | "name": "stdout", 104 | "text": [ 105 | "{'H', 'F', 'B', 'D', 'E', 'G', 'A', 'C'}\n" 106 | ] 107 | } 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "source": [ 113 | "open=set()\n", 114 | "closed=set()\n", 115 | "start_node=input(\"Enter the start node:\")\n", 116 | "open.add(start_node)" 117 | ], 118 | "metadata": { 119 | "colab": { 120 | "base_uri": "https://localhost:8080/" 121 | }, 122 | "id": "Lmm1_Hdvmssc", 123 | "outputId": "8f408bfc-2a0c-44ba-bbc4-48a09a304e06" 124 | }, 125 | "execution_count": null, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "Enter the start node:A\n" 132 | ] 133 | } 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "source": [ 139 | "path[start_node]=start_node\n", 140 | "costs[start_node]=0\n" 141 | ], 142 | "metadata": { 143 | "id": "giG-yy-JnZfH" 144 | }, 145 | "execution_count": null, 146 | "outputs": [] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "source": [ 151 | "A_star(graph,costs,open,closed,start_node)\n", 152 | "goal_node=input(\"Enter the Goal node:\")\n", 153 | "print(\"Path with least cost is: \",path[goal_node])" 154 | ], 155 | "metadata": { 156 | "colab": { 157 | "base_uri": "https://localhost:8080/" 158 | }, 159 | "id": "bkX1xdwEnhfF", 160 | "outputId": "16a79dfc-5440-4bd2-bf1d-700dae3d88d1" 161 | }, 162 | "execution_count": null, 163 | "outputs": [ 164 | { 165 | "output_type": "stream", 166 | "name": "stdout", 167 | "text": [ 168 | "Enter the Goal node:H\n", 169 | "Path with least cost is: A-->C-->G-->H\n" 170 | ] 171 | } 172 | ] 173 | } 174 | ] 175 | } -------------------------------------------------------------------------------- /students_contributions/MLP Classifier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[6]: 5 | 6 | 7 | import numpy as np 8 | import pandas as pd 9 | data=pd.read_csv("HR_comma_sep.csv") 10 | 11 | 12 | # In[7]: 13 | 14 | 15 | data.head() 16 | 17 | 18 | # In[8]: 19 | 20 | 21 | data.info 22 | 23 | 24 | # In[9]: 25 | 26 | 27 | data['Departments'].value_counts() 28 | 29 | 30 | # In[10]: 31 | 32 | 33 | data["Departments"].unique() 34 | 35 | 36 | # In[11]: 37 | 38 | 39 | data['salary'].unique() 40 | 41 | 42 | # In[12]: 43 | 44 | 45 | from sklearn import preprocessing 46 | le=preprocessing.LabelEncoder() 47 | print(le) 48 | data['salary']=le.fit_transform(data['salary']) 49 | data['Departments']=le.fit_transform(data['Departments']) 50 | 51 | 52 | # In[13]: 53 | 54 | 55 | data['salary'].unique() 56 | 57 | 58 | # In[14]: 59 | 60 | 61 | print(pd.__version__) 62 | 63 | 64 | # In[15]: 65 | 66 | 67 | X=data[['satisfaction_level','last_evaluation','number_project','average_montly_hours','time_spend_company','Work_accident','promotion_last_5years','Departments','salary']] 68 | y=data['left'] 69 | from sklearn.model_selection import train_test_split 70 | X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42) 71 | 72 | 73 | # In[20]: 74 | 75 | 76 | X_train 77 | 78 | 79 | # In[16]: 80 | 81 | 82 | y_train 83 | 84 | 85 | # In[17]: 86 | 87 | 88 | from sklearn.neural_network import MLPClassifier 89 | clf=MLPClassifier(hidden_layer_sizes=(6,5),random_state=5,verbose=True,learning_rate_init=0.01) 90 | clf.fit(X_train,y_train) 91 | 92 | 93 | # In[18]: 94 | 95 | 96 | ypred=clf.predict(X_test) 97 | from sklearn.metrics import accuracy_score 98 | accuracy_score(y_test,ypred) 99 | 100 | 101 | # In[20]: 102 | 103 | 104 | X_test.shape 105 | 106 | 107 | # In[25]: 108 | 109 | 110 | n=pd.DataFrame({'satisfaction_level':[0.23],'last_evaluation':[0.53],'number_project':[1],'average_montly_hours':[25],'time_spend_company':[3],'Work_accident':[0],'promotion_last_5years':[0],'Departments':[1],'salary':[1]}) 111 | new_data=clf.predict(n) 112 | print(new_data) 113 | 114 | 115 | # In[28]: 116 | 117 | 118 | from sklearn.metrics import classification_report 119 | print(classification_report(y_test,ypred)) 120 | 121 | 122 | # In[30]: 123 | 124 | 125 | from sklearn.metrics import confusion_matrix 126 | y_pred=clf.predict(X_test) 127 | print(confusion_matrix(y_test,ypred)) 128 | 129 | 130 | # In[31]: 131 | 132 | 133 | print(y_train.value_counts()) 134 | print(y_test.value_counts()) 135 | 136 | -------------------------------------------------------------------------------- /students_contributions/MLPClassifier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import numpy as np 8 | import pandas as pd 9 | data=pd.read_csv('HR_comma_sep.csv') 10 | data.head() 11 | 12 | 13 | # In[2]: 14 | 15 | 16 | data.info() 17 | 18 | 19 | # In[3]: 20 | 21 | 22 | data['salary'].value_counts() 23 | 24 | 25 | # In[4]: 26 | 27 | 28 | data['Department'].value_counts() 29 | 30 | 31 | # In[5]: 32 | 33 | 34 | data['last_evaluation'].value_counts() 35 | 36 | 37 | # In[10]: 38 | 39 | 40 | data['Department'].unique() 41 | 42 | 43 | # In[8]: 44 | 45 | 46 | from sklearn import preprocessing 47 | le=preprocessing.LabelEncoder() 48 | 49 | 50 | # In[11]: 51 | 52 | 53 | print(le) 54 | data['salary']=le.fit_transform(data['salary']) 55 | data['Department']=le.fit_transform(data['Department']) 56 | 57 | 58 | # In[12]: 59 | 60 | 61 | data[''].unique() 62 | 63 | 64 | # In[13]: 65 | 66 | 67 | data['Department'].unique() 68 | 69 | 70 | # In[19]: 71 | 72 | 73 | print(pd.__version__) 74 | 75 | 76 | # In[21]: 77 | 78 | 79 | X=data[['satisfaction_level','last_evaluation','number_project','average_montly_hours','time_spend_company','Work_accident','promotion_last_5years','Department','salary']] 80 | y=data['left'] 81 | 82 | 83 | # In[23]: 84 | 85 | 86 | from sklearn.model_selection import train_test_split 87 | 88 | 89 | # In[24]: 90 | 91 | 92 | X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42) 93 | X_train 94 | 95 | 96 | # In[27]: 97 | 98 | 99 | from sklearn.neural_network import MLPClassifier 100 | clf=MLPClassifier(hidden_layer_sizes=(6,5),random_state=5,verbose=True,learning_rate_init=0.01) 101 | clf.fit(X_train,y_train) 102 | 103 | 104 | # In[28]: 105 | 106 | 107 | ypred=clf.predict(X_test) 108 | from sklearn.metrics import accuracy_score 109 | accuracy_score(y_test,ypred) 110 | 111 | 112 | # In[29]: 113 | 114 | 115 | X_test.shape 116 | 117 | 118 | # In[33]: 119 | 120 | 121 | n=pd.DataFrame({ 122 | 'satisfaction_level':[0.70],'last_evaluation':[0.53],'number_project':[2],'average_montly_hours':[157],'time_spend_company':[3],'Work_accident':[0],'promotion_last_5years':[0],'Department':[1],'salary':[1] 123 | }) 124 | new_data=clf.predict(n) 125 | print(new_data) 126 | 127 | 128 | # In[35]: 129 | 130 | 131 | from sklearn.metrics import confusion_matrix 132 | y_pred=clf.predict(X_test) 133 | print(confusion_matrix(y_test,ypred)) 134 | 135 | 136 | # In[36]: 137 | 138 | 139 | print(y_train.value_counts()) 140 | print(y_test.value_counts()) 141 | 142 | 143 | # In[37]: 144 | 145 | 146 | from sklearn.metrics import classification_report 147 | print(classification_report(y_test,ypred)) 148 | 149 | 150 | # In[39]: 151 | 152 | 153 | from sklearn.metrics import confusion_matrix 154 | y_pred=clf.predict(X_test) 155 | print(confusion_matrix(y_test,ypred)) 156 | 157 | 158 | # In[40]: 159 | 160 | 161 | print(y_train.value_counts()) 162 | print(y_test.value_counts()) 163 | 164 | 165 | # In[ ]: 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /students_contributions/Nqueens.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX = 20 # size of array 4 | self.A = [0]*self.MAX 5 | 6 | def placement(self,i,j): # to check if queen can be placed 7 | for k in range(1,i): 8 | if (self.A[k] == j) or abs(self.A[k] - j) == abs(k - i): 9 | return False 10 | print(self.A) 11 | return True 12 | 13 | def printplacedqueen(self,N): # method for print the placed Queen 14 | print('Arrangment--->') 15 | print() 16 | 17 | for i in range(1,N+1): 18 | for j in range(1,N+1): 19 | if self.A[i] != j: 20 | print('\t_',end =' ') 21 | else: 22 | print('\tQ',end =' ') 23 | print() 24 | print() 25 | 26 | def N_Queens(self,i,j): 27 | for k in range(1,N+1): 28 | if self.placement(i,k): 29 | self.A[i] = k 30 | if i == N: 31 | self.printplacedqueen(N) 32 | else: 33 | self.N_Queens(i+1,N) 34 | 35 | 36 | N = int(input("enter the queens value")) 37 | obj = solution() 38 | obj.N_Queens(1,N) -------------------------------------------------------------------------------- /students_contributions/Pandas-Operations.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import pandas as pd 8 | 9 | 10 | # In[2]: 11 | 12 | 13 | pd.__version__ 14 | 15 | 16 | # In[3]: 17 | 18 | 19 | cars=pd.Series(["BEmDablu","Toyota","Honda"]) 20 | cars 21 | 22 | 23 | # In[4]: 24 | 25 | 26 | sindex=pd.Series(["BEmDablu","Honda","Toyota"],index=["Fastest","Yaverage","Slow"]) 27 | 28 | 29 | # In[5]: 30 | 31 | 32 | sindex 33 | 34 | 35 | # In[6]: 36 | 37 | 38 | 39 | 40 | 41 | # In[7]: 42 | 43 | 44 | colors=pd.Series(["Blue","Silvar","Blyack"]) 45 | colors 46 | 47 | 48 | # In[8]: 49 | 50 | 51 | car_data=pd.DataFrame({"Car make":cars,"Color":colors}) 52 | car_data 53 | 54 | 55 | # In[10]: 56 | 57 | 58 | car_sales=pd.read_csv("car-sales.csv") 59 | car_sales 60 | 61 | 62 | # In[11]: 63 | 64 | 65 | car_sales.to_csv("export_cars.csv",index=False) 66 | 67 | 68 | # In[12]: 69 | 70 | 71 | export_cars.describe() 72 | 73 | 74 | # In[13]: 75 | 76 | 77 | export_cars 78 | 79 | 80 | # In[14]: 81 | 82 | 83 | export_cars=pd.read_csv("export_cars.csv") 84 | 85 | 86 | # In[15]: 87 | 88 | 89 | export_cars 90 | 91 | 92 | # In[23]: 93 | 94 | 95 | export_cars.describe 96 | 97 | 98 | # In[17]: 99 | 100 | 101 | export_cars.dtypes 102 | 103 | 104 | # In[19]: 105 | 106 | 107 | export_cars.shape 108 | 109 | 110 | # In[20]: 111 | 112 | 113 | export_cars.info() 114 | 115 | 116 | # In[21]: 117 | 118 | 119 | export_cars.columns 120 | 121 | 122 | # In[22]: 123 | 124 | 125 | export_cars.index 126 | 127 | 128 | # In[24]: 129 | 130 | 131 | car_sales[["Odometer (KM)","Doors"]].mean() 132 | 133 | 134 | # In[25]: 135 | 136 | 137 | car_sales.sum() 138 | 139 | 140 | # In[26]: 141 | 142 | 143 | car_sales["Doors"].sum() 144 | 145 | 146 | # In[27]: 147 | 148 | 149 | len(car_sales) 150 | 151 | 152 | # In[30]: 153 | 154 | 155 | car_sales.head(3) 156 | 157 | 158 | # In[31]: 159 | 160 | 161 | car_sales.tail(3) 162 | 163 | 164 | # In[32]: 165 | 166 | 167 | fruits=pd.Series(["apple","banana","Mango","Berry"],index=[0,3,4,3]) 168 | 169 | 170 | # In[35]: 171 | 172 | 173 | fruits.iloc[3] 174 | 175 | 176 | # In[36]: 177 | 178 | 179 | fruits.loc[3] 180 | 181 | 182 | # In[37]: 183 | 184 | 185 | fruits.loc[4] 186 | 187 | 188 | # In[ ]: 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /students_contributions/TicTacToe.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import random 4 | class TicTacToe: 5 | def __init__(self): 6 | self.board = np.zeros((3, 3)) 7 | self.players = ["X", "O"] 8 | self.current_player = None 9 | self.winner = None 10 | self.game_over = False 11 | 12 | def reset(self): 13 | self.board = np.zeros((3, 3)) 14 | self.current_player = None 15 | self.winner = None 16 | self.game_over = False 17 | 18 | def available_moves(self): 19 | moves = [] 20 | for i in range(3): 21 | for j in range(3): 22 | if self.board[i][j] == 0: 23 | moves.append((i, j)) 24 | return moves 25 | 26 | def make_move(self, move): 27 | if self.board[move[0]][move[1]] != 0: 28 | return False 29 | self.board[move[0]][move[1]] = self.players.index(self.current_player) + 1 30 | self.check_winner() 31 | self.switch_player() 32 | return True 33 | 34 | def switch_player(self): 35 | if self.current_player == self.players[0]: 36 | self.current_player = self.players[1] 37 | else: 38 | self.current_player = self.players[0] 39 | 40 | def check_winner(self): 41 | # Check rows 42 | for i in range(3): 43 | if self.board[i][0] == self.board[i][1] == self.board[i][2] != 0: 44 | self.winner = self.players[int(self.board[i][0] - 1)] 45 | self.game_over = True 46 | # Check columns 47 | for j in range(3): 48 | if self.board[0][j] == self.board[1][j] == self.board[2][j] != 0: 49 | self.winner = self.players[int(self.board[0][j] - 1)] 50 | self.game_over = True 51 | # Check diagonals 52 | if self.board[0][0] == self.board[1][1] == self.board[2][2] != 0: 53 | self.winner = self.players[int(self.board[0][0] - 1)] 54 | self.game_over = True 55 | if self.board[0][2] == self.board[1][1] == self.board[2][0] != 0: 56 | self.winner = self.players[int(self.board[0][2] - 1)] 57 | self.game_over = True 58 | 59 | def print_board(self): 60 | print("-------------") 61 | for i in range(3): 62 | print("|", end=" ") 63 | for j in range(3): 64 | print(self.players[int(self.board[i][j] - 1)] if self.board[i][j] != 0 else " ", end="|") 65 | print() 66 | print("-------------") 67 | 68 | 69 | game = TicTacToe() 70 | game.current_player = game.players[0] 71 | game.print_board() 72 | 73 | while not game.game_over: 74 | move = input(f"{game.current_player}''s turn. Enter row and column (e.g. 0 0): ") 75 | move = tuple(map(int, move.split())) 76 | while move not in game.available_moves(): 77 | move = input("Invalid move. Try again: ") 78 | move = tuple(map(int, move.split())) 79 | game.make_move(move) 80 | game.print_board() 81 | 82 | if game.winner: 83 | print(f"{game.winner} wins!") 84 | else: 85 | print("It''s a tie!") 86 | -------------------------------------------------------------------------------- /students_contributions/Waterjug_auto (2).py: -------------------------------------------------------------------------------- 1 | import math 2 | from collections import deque 3 | a = int(input("Enter Jug A Capacity: ")) 4 | b = int(input("Enter Jug B Capacity: ")) 5 | ai = int(input("Initially Water in Jug A: ")) 6 | bi = int(input("Initially Water in Jug B: ")) 7 | af = int(input("Final State of Jug A: ")) 8 | bf = int(input("Final State of Jug B: ")) 9 | if a <= 0 or b <= 0: 10 | print("Jug capacities must be positive.") 11 | exit(1) 12 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 13 | print("Negative values are not allowed.") 14 | exit(1) 15 | if ai==af and bi==bf: 16 | print(f"initial state is already the final state: juga{ai} and jugb={bi}") 17 | exit() 18 | def bfs_wjug(a, b, ai, bi, af, bf): 19 | visited = set() 20 | queue = deque([(ai, bi, [])]) 21 | while queue: 22 | curr_ai, curr_bi, operations = queue.popleft() 23 | if (curr_ai, curr_bi) in visited: 24 | continue 25 | visited.add((curr_ai, curr_bi)) 26 | if curr_ai == af and curr_bi == bf: 27 | for i, op in enumerate(operations): 28 | print(f"Step {i + 1}: {op}") 29 | print(f"Final State Reached: Jug A = {curr_ai}, Jug B = {curr_bi}") 30 | return 31 | possible_operations = [ 32 | (a, curr_bi, "Fill Jug A"), 33 | (curr_ai, b, "Fill Jug B"), 34 | (0, curr_bi, "Empty Jug A"), 35 | (curr_ai, 0, "Empty Jug B"), 36 | (curr_ai - min(curr_ai, b - curr_bi), curr_bi + min(curr_ai, b - curr_bi), "Pour from A to B"), 37 | (curr_ai + min(curr_bi, a - curr_ai), curr_bi - min(curr_bi, a - curr_ai), "Pour from B to A"), 38 | ] 39 | for next_ai, next_bi, op in possible_operations: 40 | if (next_ai, next_bi) not in visited: 41 | queue.append((next_ai, next_bi, operations + [op])) 42 | print("No solution found.") 43 | return 44 | gcd = math.gcd(a, b) 45 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 46 | bfs_wjug(a, b, ai, bi, af, bf) 47 | else: 48 | print("The final state is not achievable with the given capacities.") 49 | exit() 50 | -------------------------------------------------------------------------------- /students_contributions/Waterjug_auto (3).py: -------------------------------------------------------------------------------- 1 | import math 2 | from collections import deque 3 | a = int(input("Enter Jug A Capacity: ")) 4 | b = int(input("Enter Jug B Capacity: ")) 5 | ai = int(input("Initially Water in Jug A: ")) 6 | bi = int(input("Initially Water in Jug B: ")) 7 | af = int(input("Final State of Jug A: ")) 8 | bf = int(input("Final State of Jug B: ")) 9 | if a <= 0 or b <= 0: 10 | print("Jug capacities must be positive.") 11 | exit(1) 12 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 13 | print("Negative values are not allowed.") 14 | exit(1) 15 | if ai==af and bi==bf: 16 | print(f"initial state is already the final state: juga{ai} and jugb={bi}") 17 | exit() 18 | def bfs_wjug(a, b, ai, bi, af, bf): 19 | visited = set() 20 | queue = deque([(ai, bi, [])]) 21 | while queue: 22 | curr_ai, curr_bi, operations = queue.popleft() 23 | if (curr_ai, curr_bi) in visited: 24 | continue 25 | visited.add((curr_ai, curr_bi)) 26 | if curr_ai == af and curr_bi == bf: 27 | for i, op in enumerate(operations): 28 | print(f"Step {i + 1}: {op}") 29 | print(f"Final State Reached: Jug A = {curr_ai}, Jug B = {curr_bi}") 30 | return 31 | possible_operations = [ 32 | (a, curr_bi, "Fill Jug A"), 33 | (curr_ai, b, "Fill Jug B"), 34 | (0, curr_bi, "Empty Jug A"), 35 | (curr_ai, 0, "Empty Jug B"), 36 | (curr_ai - min(curr_ai, b - curr_bi), curr_bi + min(curr_ai, b - curr_bi), "Pour from A to B"), 37 | (curr_ai + min(curr_bi, a - curr_ai), curr_bi - min(curr_bi, a - curr_ai), "Pour from B to A"), 38 | ] 39 | for next_ai, next_bi, op in possible_operations: 40 | if (next_ai, next_bi) not in visited: 41 | queue.append((next_ai, next_bi, operations + [op])) 42 | print("No solution found.") 43 | return 44 | gcd = math.gcd(a, b) 45 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 46 | bfs_wjug(a, b, ai, bi, af, bf) 47 | else: 48 | print("The final state is not achievable with the given capacities.") 49 | exit() 50 | -------------------------------------------------------------------------------- /students_contributions/Waterjug_auto.py: -------------------------------------------------------------------------------- 1 | import math 2 | from collections import deque 3 | a = int(input("Enter Jug A Capacity: ")) 4 | b = int(input("Enter Jug B Capacity: ")) 5 | ai = int(input("Initially Water in Jug A: ")) 6 | bi = int(input("Initially Water in Jug B: ")) 7 | af = int(input("Final State of Jug A: ")) 8 | bf = int(input("Final State of Jug B: ")) 9 | if a <= 0 or b <= 0: 10 | print("Jug capacities must be positive.") 11 | exit(1) 12 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 13 | print("Negative values are not allowed.") 14 | exit(1) 15 | if ai==af and bi==bf: 16 | print(f"initial state is already the final state: juga{ai} and jugb={bi}") 17 | exit() 18 | def bfs_wjug(a, b, ai, bi, af, bf): 19 | visited = set() 20 | queue = deque([(ai, bi, [])]) 21 | while queue: 22 | curr_ai, curr_bi, operations = queue.popleft() 23 | if (curr_ai, curr_bi) in visited: 24 | continue 25 | visited.add((curr_ai, curr_bi)) 26 | if curr_ai == af and curr_bi == bf: 27 | for i, op in enumerate(operations): 28 | print(f"Step {i + 1}: {op}") 29 | print(f"Final State Reached: Jug A = {curr_ai}, Jug B = {curr_bi}") 30 | return 31 | possible_operations = [ 32 | (a, curr_bi, "Fill Jug A"), 33 | (curr_ai, b, "Fill Jug B"), 34 | (0, curr_bi, "Empty Jug A"), 35 | (curr_ai, 0, "Empty Jug B"), 36 | (curr_ai - min(curr_ai, b - curr_bi), curr_bi + min(curr_ai, b - curr_bi), "Pour from A to B"), 37 | (curr_ai + min(curr_bi, a - curr_ai), curr_bi - min(curr_bi, a - curr_ai), "Pour from B to A"), 38 | ] 39 | for next_ai, next_bi, op in possible_operations: 40 | if (next_ai, next_bi) not in visited: 41 | queue.append((next_ai, next_bi, operations + [op])) 42 | print("No solution found.") 43 | return 44 | gcd = math.gcd(a, b) 45 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 46 | bfs_wjug(a, b, ai, bi, af, bf) 47 | else: 48 | print("The final state is not achievable with the given capacities.") 49 | exit() 50 | -------------------------------------------------------------------------------- /students_contributions/bfs.py: -------------------------------------------------------------------------------- 1 | graph={ 2 | 'P':['Q','R','S'], 3 | 'Q':['P','R'], 4 | 'R':['P','Q','T'], 5 | 'T':['R'], 6 | 'S':['P'] 7 | } 8 | visited=[] 9 | queue=[] 10 | def bfs(visited,graph,node): 11 | visited.append(node) 12 | queue.append(node) 13 | while queue: 14 | m=queue.pop(0) 15 | print(m,end=" ") 16 | for neighbour in graph[m]: 17 | if neighbour not in visited: 18 | visited.append(neighbour) 19 | queue.append(neighbour) 20 | print("following is the breadth first search") 21 | bfs(visited,graph,'P') -------------------------------------------------------------------------------- /students_contributions/decision tree.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import pandas as pd 8 | df=pd.read_csv("diabetes.csv") 9 | 10 | 11 | # In[2]: 12 | 13 | 14 | df.head() 15 | 16 | 17 | # In[3]: 18 | 19 | 20 | df.tail() 21 | 22 | 23 | # In[4]: 24 | 25 | 26 | df.shape 27 | 28 | 29 | # In[5]: 30 | 31 | 32 | df.isnull().sum() 33 | 34 | 35 | # In[7]: 36 | 37 | 38 | X=df.iloc[:,:-1].to_numpy() 39 | Y=df.iloc[:,-1].to_numpy() 40 | 41 | 42 | # In[8]: 43 | 44 | 45 | X 46 | 47 | 48 | # In[9]: 49 | 50 | 51 | Y 52 | 53 | 54 | # In[11]: 55 | 56 | 57 | from sklearn.model_selection import train_test_split 58 | X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.2,random_state=0) 59 | 60 | 61 | # In[12]: 62 | 63 | 64 | from sklearn.tree import DecisionTreeClassifier 65 | clf=DecisionTreeClassifier(criterion="entropy",random_state=0) 66 | clf.fit(X_train,Y_train) 67 | 68 | 69 | # In[15]: 70 | 71 | 72 | import matplotlib.pyplot as plt 73 | get_ipython().run_line_magic('matplotlib', 'inline') 74 | from sklearn.tree import plot_tree 75 | clf.fit(X_train,Y_train) 76 | plt.figure(figsize=(20,10)) 77 | plot_tree(clf,feature_names=['Glucose','BMI'],class_names=['No','Yes']) 78 | plt.show() 79 | 80 | 81 | # In[18]: 82 | 83 | 84 | clf.set_params(max_depth=3) 85 | clf.fit(X_train,Y_train) 86 | plt.figure(figsize=(20,10)) 87 | plot_tree(clf,feature_names=['Glucose','BMI'],class_names=['No','Yes']) 88 | plt.show() 89 | 90 | 91 | # In[20]: 92 | 93 | 94 | predictions=clf.predict(X_test) 95 | 96 | 97 | # In[21]: 98 | 99 | 100 | clf.predict([[90,20],[200,30]]) 101 | 102 | 103 | # In[22]: 104 | 105 | 106 | predictions=clf.predict(X_test) 107 | 108 | 109 | # In[23]: 110 | 111 | 112 | predictions 113 | 114 | 115 | # In[ ]: 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /students_contributions/decision_tree.py.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import pandas as pd 8 | df=pd.read_csv("diabetes.csv") 9 | 10 | 11 | # In[2]: 12 | 13 | 14 | df.head() 15 | 16 | 17 | # In[3]: 18 | 19 | 20 | df.tail() 21 | 22 | 23 | # In[4]: 24 | 25 | 26 | df.shape 27 | 28 | 29 | # In[5]: 30 | 31 | 32 | df.isnull().sum() 33 | 34 | 35 | # In[7]: 36 | 37 | 38 | X=df.iloc[:,:-1].to_numpy() 39 | Y=df.iloc[:,-1].to_numpy() 40 | 41 | 42 | # In[8]: 43 | 44 | 45 | X 46 | 47 | 48 | # In[9]: 49 | 50 | 51 | Y 52 | 53 | 54 | # In[11]: 55 | 56 | 57 | from sklearn.model_selection import train_test_split 58 | X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.2,random_state=0) 59 | 60 | 61 | # In[12]: 62 | 63 | 64 | from sklearn.tree import DecisionTreeClassifier 65 | clf=DecisionTreeClassifier(criterion="entropy",random_state=0) 66 | clf.fit(X_train,Y_train) 67 | 68 | 69 | # In[15]: 70 | 71 | 72 | import matplotlib.pyplot as plt 73 | get_ipython().run_line_magic('matplotlib', 'inline') 74 | from sklearn.tree import plot_tree 75 | clf.fit(X_train,Y_train) 76 | plt.figure(figsize=(20,10)) 77 | plot_tree(clf,feature_names=['Glucose','BMI'],class_names=['No','Yes']) 78 | plt.show() 79 | 80 | 81 | # In[18]: 82 | 83 | 84 | clf.set_params(max_depth=3) 85 | clf.fit(X_train,Y_train) 86 | plt.figure(figsize=(20,10)) 87 | plot_tree(clf,feature_names=['Glucose','BMI'],class_names=['No','Yes']) 88 | plt.show() 89 | 90 | 91 | # In[20]: 92 | 93 | 94 | predictions=clf.predict(X_test) 95 | 96 | 97 | # In[21]: 98 | 99 | 100 | clf.predict([[90,20],[200,30]]) 101 | 102 | 103 | # In[22]: 104 | 105 | 106 | predictions=clf.predict(X_test) 107 | 108 | 109 | # In[23]: 110 | 111 | 112 | predictions 113 | 114 | 115 | # In[ ]: 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /students_contributions/gbfs.py: -------------------------------------------------------------------------------- 1 | from state import State 2 | from queue import PriorityQueue 3 | def Greedy(given_state , n): 4 | frontier = PriorityQueue() 5 | explored = [] 6 | counter = 0 7 | root = State(given_state, None, None, 0, 0) 8 | #root.evaluation() 9 | evaluation = root.Misplaced_Tiles(n) #we can use Misplaced_Tiles() instead. 10 | frontier.put((evaluation, counter, root)) #based on greedy evaluation 11 | 12 | while not frontier.empty(): 13 | current_node = frontier.get() 14 | current_node = current_node[2] 15 | explored.append(current_node.state) 16 | 17 | if current_node.test(): 18 | return current_node.solution(), len(explored) 19 | 20 | children = current_node.expand(n) 21 | for child in children: 22 | if child.state not in explored: 23 | counter += 1 24 | evaluation = child.Misplaced_Tiles(n) #we can use Misplaced_Tiles() instead. 25 | frontier.put((evaluation, counter, child)) #based on greedy evaluation 26 | return 27 | -------------------------------------------------------------------------------- /students_contributions/hangman_1.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | from hangman_words import word_list 4 | from hangman_art import stages,logo 5 | chosen_word=random.choice(word_list) 6 | #lives=6 if len(chosen_word) >= 6 else 6 7 | lives=6 8 | 9 | #print(f'pssst, the solution is {chosen_word}.') 10 | print(logo) 11 | print(len(stages)) 12 | display=[] 13 | guessed=[] 14 | for i in range(len(chosen_word)): 15 | display.append("_") 16 | while "_" in display and lives>0: 17 | guess=input("guess a letter:").lower() 18 | if len(guess)==1 and guess.isalpha(): 19 | if guess in guessed: 20 | print("letter already present") 21 | continue 22 | guessed.append(guess) 23 | for i in range(len(chosen_word)): 24 | letter=chosen_word[i] 25 | if letter==guess: 26 | display[i]=letter 27 | if guess not in chosen_word: 28 | if lives>0: 29 | lives=lives-1 30 | if lives==0: 31 | print(stages[lives]) 32 | print(f'the solution is {chosen_word}.') 33 | print("You loose") 34 | exit(1) 35 | print(f"{' '.join(display)}") 36 | print(lives) 37 | print(stages[lives]) 38 | else: 39 | print("guess should be a charater rather than a word") 40 | else: 41 | print("you have won") 42 | -------------------------------------------------------------------------------- /students_contributions/hangmanv1.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | word_list = ["aardvark", "baboon", "camel"] 4 | chosen_word=random.choice(word_list) 5 | guess=input("Guess a letter:") 6 | for i in range(len(chosen_word)): 7 | 8 | if guess in chosen_word[i]: 9 | 10 | print("correct guess") 11 | 12 | else: 13 | 14 | print("wrong guess") -------------------------------------------------------------------------------- /students_contributions/hangmanv5.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | from hangman_words import word_list 4 | from hangman_art import stages,logo 5 | chosen_word=random.choice(word_list) 6 | #lives=6 if len(chosen_word) >= 6 else 6 7 | lives=6 8 | print(f'Pssst, the solution is {chosen_word}.') 9 | print(logo) 10 | print(len(stages)) 11 | display=[] 12 | guessed=[] 13 | for i in range(len(chosen_word)): 14 | 15 | display.append("_") 16 | while "_" in display and lives >0: 17 | guess=input("Guess a letter:").lower() 18 | if len(guess)==1 and guess.isalpha(): 19 | if guess in guessed: 20 | print("letter already present") 21 | continue 22 | guessed.append(guess) 23 | for i in range(len(chosen_word)): 24 | 25 | letter=chosen_word[i] 26 | 27 | if letter==guess: 28 | display[i]=letter 29 | if guess not in chosen_word: 30 | if lives > 0: 31 | lives=lives-1 32 | if lives==0: 33 | print(stages[lives]) 34 | print(f'the solution is {chosen_word}.') 35 | print("You loose") 36 | exit(1) 37 | print(f"{' '.join(display)}") 38 | print(lives) 39 | print(stages[lives]) 40 | else: 41 | print("guess should be a character rather than a word") 42 | 43 | else: 44 | print("You have won") 45 | 46 | -------------------------------------------------------------------------------- /students_contributions/nlp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """Untitled0.ipynb 3 | 4 | Automatically generated by Colab. 5 | 6 | Original file is located at 7 | https://colab.research.google.com/drive/1zoowcjsFQ6aEaa_wtzq_ik0PFgSY8ZnS 8 | """ 9 | 10 | import nltk 11 | nltk.download('wordnet') 12 | nltk.download('stopwords') 13 | nltk.download('omw-1.4') 14 | nltk.download('punkt_tab') 15 | 16 | text="""Hello Mr. Smith, how are you doing today? The weather is great, and city is awesome. The sky is pinkish-blue. 17 | You should\'t eat cardboard""" 18 | 19 | sent=nltk.sent_tokenize(text) 20 | print(sent) 21 | 22 | import re 23 | #text="SaaaMMM" 24 | print(text.lower()) 25 | text=re.sub(r"[^a-z\'A-Z]", " ",text.lower()) 26 | text 27 | 28 | words=text.split() 29 | print(words) 30 | 31 | from nltk.corpus import stopwords 32 | print(stopwords.words("english")) 33 | 34 | words= [w for w in words if w not in stopwords.words("english")] 35 | print(words) 36 | 37 | from nltk.stem.porter import PorterStemmer 38 | stemmed=[PorterStemmer().stem(w) for w in words] 39 | print(stemmed) 40 | 41 | from nltk.stem.wordnet import WordNetLemmatizer 42 | lemmed=[WordNetLemmatizer().lemmatize(w) for w in words] 43 | print(lemmed) 44 | 45 | from nltk import pos_tag,RegexpParser 46 | tagged=pos_tag(lemmed) 47 | print(tagged) 48 | for i, (word,tag) in enumerate(tagged): 49 | if word=="weather": 50 | tagged[i]= (word,"NN") 51 | if word=="eat": 52 | tagged[i]=(word,"VB") 53 | chunker=RegexpParser(""" 54 | NP:{} 55 | P:{} 56 | V:{} 57 | PP:{} 58 | VP:{} 59 | """) 60 | output=chunker.parse(tagged) 61 | print("After Extracting",output) 62 | 63 | nltk.download('averaged_perceptron_tagger_eng') 64 | 65 | -------------------------------------------------------------------------------- /students_contributions/numpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | import numpy as np 8 | 9 | 10 | # In[2]: 11 | 12 | 13 | arr1=np.array([1,2,3]) 14 | arr1 15 | 16 | 17 | # In[3]: 18 | 19 | 20 | type(arr1) 21 | 22 | 23 | # In[6]: 24 | 25 | 26 | arr2=np.array([[1,2,3.3],[4,5,6.5,]]) 27 | arr2 28 | 29 | 30 | # In[13]: 31 | 32 | 33 | arr3=np.array([ 34 | [ 35 | [1,2], 36 | [3,4] 37 | ], 38 | [ 39 | [5,6], 40 | [7,8] 41 | ] 42 | ]) 43 | print(arr3) 44 | 45 | 46 | # In[14]: 47 | 48 | 49 | arr4=np.array((12,13,15)) 50 | arr4 51 | 52 | 53 | # In[15]: 54 | 55 | 56 | print(arr1.ndim) 57 | 58 | 59 | # In[16]: 60 | 61 | 62 | print(arr2.ndim) 63 | 64 | 65 | # In[17]: 66 | 67 | 68 | print(arr3.ndim) 69 | 70 | 71 | # In[18]: 72 | 73 | 74 | print(arr4.ndim) 75 | 76 | 77 | # In[19]: 78 | 79 | 80 | array5=np.array([1,2,3,5],ndmin=4) 81 | array5 82 | 83 | 84 | # In[20]: 85 | 86 | 87 | print(array5.ndim) 88 | 89 | 90 | # In[22]: 91 | 92 | 93 | array5.shape 94 | 95 | 96 | # In[23]: 97 | 98 | 99 | arr2 100 | 101 | 102 | # In[25]: 103 | 104 | 105 | arr2[0][1] 106 | 107 | 108 | # arr2.shape(2,3) 109 | 110 | # In[26]: 111 | 112 | 113 | arr2.shape 114 | 115 | 116 | # In[27]: 117 | 118 | 119 | for x in range(0,2): 120 | for y in range(0,3): 121 | print(arr2[x][y]) 122 | 123 | 124 | # In[29]: 125 | 126 | 127 | arr1.dtype 128 | 129 | 130 | # In[30]: 131 | 132 | 133 | arr2.dtype 134 | 135 | 136 | # In[32]: 137 | 138 | 139 | arr5=np.array([1,2,3,4,5],dtype='S') 140 | arr5 141 | 142 | 143 | # In[34]: 144 | 145 | 146 | array2conv=arr2.astype('i') 147 | array2conv 148 | 149 | 150 | # 151 | 152 | # In[35]: 153 | 154 | 155 | array2float=arr2.astype('f') 156 | array2float 157 | 158 | 159 | # In[41]: 160 | 161 | 162 | num1=np.zeros((2,2),dtype=int) 163 | num1 164 | 165 | 166 | # In[47]: 167 | 168 | 169 | range_array=np.arange(0,10,3) 170 | range_array 171 | 172 | 173 | # In[61]: 174 | 175 | 176 | a=np.random.randint(low=4,high=10,size=5) 177 | a 178 | 179 | 180 | # In[64]: 181 | 182 | 183 | np.concatenate([arr1,arr4]) 184 | 185 | 186 | # In[65]: 187 | 188 | 189 | flatarr=arr3.flatten() 190 | flatarr 191 | 192 | 193 | # In[ ]: 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /students_contributions/pandas.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[3]: 5 | 6 | 7 | import pandas as pd 8 | 9 | 10 | # In[4]: 11 | 12 | 13 | pd.__version__ 14 | 15 | 16 | # In[11]: 17 | 18 | 19 | sindex=pd.Series(["BMW","Toyota","Homnda"],index=["first","second","third"]) 20 | sindex 21 | 22 | 23 | # In[12]: 24 | 25 | 26 | sindex["second"] 27 | 28 | 29 | # In[13]: 30 | 31 | 32 | colors=pd.Series(["red","blue","white"]) 33 | 34 | 35 | # In[14]: 36 | 37 | 38 | colors 39 | 40 | 41 | # In[17]: 42 | 43 | 44 | car_data=pd.DataFrame({"Car make":cars,"color":colors}) 45 | car_data 46 | 47 | 48 | # In[24]: 49 | 50 | 51 | car_sales=pd.read_csv("car-sales.csv") 52 | car_sales 53 | 54 | 55 | # In[34]: 56 | 57 | 58 | car_sales.to_csv("export_cars.csv",index=False) 59 | 60 | export_cars=pd.read_csv(") 61 | # In[35]: 62 | 63 | 64 | export_cars 65 | 66 | 67 | # In[36]: 68 | 69 | 70 | export_cars=pd.read_csv("export_cars.csv") 71 | 72 | 73 | # In[37]: 74 | 75 | 76 | export_cars 77 | 78 | 79 | # In[38]: 80 | 81 | 82 | export_cars.describe() 83 | 84 | 85 | # In[39]: 86 | 87 | 88 | export_cars.dtypes 89 | 90 | 91 | # In[42]: 92 | 93 | 94 | export_cars.shape 95 | 96 | 97 | # In[45]: 98 | 99 | 100 | export_cars.info() 101 | 102 | 103 | # In[46]: 104 | 105 | 106 | export_cars.columns 107 | 108 | 109 | # In[50]: 110 | 111 | 112 | export_cars.index 113 | 114 | 115 | # In[51]: 116 | 117 | 118 | export_cars.describe 119 | 120 | 121 | # In[54]: 122 | 123 | 124 | car_sales[["Odometer (KM)","Doors"]].mean() 125 | 126 | 127 | # 128 | 129 | # In[55]: 130 | 131 | 132 | car_sales.sum 133 | 134 | car_sales.sum() 135 | # In[56]: 136 | 137 | 138 | car_sales.sum() 139 | 140 | 141 | # In[57]: 142 | 143 | 144 | car_sales["Doors"].sum() 145 | 146 | 147 | # In[58]: 148 | 149 | 150 | len(car_sales) 151 | 152 | 153 | # In[59]: 154 | 155 | 156 | car_sales.head() 157 | 158 | 159 | # In[60]: 160 | 161 | 162 | car_sales.tail() 163 | 164 | 165 | # In[64]: 166 | 167 | 168 | car_sales.loc[5] 169 | 170 | 171 | # In[65]: 172 | 173 | 174 | car_sales.iloc[5] 175 | 176 | 177 | # In[71]: 178 | 179 | 180 | fruits=pd.Series(["apple","banana","mango","berry"],index=[0,3,4,3]) 181 | 182 | 183 | # In[72]: 184 | 185 | 186 | fruits.iloc[3] 187 | 188 | 189 | # In[73]: 190 | 191 | 192 | fruits.loc[3] 193 | 194 | 195 | # In[ ]: 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /students_contributions/prolog_familytree.py: -------------------------------------------------------------------------------- 1 | male(harivansh). 2 | male(amitabh). 3 | male(abhishek). 4 | female(teji). 5 | female(jaya). 6 | female(shweta). 7 | female(aishwarya). 8 | female(aradhya). 9 | 10 | parent(harivansh,amitabh). 11 | parent(teji,amitabh). 12 | parent(amitabh,abhishek). 13 | parent(amitabh,shweta). 14 | parent(jaya,abhishek). 15 | parent(jaya,shweta). 16 | parent(abhishek,aradhya). 17 | parent(aishwarya,aradhya). 18 | 19 | mother(M,C):-female(M),parent(M,C). 20 | father(F,C):-male(F),parent(F,C). 21 | son(S,P):-male(S),parent(P,S). 22 | daughter(D,P):-female(D), parent(P,D). 23 | brother(B,S):-male(B),parent(P,B),parent(P,S). 24 | sister(S,B):-female(S), parent(P,S), parent(P,B). 25 | grandfather(G,C):-male(G),parent(G,M),parent(M,C). 26 | grandmother(GM,C):-female(GM),parent(GM,M),parent(M,C). 27 | 28 | -------------------------------------------------------------------------------- /students_contributions/queen (1).py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX = 20 # size of array 4 | self.A = [0]*self.MAX 5 | 6 | def placement(self,i,j): # to check if queen can be placed 7 | for k in range(1,i): 8 | if (self.A[k] == j) or abs(self.A[k] - j) == abs(k - i): 9 | return False 10 | print(self.A) 11 | return True 12 | 13 | def printplacedqueen(self,N): # method for print the placed Queen 14 | print('Arrangment--->') 15 | print() 16 | 17 | for i in range(1,N+1): 18 | for j in range(1,N+1): 19 | if self.A[i] != j: 20 | print('\t_',end =' ') 21 | else: 22 | print('\tQ',end =' ') 23 | print() 24 | print() 25 | 26 | def N_Queens(self,i,j): 27 | for k in range(1,N+1): 28 | if self.placement(i,k): 29 | self.A[i] = k 30 | if i == N: 31 | self.printplacedqueen(N) 32 | else: 33 | self.N_Queens(i+1,N) 34 | 35 | 36 | N = int(input("enter the queens value")) 37 | obj = solution() 38 | obj.N_Queens(1,N) -------------------------------------------------------------------------------- /students_contributions/queen (2).py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX = 20 # size of array 4 | self.A = [0]*self.MAX 5 | 6 | def placement(self,i,j): # to check if queen can be placed 7 | for k in range(1,i): 8 | if (self.A[k] == j) or abs(self.A[k] - j) == abs(k - i): 9 | return False 10 | print(self.A) 11 | return True 12 | 13 | def printplacedqueen(self,N): # method for print the placed Queen 14 | print('Arrangment--->') 15 | print() 16 | 17 | for i in range(1,N+1): 18 | for j in range(1,N+1): 19 | if self.A[i] != j: 20 | print('\t_',end =' ') 21 | else: 22 | print('\tQ',end =' ') 23 | print() 24 | print() 25 | 26 | def N_Queens(self,i,j): 27 | for k in range(1,N+1): 28 | if self.placement(i,k): 29 | self.A[i] = k 30 | if i == N: 31 | self.printplacedqueen(N) 32 | else: 33 | self.N_Queens(i+1,N) 34 | 35 | 36 | N = int(input("enter the queens value")) 37 | obj = solution() 38 | obj.N_Queens(1,N) -------------------------------------------------------------------------------- /students_contributions/queen.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX = 20 # size of array 4 | self.A = [0]*self.MAX 5 | 6 | def placement(self,i,j): # to check if queen can be placed 7 | for k in range(1,i): 8 | if (self.A[k] == j) or abs(self.A[k] - j) == abs(k - i): 9 | return False 10 | print(self.A) 11 | return True 12 | 13 | def printplacedqueen(self,N): # method for print the placed Queen 14 | print('Arrangment--->') 15 | print() 16 | 17 | for i in range(1,N+1): 18 | for j in range(1,N+1): 19 | if self.A[i] != j: 20 | print('\t_',end =' ') 21 | else: 22 | print('\tQ',end =' ') 23 | print() 24 | print() 25 | 26 | def N_Queens(self,i,j): 27 | for k in range(1,N+1): 28 | if self.placement(i,k): 29 | self.A[i] = k 30 | if i == N: 31 | self.printplacedqueen(N) 32 | else: 33 | self.N_Queens(i+1,N) 34 | 35 | 36 | N = int(input("enter the queens value")) 37 | obj = solution() 38 | obj.N_Queens(1,N) -------------------------------------------------------------------------------- /students_contributions/queens.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX=20 4 | self.A=[0]*self.MAX 5 | def placement(self,i,j): 6 | for k in range(1,i): 7 | if(self.A[k]==j) or abs(self.A[k]-j)==abs(k-i): 8 | return False 9 | print(self.A) 10 | return True 11 | def printplacedqueen(self,N): 12 | print('Arrangement--->') 13 | print() 14 | for i in range(1,N+1): 15 | for j in range(1,N+1): 16 | if self.A[i] != j: 17 | print('\t_',end=' ') 18 | else: 19 | print('\tQ',end=' ') 20 | print() 21 | print() 22 | def N_Queens(self,i,j): 23 | for k in range(1,N+1): 24 | if self.placement(i,k): 25 | self.A[i]=k 26 | if i == N: 27 | self.printplacedqueen(N) 28 | else: 29 | self.N_Queens(i+1,N) 30 | N=int(input("Enter the queens value:")) 31 | obj=solution() 32 | obj.N_Queens(1,N) 33 | 34 | -------------------------------------------------------------------------------- /students_contributions/waterjugmanual.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | # Input capacities and initial/final states for jugs 4 | a = int(input("Enter Jug A Capacity: ")) 5 | b = int(input("Enter Jug B Capacity: ")) 6 | ai = int(input("Initially Water in Jug A: ")) 7 | bi = int(input("Initially Water in Jug B: ")) 8 | af = int(input("Final State of Jug A: ")) 9 | bf = int(input("Final State of Jug B: ")) 10 | 11 | # Check for negative values 12 | if a <= 0 or b <= 0: 13 | print("Jug capacities must be positive.") 14 | exit(1) 15 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 16 | print("Negative values are not allowed.") 17 | exit(1) 18 | 19 | # Define the water jug solver function 20 | def wjug(a, b, ai, bi, af, bf): 21 | print("List Of Operations You Can Do:\n") 22 | print("1. Fill Jug A Completely") 23 | print("2. Fill Jug B Completely") 24 | print("3. Empty Jug A Completely") 25 | print("4. Empty Jug B Completely") 26 | print("5. Pour From Jug A till Jug B is full or A becomes empty") 27 | print("6. Pour From Jug B till Jug A is full or B becomes empty") 28 | print("7. Pour all from Jug B to Jug A") 29 | print("8. Pour all from Jug A to Jug B") 30 | 31 | # Loop until the final state is reached 32 | while ai != af or bi != bf: 33 | op = int(input("Enter the Operation (1-8): ")) 34 | 35 | if op == 1: # Fill Jug A completely 36 | ai = a 37 | elif op == 2: # Fill Jug B completely 38 | bi = b 39 | elif op == 3: # Empty Jug A 40 | ai = 0 41 | elif op == 4: # Empty Jug B 42 | bi = 0 43 | elif op == 5: # Pour from A to B 44 | pour_amount = min(ai, b - bi) 45 | ai -= pour_amount 46 | bi += pour_amount 47 | elif op == 6: # Pour from B to A 48 | pour_amount = min(bi, a - ai) 49 | bi -= pour_amount 50 | ai += pour_amount 51 | elif op == 7: # Pour all from B to A 52 | pour_amount = min(bi, a - ai) 53 | ai += pour_amount 54 | bi -= pour_amount 55 | elif op == 8: # Pour all from A to B 56 | pour_amount = min(ai, b - bi) 57 | bi += pour_amount 58 | ai -= pour_amount 59 | else: 60 | print("Invalid operation. Please choose a number between 1 and 8.") 61 | continue 62 | 63 | print(f"Jug A: {ai}, Jug B: {bi}") 64 | 65 | if ai == af and bi == bf: 66 | print("Final State Reached: Jug A =", ai, ", Jug B =", bi) 67 | return 68 | 69 | 70 | 71 | print("Final State Reached: Jug A =", ai, ", Jug B =", bi) 72 | 73 | # Check if the final state is achievable using GCD 74 | gcd = math.gcd(a, b) 75 | 76 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 77 | wjug(a, b, ai, bi, af, bf) 78 | else: 79 | print("The final state is not achievable with the given capacities.") 80 | exit(1) 81 | -------------------------------------------------------------------------------- /uninformed search/bfs.py: -------------------------------------------------------------------------------- 1 | graph={ 2 | 'P':['Q','R','S'], 3 | 'Q':['P','R'], 4 | 'R':['P','Q','T'], 5 | 'T':['R'], 6 | 'S':['P'] 7 | } 8 | visited=[] 9 | queue=[] 10 | def bfs(visited,graph,node): 11 | visited.append(node) 12 | queue.append(node) 13 | while queue: 14 | m=queue.pop(0) 15 | print(m,end=" ") 16 | for neighbour in graph[m]: 17 | if neighbour not in visited: 18 | visited.append(neighbour) 19 | queue.append(neighbour) 20 | print("following is the breadth first search") 21 | bfs(visited,graph,'P') -------------------------------------------------------------------------------- /uninformed search/dfs.py: -------------------------------------------------------------------------------- 1 | #ADJACENCY LIST 2 | graph = { 3 | 'A' : ['B','C'], 4 | 'B' : ['D', 'E'], 5 | 'C' : ['F'], 6 | 'D' : [], 7 | 'E':['F'], 8 | 'F' : [], 9 | } 10 | visited = set() # Set to keep track of visited nodes of graph. 11 | def dfs(visited, graph, node): 12 | #print(visited) #function for dfs 13 | if node not in visited: 14 | print (node) 15 | visited.add(node) 16 | for neighbour in graph[node]: 17 | dfs(visited, graph, neighbour) 18 | print("Following is the Depth-First Search") 19 | dfs(visited, graph, 'A') -------------------------------------------------------------------------------- /waterjug code/waterjbfs.py: -------------------------------------------------------------------------------- 1 | import math 2 | from collections import deque 3 | 4 | ''' Input capacities and initial/final states for jugs''' 5 | a = int(input("Enter Jug A Capacity: ")) 6 | b = int(input("Enter Jug B Capacity: ")) 7 | ai = int(input("Initially Water in Jug A: ")) 8 | bi = int(input("Initially Water in Jug B: ")) 9 | af = int(input("Final State of Jug A: ")) 10 | bf = int(input("Final State of Jug B: ")) 11 | 12 | # Check for negative values and whether initial state is equal to final state 13 | if a <= 0 or b <= 0: 14 | print("Jug capacities must be positive.") 15 | exit(1) 16 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 17 | print("Negative values are not allowed.") 18 | exit(1) 19 | if ai==af and bi==bf: 20 | print(f"initial state is already the final state: juga{ai} and jugb={bi}") 21 | exit() 22 | # Define the water jug solver function using BFS 23 | def bfs_wjug(a, b, ai, bi, af, bf): 24 | visited = set() 25 | queue = deque([(ai, bi, [])]) # (Jug A state, Jug B state, List of operations) 26 | 27 | while queue: 28 | curr_ai, curr_bi, operations = queue.popleft() 29 | 30 | if (curr_ai, curr_bi) in visited: 31 | continue 32 | visited.add((curr_ai, curr_bi)) 33 | 34 | # Check if the final state is reached 35 | if curr_ai == af and curr_bi == bf: 36 | for i, op in enumerate(operations): 37 | print(f"Step {i + 1}: {op}") 38 | print(f"Final State Reached: Jug A = {curr_ai}, Jug B = {curr_bi}") 39 | return 40 | 41 | # List of possible operations 42 | possible_operations = [ 43 | (a, curr_bi, "Fill Jug A"), # Fill Jug A 44 | (curr_ai, b, "Fill Jug B"), # Fill Jug B 45 | (0, curr_bi, "Empty Jug A"), # Empty Jug A 46 | (curr_ai, 0, "Empty Jug B"), # Empty Jug B 47 | (curr_ai - min(curr_ai, b - curr_bi), curr_bi + min(curr_ai, b - curr_bi), "Pour from A to B"), # Pour A to B 48 | (curr_ai + min(curr_bi, a - curr_ai), curr_bi - min(curr_bi, a - curr_ai), "Pour from B to A"), # Pour B to A 49 | ] 50 | 51 | # Add each possible operation to the queue 52 | for next_ai, next_bi, op in possible_operations: 53 | if (next_ai, next_bi) not in visited: 54 | queue.append((next_ai, next_bi, operations + [op])) 55 | 56 | print("No solution found.") 57 | return 58 | 59 | # Check if the final state can be achievable using GCD 60 | gcd = math.gcd(a, b) 61 | 62 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 63 | bfs_wjug(a, b, ai, bi, af, bf) 64 | else: 65 | print("The final state is not achievable with the given capacities.") 66 | exit() 67 | -------------------------------------------------------------------------------- /waterjug code/waterjug.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Divk-Ashwin/Artificial-Intelligence-Lab/74044df6dcd54d2fd1f090b04308ad2453ce7249/waterjug code/waterjug.pptx -------------------------------------------------------------------------------- /waterjug code/waterjugmanual.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | # Input capacities and initial/final states for jugs 4 | a = int(input("Enter Jug A Capacity: ")) 5 | b = int(input("Enter Jug B Capacity: ")) 6 | ai = int(input("Initially Water in Jug A: ")) 7 | bi = int(input("Initially Water in Jug B: ")) 8 | af = int(input("Final State of Jug A: ")) 9 | bf = int(input("Final State of Jug B: ")) 10 | 11 | # Check for negative values 12 | if a <= 0 or b <= 0: 13 | print("Jug capacities must be positive.") 14 | exit(1) 15 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 16 | print("Negative values are not allowed.") 17 | exit(1) 18 | 19 | # Define the water jug solver function 20 | def wjug(a, b, ai, bi, af, bf): 21 | print("List Of Operations You Can Do:\n") 22 | print("1. Fill Jug A Completely") 23 | print("2. Fill Jug B Completely") 24 | print("3. Empty Jug A Completely") 25 | print("4. Empty Jug B Completely") 26 | print("5. Pour From Jug A till Jug B is full or A becomes empty") 27 | print("6. Pour From Jug B till Jug A is full or B becomes empty") 28 | print("7. Pour all from Jug B to Jug A") 29 | print("8. Pour all from Jug A to Jug B") 30 | 31 | # Loop until the final state is reached 32 | while ai != af or bi != bf: 33 | op = int(input("Enter the Operation (1-8): ")) 34 | 35 | if op == 1: # Fill Jug A completely 36 | ai = a 37 | elif op == 2: # Fill Jug B completely 38 | bi = b 39 | elif op == 3: # Empty Jug A 40 | ai = 0 41 | elif op == 4: # Empty Jug B 42 | bi = 0 43 | elif op == 5: # Pour from A to B 44 | pour_amount = min(ai, b - bi) 45 | ai -= pour_amount 46 | bi += pour_amount 47 | elif op == 6: # Pour from B to A 48 | pour_amount = min(bi, a - ai) 49 | bi -= pour_amount 50 | ai += pour_amount 51 | elif op == 7: # Pour all from B to A 52 | pour_amount = min(bi, a - ai) 53 | ai += pour_amount 54 | bi -= pour_amount 55 | elif op == 8: # Pour all from A to B 56 | pour_amount = min(ai, b - bi) 57 | bi += pour_amount 58 | ai -= pour_amount 59 | else: 60 | print("Invalid operation. Please choose a number between 1 and 8.") 61 | continue 62 | 63 | print(f"Jug A: {ai}, Jug B: {bi}") 64 | 65 | if ai == af and bi == bf: 66 | print("Final State Reached: Jug A =", ai, ", Jug B =", bi) 67 | return 68 | 69 | 70 | 71 | print("Final State Reached: Jug A =", ai, ", Jug B =", bi) 72 | 73 | # Check if the final state is achievable using GCD 74 | gcd = math.gcd(a, b) 75 | 76 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 77 | wjug(a, b, ai, bi, af, bf) 78 | else: 79 | print("The final state is not achievable with the given capacities.") 80 | exit(1) 81 | --------------------------------------------------------------------------------