$24
Task description
In this assignment you will implement the K‐Nearest Neighbour and Naïve Bayes algorithms and evaluate them on a real dataset using the stratified cross validation method. You will also evaluate the performance of other classifiers on the same dataset using Weka. Finally, you will investigate the effect of feature selection, in particular the Correlation‐based Feature Selection method (CFS) from Weka.
Late submissions policy
Penalty for late submission is 1 mark per day, including the weekends. If the assignment is submitted more than 7 days after the deadline, it will not be accepted. The day is considered to end at 5:00pm, i.e. if the assignment is submitted at 5:05pm on 6th of May it will be considered one day late.
Programming languages
Your implementation can be written in Python, Java, C, C++ or MATLAB. The assignment will be tested on the University machines, so your code must be compatible with the language version installed on those machines. You are not allowed to use any of the built‐in classification libraries for the purposes of this assignment.
Note for those considering using MATLAB: the online submission system does not have the capability of running MATLAB code, and so any MATLAB submissions will be manually marked only, after the due date. The code will be marked to the same standards as the other languages; however you will not get to see the automatic testing results. Keep this in mind if you choose to complete the assignment in MATLAB.
Submission and pair work
Your assignment can be completed individually or in pairs. See the submission details section for more information about how to submit.
This assignment will be submitted using the submission tool PASTA (http://comp3308.it.usyd.edu.au). In order to connect to the website, you’ll need to be connected to the university VPN. You can read this page to find out how to connect to the VPN. PASTA will allow you to make as many submissions as you wish, and each submission will provide you with feedback on each of the components of the assignment. You last submission before the assignment deadline will be marked, and the mark displayed on PASTA will be the final mark for your code (12 marks).
Introduction to Artificial Intelligence Page 1 of
Data
The dataset for this assignment is the Pima Indian Diabetes dataset. It contains 768 instances described by 8 numeric attributes. There are two classes ‐ yes and no. Each entry in the dataset corresponds to a patient’s record; the attributes are personal characteristics and test measurements; the class shows if the person shows signs of diabetes or not. The patients are from Pima Indian heritage, hence the name of the dataset.
A copy of the dataset can be downloaded from Blackboard. There are 2 files associated with the dataset. The first file, *.names, describes the data, including the number and the type of the attributes and classes, as well as their meaning. The second file, *.data, contains the data itself. Your task is to predict the class, where the class can be yes or no.
Note: The original dataset can be sourced from UCI Machine Learning Repository. However, you need to use the dataset available on Blackboard as it has been modified for consistency.
Data preprocessing
Read the pima‐indians‐diabetes.names file and learn more about the meaning of the attributes and the classes. Use Weka’s in‐built normalisation filter to normalise the values of each attribute to make sure they are in the range [0,1]. The normalisation should be done along each column (attribute), not each row (entry). The class attribute is not normalised – it should remain unchanged. Save the preprocessed file as pima.csv.
Warning: In order to ensure that Weka can process the data, you will need to add headers to the data file and save it as a .csv file. The headers should be removed after preprocessing.
Classification algorithms
K‐Nearest Neighbour
The K‐Nearest Neighbour algorithm should be implemented for any K value and should use Euclidean distance as the distance measure. If there is ever a tie between the two classes, choose class yes.
Naïve Bayes
The Naïve Bayes should be implemented for numeric attributes, using a probability density function. Assume a normal distribution, i.e. use the probability density function for a normal distribution. As before, if there is ever a tie between the two classes, choose class yes.
Note: Carefully read section 6 to find out how your program will be expected to receive input and give output.
10‐fold stratified cross‐validation
In order to evaluate the performance of the classifiers, you will have to implement 10‐fold stratified cross‐validation. Your program should be able to show the algorithm’s average accuracy over the 10 folds. This information will be required to complete the report.
Your implementation of 10‐fold stratified cross‐validation will be tested based on your pima‐ folds.csv file. The information about the folds should be stored in pima‐folds.csv in the following format for each fold:
Name of the fold, fold1 to fold10.
Contents of the fold, with each entry on a new line.
A single blank line to separate the folds from each other.
An example of the pima‐folds.csv file would look as follows (made up data):
fold1
0.588,0.628,0.574,0.263,0.136,0.463,0.054,0.333,yes
0.243,0.274,0.224,0.894,0.113,0.168,0.735,0.321,no
fold2
0.588,0.628,0.574,0.263,0.136,0.463,0.054,0.333,yes
0.243,0.274,0.224,0.894,0.113,0.168,0.735,0.321,no
...
fold10
0.588,0.628,0.574,0.263,0.136,0.463,0.054,0.333,yes
0.243,0.274,0.224,0.894,0.113,0.168,0.735,0.321,no
Note: The number of instances per fold should not vary by more than one. If the total number of instances is not divisible by ten, the remaining items should be distributed amongst the folds rather than being placed in one fold.
Feature selection
Correlation‐based feature selection (CFS) is a method for selecting a subset of the original attributes. It searches for the best subset of features, where best is defined by a heuristic which considers how good the individual features are at predicting the class and how much they correlate with the other features. Good subsets of features contain features that are highly correlated with the class and uncorrelated with each other.
Load the pima.csv file inWeka, and apply CFS to reduce the number of features. It is available from the “Select attributes” tab in Weka. Use “Best‐First Search” as the search method. Save the CSV file with the reduced number of attributes (this can be done in Weka) and name it pima‐CFS.csv.
Warning: As before, in order to ensure Weka can understand the data, you’ll need to add headers. Once you are done processing, remove the headers
Input and output
Input
Your program will need to be named MyProgram, however may be written in any of the languages mentioned in the “Programming languages” section.
Your program should take 3 command line arguments. The first argument is the path to the training data file, the second is the path to the testing data file, and the third is the name of the algorithm to be executed (NB for Naïve Bayes and kNN for the Nearest Neighbour, where k is replaced with a number; e.g. 5NN).
For example, if you were to make a submission in Java, your main class would be MyProgram.java, and the following are possible inputs to the program:
$ java MyProgram pima.csv examples.csv NB
$ java MyProgram pima‐CFS.csv examples.csv 4NN
The input testing data file will consist of several new examples to test your data on. The file will not have headers, will have one example per line, and each line will consist of a normalised value for each of the 8 non‐class attributes separated by commas. An example input file would look as follows:
0.588,0.628,0.574,0.263,0.136,0.463,0.054,0.333
0.243,0.274,0.224,0.894,0.113,0.168,0.735,0.321
0.738,0.295,0.924,0.113,0.693,0.666,0.486,0.525
Output
Your program will output to standard output (a.k.a. “the console”). The output should be one class value (yes or no) per line – each line representing your program’s classification of the corresponding line in the input file. An example output should look as follows:
yes
no
yes
Note: These outputs are in no way related to the sample inputs given above. If you have any questions or need any clarifications about program input or output, ask a question on Piazza or ask your tutor. Since your program will be automatically tested by PASTA, it is important that you follow the instructions exactly.
Weka evaluation
In Weka select 10‐fold cross validation (it is actually 10‐fold stratified cross validation) and run the following algorithms: ZeroR, 1R, k‐Nearest Neighbor (k‐NN; IBk in Weka), Naïve Bayes (NB), Decision Tree (DT; J48 in Weka) and Multi‐Layer Perceptron (MLP).
Compare their performance with your k‐Nearest Neighbor and Naïve Bayes classifiers. Do this for the case without feature selection (using pima.csv) and with CFS feature selection (using pima‐ CFS.csv).
Report
You will have to describe your analysis and findings in a report similar to a research paper. Your report should include 5 sections. There is no minimum or maximum length for the report – you will be marked on the quality of the content that you provide.
Aim
This section should briefly state the aim of your study, e.g. predicting X based on Y etc., and include a paragraph about why this problem is important.
Data
This section should describe the dataset, mentioning the number of attributes and classes. It should also briefly describe the CFS method and list the attributes selected by the CFS.
Results and discussion
The accuracy results should be presented (in percentage, using 10‐fold cross validation) in the following table where My1NN, My5NN and MyNB are your implementations of the 1NN, 5NN and NB algorithms, evaluated using your stratified 10‐fold cross validation.
ZeroR
1R
1NN
5NN
NB
DT
MLP
No feature
selection
CFS
My1NN My5NN MyNB
No feature
selection
CFS
In the discussion, compare the performance of the classifiers, with and without feature selection. Compare your implementations of k‐NN and NB with Weka’s. Discuss the effect of the feature selection – did CFS select a subset of the original features, and if so, did the selected subset make intuitive sense to you? Was feature selection beneficial, i.e. did it improve accuracy, or have any other advantages? Why do you think this is the case? Include anything else that you consider important.
Conclusion
Summarise your main findings and, if possible, suggest future work.
Reflection
Write one or two paragraphs describing the most important thing that you have learned throughout this assignment.
Submission Details
This assignment is to be submitted electronically via the PASTA submission system.
Individual submissions setup
The first thing you must do is create an individual group on PASTA. This is due to a limitation of PASTA.
To create a group, follow the instructions below:
Click on the group management icon on PASTA, under the submit button:
Click on “Add a New Group”
Click on “Join Group” next to the group you just created.
Click on “Lock Group” to lock the group and stop others from joining the group.
Pair submissions setup
The first thing you must do is create/join a group on PASTA. Follow the instructions below:
Click on the group management icon on PASTA, under the submit button:
If your pair has not yet formed a group on PASTA, click on “Add a New Group”, otherwise go to step 3.
Click on “Join Group” next to your group in the “Other Existing Groups” section.
If you wish to stop anyone from joining your group, click on “Lock Group”.
All submissions
Your submission should be zipped together in a single .zip file and include the following:
The report in PDF format.
The source code with a main program called MyProgram. Valid extensions are .java, .py,
.c, .cpp, .cc, and .m.
Three data files: pima.csv, pima‐CFS.csv and pima‐folds.csv.
A valid submission might look like this:
submission.zip
|‐ pima.csv
|‐ pima‐folds.csv
|‐ pima‐CSF.csv
|‐ report/
| +‐ report.pdf
|‐ MyProgram.java
+‐ extrapackage/
|‐ MyClass.java
+‐ OtherClass.java
Upload your submission on PASTA under Assignment 1. Make sure you tick the box saying that you’re submitting on behalf of your group (even if you’re working individually). The submission won’t work if you don’t.
Introduction to Artificial Intelligence Page 6 of 7
COMP3308
Marking criteria
[12 marks] Code – based on the tests in PASTA; automatic marking [8 marks] Report:
[0.5 marks] Introduction
What is the aim of the study?
Why is this study (the problem) important?
[0.5 marks] Data – well explained
Dataset – brief description of the dataset
Attribute selection – brief summary of CFS and a list of the selected attributes
[4 marks] Results and discussion
All results presented
Correct and deep discussion of the results
Effect of the feature selection – beneficial or not (accuracy, other advantages)
Comparison between the classifiers (accuracy, other advantages)
[1.5 marks] Conclusions and future work
Meaningful conclusions based on the results
Meaningful future work suggested
[0.5 marks] Reflection (meaningful and relevant personal reflection)
[1 marks] English and presentation
Academic style, grammatical sentences, no spelling mistakes
Good structure and layout; consistent formatting
Penalty for late submission:
‐1 mark for each day late
Introduction to Artificial Intelligence Page 7 of 7