fam_pr_qb
fam_pr_qb
Consider following
tree. Start node = 2, Goal node = 11
=>graph = {
'2' : ['7','5'],
'7' : ['1','6'],
'1' : [],
'6' : ['5','11'],
'5' : [],
'11' :[],
'5' : ['9'],
'9' : ['4'],
'4' : []
}
visited = []
queue = []
while queue:
m = queue.pop(0)
print(m, end = " ")
graph = {
'5' : ['3','7'],
'3' : ['2','4'],
'7' : ['5','8'],
'2' : ['3'],
'4' : ['3','8'],
'8' : ['7','4'],
}
visited = []
queue = []
def bfs (visited, graph, node):
visited.append(node)
queue.append(node)
while queue :
m=queue.pop(0)
print(m)
print("BFS is ")
bfs(visited, graph, '5')
graph ={
's' : ['a','k'],
'a' : ['b','c'],
'k' : ['i','j'],
'b' : ['h','m'],
'c' : ['n'],
'i' : ['o'],
'j' : [],
'h' : [],
'm' : [],
'n' : [],
'o' : []
}
visited =set()
def dfs (visited, graph, node):
if node not in visited:
print (node)
visited.add(node)
for neighbour in graph[node]:
dfs (visited, graph, neighbour)
graph ={
'1' : ['2','3'],
'2' : ['4','5'],
'3' : ['6','7'],
'4' : [],
'5' : [],
'6' : [],
'7' : [],
}
visited =set()
def dfs (visited, graph, node):
if node not in visited:
print (node)
visited.add(node)
for neighbour in graph[node]:
dfs (visited, graph, neighbour)
5. Implement best first search algorithm in python for following tree. Starting
node (10), Goal node (100).
6. Implement best first search algorithm in python for following graph.
Starting node(S), Goal node(G)
while pq:
_, current = pq.get()
if current in visited:
continue
print (current)
visited.add(current)
if current == goal:
print("Goal reached!")
return
=>
from queue import PriorityQueue
def a_star(graph, start, goal, h):
pq = PriorityQueue()
pq.put((h[start], start, 0, []))
while pq:
_, current, g, path = pq.get()
path = path + [current]
if current == goal:
return path, g
for neighbor, cost in graph[current]:
pq.put((g + cost + h[neighbor], neighbor, g + cost, path))
return None,
graph = {
's': [('a', 1), ('g', 10)],
'a': [('b', 2),('s', 1),('c',1)],
'b': [('d', 5),('a', 2)],
'c': [('g', 4),('a',1)],
'd': [('g', 2),('b', 5)],
'g': []
}
h = {'s': 5, 'a': 3, 'b': 4, 'c': 2, 'd': 6, 'g': 0}
path, cost = a_star(graph, 's', 'g', h)
print("Path: ",path)
print("Cost: ",cost)
8. Build model on data sets for Credit Card Fraud Detection Dataset.
9. Build model on data sets for E-mail Spam Detection.
10. Build model on data sets for Lung Cancer Detection.
11. Perform EDA on data sets for Gold Price Prediction.
12. Build model on NLP Emotion Detection Dataset.
13. Build model on NLP for Twitter Dataset.
14. Build model on NLP for Fake News Dataset.
15. Use Python to analyse & load a Flight price prediction dataset into training
and Testing sets.
16. Write a program to analyse & load Iris flower dataset using Python and
perform training and testing.
17. Write a Python program to implement Simple Linear Regression using a
real-world dataset for house prices.
18. Write a Python program to implement Simple Linear Regression using a
real-world dataset stock prices.
19. Write a Python program to implement Multiple Linear Regression for car
price prediction.
20. Write a Python program to implement Multiple Linear Regression for wine
quality prediction.
for logistic regression the code will be :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
df=pd.read_csv('Heart_disease_cleveland_new.csv')
df.head()
df.shape
df.info()
df.isnull.sum()
df.columns
df.hist(figsize=(15,15),color='blue')
sns.heatmap(df.corr(),annot=True)
x=df.drop(columns=['placed'])
y=df['placed']
X_train,X_test,y_train,y_test=train_test_split(x,y,test_size=0.20,random_state=42)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
model=LogisticRegression()
model.fit(X_train,y_train)
score=model.score(X_train,y_train)
score
y_pred=model.predict(X_test)
y_pred