The image as attached is my question, I already have the answer with red text. Also I implement a python code for this question as follow: And all you need to do is help me check the python code. If there is any error, please help me correct it, thank you. # import the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd import sklearn from sklearn import preprocessing from sklearn.preprocessing import LabelEncoder from sklearn.naive_bayes import GaussianNB #0.2 Assigning features and label variables ID = ['1234', '6754', '2345','2457','3567','7532','1456','1468','8989','9876'] Temp = ['H','H','N','H','N','N','N','H','H','H'] BP = ['H','N','H','H','H','H','N','N','N','N'] Test1 = ['P','N','P','P','P','N','N','N','N','N'] Test2 = ['N','P','P','N','P','N','N','N','P','N'] Health = ['D','D','D','D','D','H','H','H','H','H'] #0.3 Creating labelEncoder and Converting string labels into numbers. le = preprocessing.LabelEncoder() Temp_encoded=le.fit_transform(Temp) print("The encoded temp values are: {}".format(Temp_encoded)) BP_encoded=le.fit_transform(BP) print("The encoded BP values are: {}".format(BP_encoded)) Test1_encoded=le.fit_transform(Test1) print("The encoded Test1 values are: {}".format(Test1_encoded)) Test2_encoded=le.fit_transform(Test2) print("The encoded Test2 values are: {}".format(Test2_encoded)) Health_encoded=le.fit_transform(Health) print("The encoded Health values are: {}".format(Health_encoded)) #0.3.1 Now combine all the features in a single variable (list of tuples). features=zip(Temp_encoded,BP_encoded,Test1_encoded,Test2_encoded) features = list(features) print(features) #0.4 Create a Naive Bayesian Classifier and train the model using the training sets model = GaussianNB() model.fit(features,Health_encoded) #0.5 Predict the output for the new patient: 0: Diseased and 1: Healthy # a) giving value of each term in our NB classifier predicted= model.predict([[0,0,0,1]]) # b) Our Prediction print("Predicted Value:", predicted) #0.6 So our prediction shows the new patient’s health as Healthy (H).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The image as attached is my question, I already have the answer with red text.

Also I implement a python code for this question as follow:

And all you need to do is help me check the python code.

If there is any error, please help me correct it, thank you.

# import the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import sklearn
from sklearn import preprocessing
from sklearn.preprocessing import LabelEncoder
from sklearn.naive_bayes import GaussianNB

#0.2 Assigning features and label variables

ID = ['1234', '6754', '2345','2457','3567','7532','1456','1468','8989','9876']
Temp = ['H','H','N','H','N','N','N','H','H','H']
BP = ['H','N','H','H','H','H','N','N','N','N']
Test1 = ['P','N','P','P','P','N','N','N','N','N']
Test2 = ['N','P','P','N','P','N','N','N','P','N']
Health = ['D','D','D','D','D','H','H','H','H','H']

#0.3 Creating labelEncoder and Converting string labels into numbers.

le = preprocessing.LabelEncoder()
Temp_encoded=le.fit_transform(Temp)
print("The encoded temp values are: {}".format(Temp_encoded))
BP_encoded=le.fit_transform(BP)
print("The encoded BP values are: {}".format(BP_encoded))
Test1_encoded=le.fit_transform(Test1)
print("The encoded Test1 values are: {}".format(Test1_encoded))
Test2_encoded=le.fit_transform(Test2)
print("The encoded Test2 values are: {}".format(Test2_encoded))

Health_encoded=le.fit_transform(Health)
print("The encoded Health values are: {}".format(Health_encoded))

#0.3.1 Now combine all the features in a single variable (list of tuples).

features=zip(Temp_encoded,BP_encoded,Test1_encoded,Test2_encoded)
features = list(features)
print(features)

#0.4 Create a Naive Bayesian Classifier and train the model using the training sets

model = GaussianNB()
model.fit(features,Health_encoded)

#0.5 Predict the output for the new patient: 0: Diseased and 1: Healthy

# a) giving value of each term in our NB classifier
predicted= model.predict([[0,0,0,1]])
# b) Our Prediction
print("Predicted Value:", predicted)

#0.6 So our prediction shows the new patient’s health as Healthy (H).

2. (15 pts) Given the following data set, we apply a naïve Bayesian (NB) classifier to predict the Health status.
Each patient is described by Temp={H,N}, BP={H,N}, Test1={P,N} and Test2={P,N}. The class is Health={D,H}.
ID
Temp
ВР
Test1
Test2
Health
1234
H
H.
N
6754
H
N
N
P
D
2345
N
H
P
P
2457
H
H.
P
N
D
3567
N
H
P
7532
N
H.
N
N
H
1456
N
N
N
H
1468
H
N
N
N
H
8989
H
N
N
P
H
9876
H
N
N
N
H
For a new patient, ID 9999, with Temp=H, BP=H, Test1=N, Test2=P, is he/she Healthy (H) or Diseased (D)?
Show (a) the value of each term in your NB classifier, and (b) your prediction.
Answer:
P_temp(H/D)=3/5, P_temp(N/D)=2/5
P_temp(H/H)=3/5, P_temp(N/H)=2/5
P_BP(H/D)=4/5, P_BP(N/D)=1/5
P_BP(H/H)=1/5, P_BP(N/H)=4/5
P_Test1(P/D)=4/5, P_Test1(N/D)=1/5
P_Test1(P/H)=0/5, P_Test1(N/H)=5/5
P_Test2(P/D)=3/5, P_Test2(N/D)=2/5
P_Test2(P/H)=1/5, P_Test2(N/H)=4/5
new patient A: Temp=H, BP=H, Test1=N, Test2=P
S((H,H,N,P),D) = 3/5 * 4/5 * 1/5 * 3/5 = 0.0576
S((H,H,N,P),H) = 3/5 * 1/5 * 5/5 * 1/5 = 0.024
S((H,H,N,P),D) > S((H,H,N,P),H)
So predict A as class D.
Transcribed Image Text:2. (15 pts) Given the following data set, we apply a naïve Bayesian (NB) classifier to predict the Health status. Each patient is described by Temp={H,N}, BP={H,N}, Test1={P,N} and Test2={P,N}. The class is Health={D,H}. ID Temp ВР Test1 Test2 Health 1234 H H. N 6754 H N N P D 2345 N H P P 2457 H H. P N D 3567 N H P 7532 N H. N N H 1456 N N N H 1468 H N N N H 8989 H N N P H 9876 H N N N H For a new patient, ID 9999, with Temp=H, BP=H, Test1=N, Test2=P, is he/she Healthy (H) or Diseased (D)? Show (a) the value of each term in your NB classifier, and (b) your prediction. Answer: P_temp(H/D)=3/5, P_temp(N/D)=2/5 P_temp(H/H)=3/5, P_temp(N/H)=2/5 P_BP(H/D)=4/5, P_BP(N/D)=1/5 P_BP(H/H)=1/5, P_BP(N/H)=4/5 P_Test1(P/D)=4/5, P_Test1(N/D)=1/5 P_Test1(P/H)=0/5, P_Test1(N/H)=5/5 P_Test2(P/D)=3/5, P_Test2(N/D)=2/5 P_Test2(P/H)=1/5, P_Test2(N/H)=4/5 new patient A: Temp=H, BP=H, Test1=N, Test2=P S((H,H,N,P),D) = 3/5 * 4/5 * 1/5 * 3/5 = 0.0576 S((H,H,N,P),H) = 3/5 * 1/5 * 5/5 * 1/5 = 0.024 S((H,H,N,P),D) > S((H,H,N,P),H) So predict A as class D.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY