0% found this document useful (0 votes)
22 views66 pages

AIES LAB PROGRAM (1) (2) .Docx 20240926 204425 0000

The document contains multiple algorithms and programs for solving various computational problems, including the N-Queens problem, Depth First Search (DFS), Best First Search, Tower of Hanoi, water jug problem, A* algorithm, Tic-Tac-Toe using minimax, 8-queens problem, and map coloring. Each program is accompanied by its output demonstrating the results of the computations. The algorithms are implemented in Python and utilize different data structures and techniques to achieve their objectives.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views66 pages

AIES LAB PROGRAM (1) (2) .Docx 20240926 204425 0000

The document contains multiple algorithms and programs for solving various computational problems, including the N-Queens problem, Depth First Search (DFS), Best First Search, Tower of Hanoi, water jug problem, A* algorithm, Tic-Tac-Toe using minimax, 8-queens problem, and map coloring. Each program is accompanied by its output demonstrating the results of the computations. The algorithms are implemented in Python and utilize different data structures and techniques to achieve their objectives.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

PROGRAM

global N

N=4

def printSolution(board):

for i in range(N):

for j in range(N):

print (board[i][j],end=' ')

print()

def isSafe(board, row, col):

for i in range(col):

if board[row][i] == 1:

return False

for i, j in zip(range(row, -1, -1), range(col, -1, -1)):

if board[i][j] == 1:

return False

for i, j in zip(range(row, N, 1), range(col, -1, -1)):

if board[i][j] == 1:

return False

return True

def solveNQUtil(board, col):

if col >= N:

return True
for i in range(N):

if isSafe(board, i, col):

board[i][col] = 1

if solveNQUtil(board, col + 1) == True:

return True

board[i][col] = 0

return False

def solveNQ():

board = [ [0, 0, 0, 0],

[0, 0, 0, 0],

[0, 0, 0, 0],

[0, 0, 0, 0]

if solveNQUtil(board, 0) == False:

print ("Solution does not exist")

return False

printSolution(board)

return True

solveNQ()

OUTPUT

0010

1000
0001

0100
PROGRAM

from collections import defaultdict

class Graph: def __init__(self): self.graph = defaultdict(list)

def addEdge(self,u,v): self.graph[u].append(v)

def DFSUtil(self, v, visited): visited[v]= True print (v) for i in self.graph[v]: if


visited[i] == False: self.DFSUtil(i, visited)

def DFS(self): V = len(self.graph) visited =[False]*(V) for i in range(V): if visited[i]


== False: self.DFSUtil(i, visited)

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


3)print ("Following is Depth First Traversal")g.DFS()
OUTPUT

Following is Depth First Traversal0123


PROGRAM

from queue import PriorityQueue

v = 14

graph = [[] for i in range(v)]


def best_first_search(actual_Src, target, n):

visited = [False] * n

pq = PriorityQueue()

pq.put((0, actual_Src))

visited[actual_Src] = True

while pq.empty() == False:

u = pq.get()[1]

print(u, end=" ")

if u == target:

break

for v, c in graph[u]:

if visited[v] == False:

visited[v] = True

pq.put((c, v))

print()

def addedge(x, y, cost):

graph[x].append((y, cost))

graph[y].append((x, cost))

addedge(0, 1, 3)

addedge(0, 2, 6)

addedge(0, 3, 5)

addedge(1, 4, 9)
addedge(1, 5, 8)

addedge(2, 6, 12)

addedge(2, 7, 14)

addedge(3, 8, 7)

addedge(8, 9, 5)

addedge(8, 10, 6)

addedge(9, 11, 1)

addedge(9, 12, 10)

addedge(9, 13, 2)

source = 0

target = 9

best_first_search(source, target, v)
OUTPUT:

013289
PROGRAM

def TowerOfHanoi(n , source, destination, auxiliary): if n==1: print ("Move disk 1 from
source",source,"to destination",destination) return TowerOfHanoi(n-1, source, auxiliary,
destination) print ("Move disk",n,"from source",source,"to destination",destination) TowerOfHanoi(n-
1, auxiliary, destination, source)n = 4TowerOfHanoi(n,'A','B','C')

OUTPUT
Move disk 1 from source A to destination CMove disk 2 from source A to destination BMove disk 1 from
source C to destination BMove disk 3 from source A to destination CMove disk 1 from source B to
destination AMove disk 2 from source B to destination CMove disk 1 from source A to destination
CMove disk 4 from source A to destination BMove disk 1 from source C to destination BMove disk 2
from source C to destination AMove disk 1 from source B to destination AMove disk 3 from source C to
destination BMove disk 1 from source A to destination CMove disk 2 from source A to destination
BMove disk 1 from source C to destination B
PROGRAM

from collections import defaultdictjug1, jug2, aim = 4, 3, 2visited = defaultdict(lambda: False)

def waterJugSolver(amt1, amt2): if (amt1 == aim and amt2 == 0) or (amt2 == aim and amt1 == 0):
print(amt1, amt2) return True if visited[(amt1, amt2)] == False: print(amt1, amt2)
visited[(amt1, amt2)] = True return (waterJugSolver(0, amt2) or waterJugSolver(amt1, 0) or
waterJugSolver(jug1, amt2) or waterJugSolver(amt1, jug2) or
waterJugSolver(amt1 + min(amt2, (jug1-amt1)), amt2 - min(amt2, (jug1-amt1))) or
waterJugSolver(amt1 - min(amt1, (jug2-amt2)), amt2 + min(amt1, (jug2-amt2)))) else:
return Falseprint("Steps: ")waterJugSolver(0, 0)
OUTPUT

Steps:0 04 04 30 33 03 34 20 2
PROGRAM

def aStarAlgo(start_node, stop_node):

open_set = set(start_node)

closed_set = set()

g = {}

parents = {}

g[start_node] = 0

parents[start_node] = start_node
while len(open_set) > 0:

n = None

for v in open_set:

if n == None or g[v] + heuristic(v) < g[n] + heuristic(n):

n=v

if n == stop_node or Graph_nodes[n] == None:

pass

else:

for (m, weight) in get_neighbors(n):

if m not in open_set and m not in closed_set:

open_set.add(m)

parents[m] = n

g[m] = g[n] + weight

else:

if g[m] > g[n] + weight:

g[m] = g[n] + weight

parents[m] = n

if m in closed_set:

closed_set.remove(m)

open_set.add(m)

if n == None:

print('Path does not exist!')

return None
if n == stop_node:

path = []

while parents[n] != n:

path.append(n)

n = parents[n]

path.append(start_node)

path.reverse()

print('Path found: {}'.format(path))

return path

open_set.remove(n)

closed_set.add(n)

print('Path does not exist!')

return None

def get_neighbors(v):

if v in Graph_nodes:

return Graph_nodes[v]

else:

return None

def heuristic(n):

H_dist = {

'A': 11,

'B': 6,
'C': 5,

'D': 7,

'E': 3,

'F': 6,

'G': 5,

'H': 3,

'I': 1,

'J': 0

return H_dist[n]

Graph_nodes = {

'A': [('B', 6), ('F', 3)],

'B': [('A', 6), ('C', 3), ('D', 2)],

'C': [('B', 3), ('D', 1), ('E', 5)],

'D': [('B', 2), ('C', 1), ('E', 8)],

'E': [('C', 5), ('D', 8), ('I', 5), ('J', 5)],

'F': [('A', 3), ('G', 1), ('H', 7)],

'G': [('F', 1), ('I', 3)],

'H': [('F', 7), ('I', 2)],

'I': [('E', 5), ('G', 3), ('H', 2), ('J', 3)],

aStarAlgo('A', 'J')
OUTPUT

Path found: ['A', 'F', 'G', 'I', 'J']


PROGRAM

import math

class GameState:

def __init__(self, board, player_turn):

self.board = board

self.player_turn = player_turn

def print_board(self):

for row in self.board:

print(' | '.join(cell if cell != '' else ' ' for cell in row))

print('-' * 5)

def evaluate(self):

win_conditions = [

[self.board[0][0], self.board[0][1], self.board[0][2]],

[self.board[1][0], self.board[1][1], self.board[1][2]],

[self.board[2][0], self.board[2][1], self.board[2][2]],

[self.board[0][0], self.board[1][0], self.board[2][0]],

[self.board[0][1], self.board[1][1], self.board[2][1]],

[self.board[0][2], self.board[1][2], self.board[2][2]],

[self.board[0][0], self.board[1][1], self.board[2][2]],


[self.board[2][0], self.board[1][1], self.board[0][2]]

for condition in win_conditions:

if condition == ['X', 'X', 'X']:

return 10

if condition == ['O', 'O', 'O']:

return -10

if any(cell == '' for row in self.board for cell in row):

return 0

return 0

def generate_possible_moves(self):

moves = []

for i in range(3):

for j in range(3):

if self.board[i][j] == '':

new_board = [row[:] for row in self.board]

new_board[i][j] = 'X' if self.player_turn else 'O'

moves.append(GameState(new_board, not self.player_turn))

return moves

def is_terminal(self):

return self.evaluate() != 0 or all(cell != '' for row in self.board for cell in row)
def minimax(state, depth, alpha, beta, maximizing_player):

if state.is_terminal() or depth == 0:

return state.evaluate()

if maximizing_player:

max_eval = -math.inf

for move in state.generate_possible_moves():

eval = minimax(move, depth - 1, alpha, beta, False)

max_eval = max(max_eval, eval)

alpha = max(alpha, eval)

if beta <= alpha:

break

return max_eval

else:

min_eval = math.inf

for move in state.generate_possible_moves():

eval = minimax(move, depth - 1, alpha, beta, True)

min_eval = min(min_eval, eval)

beta = min(beta, eval)

if beta <= alpha:

break

return min_eval

def best_move(state, depth):

best_eval = -math.inf if state.player_turn else math.inf

best_move = None
for move in state.generate_possible_moves():

eval = minimax(move, depth - 1, -math.inf, math.inf, not state.player_turn)

if (state.player_turn and eval > best_eval) or (not state.player_turn and eval < best_eval):

best_eval = eval

best_move = move

return best_move

current_board = [

['X', '', ''],

['', '', ''],

['', '', '']

initial_state = GameState(current_board, False)

print("Current Board State:")

initial_state.print_board()

depth = 3

move = best_move(initial_state, depth)

if move:

position = [(i, row.index('O')) for i, row in enumerate(move.board) if 'O' in row][0]

print(f"Best move for the opponent: {position}")

else:

print("No valid move found")

OUTPUT

Current Board State:

X| |
-----

| |

-----

| |

-----

Best move for the opponent: (0, 1)


PROGRAM

import random

def generate_initial_state():

return [random.randint(0, 7) for _ in range(8)]

def heuristic(state):

conflicts = 0

for i in range(8):

for j in range(i + 1, 8):


if state[i] == state[j] or abs(state[i] - state[j]) == abs(i - j):

conflicts += 1

return conflicts

def generate_successors(state):

successors = []

for row in range(8):

for col in range(8):

if col != state[row]:

new_state = state[:]

new_state[row] = col

successors.append(new_state)

return successors

def first_choice_hill_climbing(max_iterations=1000):

iteration = 0

while iteration < max_iterations:

current_state = generate_initial_state()

current_heuristic = heuristic(current_state)

while current_heuristic > 0:

successors = generate_successors(current_state)

next_state = min(successors, key=lambda s: heuristic(s))

next_heuristic = heuristic(next_state)

if next_heuristic >= current_heuristic:

break
current_state = next_state

current_heuristic = next_heuristic

if current_heuristic == 0:

return current_state

iteration += 1

return None

def print_state(state):

board = [['0' for _ in range(8)] for _ in range(8)]

for row in range(8):

board[state[row]][row] = '1'

for row in board:

print(' '.join(row))

print()

solution = first_choice_hill_climbing(max_iterations=5000)

if solution:

print("Solution found:")

print_state(solution)

else:

print("No solution found or local maximum reached.")


OUTPUT

Solution found:

10000000

00000010

00001000

00000001

01000000

00010000

00000100

00100000
PROGRAM

def is_valid(assignment, region, color, adjacency_list):

for neighbor in adjacency_list[region]:

if neighbor in assignment and assignment[neighbor] == color:

return False

return True

def backtrack(assignment, regions, colors, adjacency_list):

if len(assignment) == len(regions):

return assignment

for region in regions:

if region not in assignment:

for color in colors:

if is_valid(assignment, region, color, adjacency_list):

assignment[region] = color

result = backtrack(assignment, regions, colors, adjacency_list)

if result:

return result

del assignment[region]

return None

return None

def map_coloring(regions, colors, adjacency_list):

assignment = {}

return backtrack(assignment, regions, colors, adjacency_list)


def print_solution(solution):

if solution:

for region, color in solution.items():

print(f"Region {region} is colored {color}")

else:

print("No solution found")

regions = ['A', 'B', 'C']

colors = ['Red', 'Green', 'Blue']

adjacency_list = {

'A': ['B', 'C'],

'B': ['A', 'C'],

'C': ['A', 'B']

print("Map coloring solution is found:")

solution = map_coloring(regions, colors, adjacency_list)

print_solution(solution)

OUTPUT

Map coloring solution is found:

Region A is colored Red


Region B is colored Green

Region C is colored Blue


PROGRAM

import random

name = input("What is your name? ")

print("Good Luck, ", name)

words = ['rainbow', 'computer', 'science', 'programming',

'python', 'mathematics', 'player', 'condition',

'reverse', 'water', 'board', 'geeks']

word = random.choice(words)

print("Guess the characters")

guesses = ''

turns = 12

while turns > 0:

failed = 0
for char in word:

if char in guesses:

print(char, end=" ")

else:

print("_", end=" ")

failed += 1

print()

if failed == 0:

print("You Win!")

print("The word is: ", word)

break

guess = input("Guess a character: ")

guesses += guess

if guess not in word:

turns -= 1

print("Wrong!")

print(f"You have {turns} more guesses")

if turns == 0:

print("You Lose")

print("The word was:", word)


OUTPUT

What is your name? abi

Good Luck ! abi

Guess the characters

guess a character:g

Wrong

You have 11 more guesses

_
_

guess a character:r

guess a character:t

Wrong

You have 10 more guesses

guess a character:p

p_

guess a character:l
pl_

guess a character:y

pl_

y_

guess a character:a

play_

guess a character:e

player

You Win

The word is: player


PROGRAM

import numpy as np

import random

from time import sleep

def create_board():

return np.array([[0, 0, 0],

[0, 0, 0],

[0, 0, 0]])

def possibilities(board):

l = []

for i in range(len(board)):
for j in range(len(board)):

if board[i][j] == 0:

l.append((i, j))

return l

def random_place(board, player):

selection = possibilities(board)

current_loc = random.choice(selection)

board[current_loc] = player

return board

def row_win(board, player):

for x in range(len(board)):

win = True

for y in range(len(board)):

if board[x, y] != player:

win = False

break

if win:

return True

return False

def col_win(board, player):

for x in range(len(board)):

win = True

for y in range(len(board)):

if board[y, x] != player:

win = False

break
if win:

return True

return False

def diag_win(board, player):

win = True

for x in range(len(board)):

if board[x, x] != player:

win = False

break

if win:

return True

win = True

for x in range(len(board)):

y = len(board) - 1 - x

if board[x, y] != player:

win = False

break

return win

def evaluate(board):

winner = 0

for player in [1, 2]:

if row_win(board, player) or col_win(board, player) or diag_win(board, player):

winner = player

break

if np.all(board != 0) and winner == 0:

winner = -1 # Draw condition


return winner

def play_game():

board = create_board()

winner = 0

counter = 1

print("Starting board:")

print(board)

sleep(2)

while winner == 0:

for player in [1, 2]:

board = random_place(board, player)

print(f"Board after move {counter}:")

print(board)

sleep(2)

counter += 1

winner = evaluate(board)

if winner != 0:

break

return winner

winner = play_game()

if winner == -1:

print("The game is a draw!")

else:

print(f"The winner is Player {winner}!")


OUTPUT

[[0 0 0]

[0 0 0]

[0 0 0]]

Board after 1 move

[[0 0 0]

[0 0 1]

[0 0 0]]

Board after 2 move

[[0 0 0]

[0 0 1]

[0 0 2]]

Board after 3 move

[[0 0 0]

[1 0 1]

[0 0 2]]

Board after 4 move

[[0 0 0]

[1 2 1]

[0 0 2]]
Board after 5 move

[[0 0 0]

[1 2 1]

[0 1 2]]

Board after 6 move

[[0 0 2]

[1 2 1]

[0 1 2]]

Board after 7 move

[[1 0 2]

[1 2 1]

[0 1 2]]

Board after 8 move

[[1 0 2]

[1 2 1]

[2 1 2]]

Winner is: 2
PROGRAM:

def unify(term1, term2, substitution=None):

if substitution is None:

substitution = {}

if term1 == term2:

return substitution

if is_variable(term1):

return unify_variable(term1, term2, substitution)

if is_variable(term2):

return unify_variable(term2, term1, substitution)

if is_compound(term1) and is_compound(term2):

if term1[0] != term2[0]:

return None

if len(term1) != len(term2):

return None

for subterm1, subterm2 in zip(term1[1:], term2[1:]):

substitution = unify(subterm1, subterm2, substitution)

if substitution is None:

return None

return substitution

return None

def is_variable(term):

return isinstance(term, str) and term.islower()

def is_compound(term):
return isinstance(term, list) and len(term) > 0

def unify_variable(var, value, substitution):

if var in substitution:

return unify(substitution[var], value, substitution)

if value in substitution:

return unify(var, substitution[value], substitution)

if occurs_check(var, value, substitution):

return None

substitution[var] = value

return substitution

def occurs_check(var, term, substitution):

if var == term:

return True

if is_variable(term):

return term in substitution and occurs_check(var, substitution[term], substitution)

if is_compound(term):

return any(occurs_check(var, subterm, substitution) for subterm in term[1:])

return False

term1 = ['king','x']

term2 = ['king','john']

substitution = unify(term1, term2)

print("Substitution:", substitution)

OUTPUT:
Substitution: {'x': 'john'}
PROGRAM:

def forward_chaining(rules, facts):

derived_facts = set(facts)

changes = True

while changes:

changes = False

for antecedent, consequent in rules:

if all(a in derived_facts for a in antecedent):

if consequent not in derived_facts:

derived_facts.add(consequent)

changes = True

return derived_facts

def backward_chaining(goal, rules, facts, depth=0):

if goal in facts:

return True

if depth > 10:

return False

for antecedent, consequent in rules:

if consequent == goal:
if all(backward_chaining(a, rules, facts, depth + 1) for a in antecedent):

return True

return False

def print_results(forward_result, backward_result, goal):

print("Forward Chaining Result:", forward_result)

print("Backward Chaining Result:", backward_result)

rules = [

(['A'], 'B'),

(['B', 'C'], 'D'),

(['D'], 'E')

facts = {'A', 'C'}

goal = 'E'

forward_result = forward_chaining(rules, facts)

backward_result = backward_chaining(goal, rules, facts)

print_results(forward_result, backward_result, goal)


OUTPUT:

Forward Chaining Result: {'C', 'E', 'A', 'D', 'B'}

Backward Chaining Result: True


PROGRAM:

def memory_loss_expert_systems(rules, symptoms):

diagnoses = set()

changes = True

while changes:

changes = False

for antecedent, consequent in rules:

if all(symptom in symptoms for symptom in antecedent):


if consequent not in diagnoses:

diagnoses.add(consequent)

changes = True

return diagnoses

def get_user_symptoms():

print("Welcome to the Memory Loss Expert System.")

print("Please enter symptoms separated by commas (e.g., forgetfulness, confusion):")

user_input = input("Symptoms: ").strip()

symptoms = set(symptom.strip() for symptom in user_input.split(','))

return symptoms

def print_diagnosis(diagnoses):

if diagnoses:

print("\nPossible diagnoses:")

for diagnosis in diagnoses:

print(f"- {diagnosis}")

else:

print("\nNo diagnosis can be made based on the provided symptoms.")

rules = [

(['forgetfulness', 'confusion', 'difficulty concentrating'], 'Alzheimer\'s Disease'),

(['short-term memory loss', 'disorientation'], 'Mild Cognitive Impairment'),

(['long-term memory loss', 'confusion'], 'Dementia'),

(['difficulty finding words', 'disorientation'], 'Frontotemporal Dementia'),

(['severe memory loss', 'difficulty with daily tasks'], 'Severe Cognitive Impairment')

]
user_symptoms = get_user_symptoms()

possible_diagnoses = memory_loss_expert_systems(rules, user_symptoms)

print_diagnosis(possible_diagnoses)
OUTPUT:

Welcome to the Memory Loss Expert System.

Please enter symptoms separated by commas (e.g., forgetfulness, confusion):

Symptoms: forgetfulness, confusion, difficulty concentrating

Possible diagnoses:

- Alzheimer's Disease
PROGRAM:
def get_user_symptoms():

symptoms = {

'fever': None,

'cough': None,

'sore throat': None,

'body aches': None,

'fatigue': None,

'headache': None,

'chills': None,

'runny nose': None,

'nausea': None,

'vomiting': None,

'diarrhea': None

print("Welcome to the Influenza Diagnosis Expert System.")

for symptom in symptoms:

while True:

response = input(f"Are you experiencing {symptom}? (yes/no): ").strip().lower()

if response in ['yes', 'no']:

symptoms[symptom] = response == 'yes'

break

else:

print("Invalid response. Please answer 'yes' or 'no'.")

return symptoms

def diagnose_influenza(symptoms):
if (

symptoms['fever'] and

symptoms['cough'] and

symptoms['body aches'] and

symptoms['fatigue'] and

symptoms['headache'] and

symptoms['chills'] and

not symptoms['sore throat'] and

not symptoms['runny nose'] and

not symptoms['nausea'] and

not symptoms['vomiting'] and

not symptoms['diarrhea']

):

return "Based on your symptoms, it is possible that you have influenza."

else:

return "Based on your symptoms, it is less likely that you have influenza.

Please consult a health care professional for a more accurate diagnosis."

def main():

user_symptoms = get_user_symptoms()

diagnosis = diagnose_influenza(user_symptoms)

print(diagnosis)

if __name__ == "__main__":

main()
OUTPUT:

Welcome to the Influenza Diagnosis Expert System.

Are you experiencing fever? (yes/no): yes

Are you experiencing cough? (yes/no): yes

Are you experiencing sore throat? (yes/no): no

Are you experiencing body aches? (yes/no): yes

Are you experiencing fatigue? (yes/no): yes

Are you experiencing headache? (yes/no): no

Are you experiencing chills? (yes/no): no


Are you experiencing runny nose? (yes/no): yes

Are you experiencing nausea? (yes/no): yes

Are you experiencing vomiting? (yes/no): no

Are you experiencing diarrhea? (yes/no): no

Based on your symptoms, it is less likely that you have influenza.

Please consult a health care professional for a more accurate diagnosis.


PROGRAM:

import pandas as pd

import numpy as np

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

from fairlearn.metrics import (

demographic_parity_difference,

equalized_odds_difference,

selection_rate,

np.random.seed(42)

data_size = 1000
data = {

'income': np.random.randint(30000, 120000, size=data_size),

'age': np.random.randint(18, 70, size=data_size),

'gender': np.random.choice(['male', 'female'], size=data_size),

'loan_approved': np.random.choice([0, 1], size=data_size, p=[0.3, 0.7])

df = pd.DataFrame(data)

df['gender'] = df['gender'].map({'male': 0, 'female': 1})

X = df[['income', 'age', 'gender']]

y = df['loan_approved']

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

model = RandomForestClassifier(random_state=42)

model.fit(X_train, y_train)

y_pred = model.predict(X_test)

accuracy = accuracy_score(y_test, y_pred)

demographic_parity = demographic_parity_difference(y_test, y_pred, sensitive_features=X_test['gender'])

equalized_odds = equalized_odds_difference(y_test, y_pred, sensitive_features=X_test['gender'])

intercept = model.predict_proba(X_test)[:, 1].mean()

prediction_local = model.predict_proba(X_test[0].values.reshape(1, -1))[0]

print(f"Accuracy: {accuracy:.2f}")

print(f"Demographic Parity Difference: {demographic_parity:.2f}")

print(f"Equalized Odds Difference: {equalized_odds:.2f}")

print(f"Intercept (mean probability): {intercept:.2f}")

print(f"Prediction for first sample: {prediction_local}")

print(f"Actual class for first sample: {y_test.values[0]}")


OUTPUT:

Accuracy:0.75

Demographic Parity Difference: 0.05 Equalized

Odds Difference:0.08

Intercept 0.17

Prediction_local{0.55 0.45]

Right :0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy