ML_assignment_6

.pdf

School

Drexel University *

*We aren’t endorsed by this school

Course

613

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

5

Uploaded by CaptainMantisMaster961

Report
Machine Learning Assignment 6 - Probabilistic Models Fall 2023 Meet Sakariya 14473322 1 Theory 1 (a) Computer the posteriors for the observation i. Inference (5pts) Solution: Posterior using Inference: P(y=+ |x=[T,T]) = 3/12 = 0.25 P(y=- |x=[T,T]) = 0/12 = 0 Normalize: P(y=+ |x=[T,T]) = 0.25/(0.25+0) = 1 P(y=- |x=[T,T]) = 0/(0.25+0) = 0 ii. Naive Bayes (5pts) Solution: Posterior using Naive Bayes: P(y=+) = 12/21 = 0.571 P(x1=T y=+) = (3+4)/12 = 0.583 P(x2=T y=+) = (3+4)/12 = 0.583 x = [ ] using: 1. Consider the following set of training examples for an unknown target function: ( Y x1 x2 Count + T T 3 + T F 4 + F T 4 + F F 1 - T T 0 - T F 1 - F T 3 - F F 5 ) : T,T x1, x2 y | |
2 P(y=-) = 9/21 = 0.428 P(x1=T |y=-) = 1/9 = 0.111 P(x2=T |y=-) = 3/9 = 0.333 Naive Bayes for x = [T, T] P(Y |X) = (P(Y).P(X|Y))/P(X) P(Y=+).P(x1=T|Y=+).P(x2=T|Y=+) and P(Y |X) = (P(Y).P(X|Y))/P(X) P(Y=-).P(x1=T|Y=-).P(x2=T|Y=-) P(y=+ |x=[T,T]) = (0.571)(0.583)(0.583) = 0.194 P(y=- |x=[T,T]) = (0.428)(0.111)(0.333) = 0.016 Normalize: P(y=+ x) = 0.194/(0.194+0.016) = 0.924 P(y=- x) = 0.016/(0.194+0.016) = 0.076 | |
2 NaiveBayesClassifier Let’s train and test a dataset. 3 1. Description of any additional pre-processing of the dataset you did. 2. The validation accuracy of your system. 3. Your confusion matrix. to classifiy the fetal state from the Cartiotocography Here are the main pre-processing steps I performed on the CTG dataset: 1) I shuffled the rows randomly using scikit-learn’s shuffle function to ensure the training and vali- dation sets contain a random mix of samples. 2) I split the shuffled dataframe into a training set with the first 2/3 observations and a validation set with the remaining 1/3 observations. 3) For each feature, I computed the mean value from the training data. Then I binarized each feature in the training and validation sets by setting values >= mean to 1 and values < mean to 0. This pre-processes the continuous features to be more suitable for naive Bayes. 4) The original data had a ’CLASS’ column that I discarded, only keeping the ’NSP’ target column. Accuracy: 0.8486562942008486 Confusion matrix: 1. Reads in the data. 2. Shuffles the observations 3. Selects the first 2/3 (round up) of the data for training and the remaining for validation. 4. Pre-processes the data. Although technically some of the columns are discerete valued, let’s treat them all as continuous and convert them to binary ones using the mean of that feature, as computed from the training data. 5. You can now using the training dataset to compute: (a) Class priors (b) Naive probabilities, P(xi |y) for each feature of each class 6. Given that information, you can now classifies each validation sample. Naive Bayes Classifier Solution: Write a script that: In your report you will need:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help