ML_assignment_6.pdf

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
4
3 AdditionalDataset 5 Now let’s see how your systems work on another multi-class dataset, the Yale Faces dataset! As with the prior assignment, read in all the images, resize them to be 40 × 40 images (use nearest neighbors so no interpolation occurs), then reshape into 1 × 1600 feature vectors, such that in the end we have a 154 × 1600 observable data matrix. As far as pre-processing the features, as long as you used nearest neighbors for resizing your images, all the features will be discrete [0,255], so there’s no need to zscore or convert features to categorical. We’ll again be classifying the subject, so again you should divide your training and validation ac- cording to subject (2/3 of each subject for training, 1/3 for validating). Plug this into your Naive Bayes implementation and again report the validation accuracy and confusion matrix. Solution: Here are the main pre-processing steps I performed on the Yale Faces dataset: 1) I extracted the subject ID from the filename of each image to get the class label 2) I resized each image to 40x40 pixels using nearest neighbor interpolation to keep the pixel values discrete while reducing the image size. 3) Each 40x40 image was flattened into a 1D array of length 1600 (40 * 40 pixels). 4) The dataset was split stratified by subject into 2/3 training and 1/3 validation sets to ensure the same distribution of subjects in each set. 5) Since the pixel values are discrete integers in [0,255], I did not standardize or normalize the feature Accuracy: 0.7843137254901961 Confusion matrix: