CN710-Structured Activities

advertisement
CELEST Application Building Framework for CN710 : Structured Activity
This document describes development and testing activities based on the CN710 Learning Game Application.
This activity helps you to build a data set to represent the problem domain, and to write a classifier program
as well as custom evaluation criteria code.
I. Development
1. Data set Construction for Circle in Square
1) Download cis_train1.txt from http://www.cns.bu.edu/~chhsiao/cis_train1.txt (Open web page -> Choose
File from the toolbar menu -> Save As -> .txt file)
2) Download makewikafilesGeneral.m from http://www.cns.bu.edu/~chhsiao/makewikafilesGeneral.m
(Open web page -> Choose File from the toolbar menu -> Save As -> .txt file)
3) Put the makewikafilesGeneral.txt and cis_train1.txt in the same directory
4) Open Matlab
5) Select the current directory
6) In Matlab, type
load cis_train1.txt;
LoadMatrix = cis_train1;
save cis_train1;
makewikafilesGeneral(‘cis_train1.mat’,’cis_train1.arff’);
7) The final result that you get should look like the following
1
2. Classifier Construction (ZeroR Algorithm)
1) Write a Class for building and using a 0-R classifier. This predicts the mean (for a numeric class) or the
mode (for a nominal class).
1.1)
Go to http://www.cns.bu.edu/~chhsiao/ZeroR.java
This is the actual program. You must try to write this program on your own after you have got your
java basics correct.
The steps to write this code is given as follows
1.2)
Set up New Java Class for classifier code
1.2.1) On the Package Explorer tab in the Eclipse environment, right click on weka.classifiers.functions-> New
–> Class -> Enter a name ->Finish
1.3) Write classifier code as a Java class. See http://www.mindview.net/Books/TIJ/ for information about Java
Programming
1.3.1) In the window opened for [yourclassname.java], start writing the code as follows
2
The program:
//Include the necessary import(s)
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import java.io.*;
import java.util.*;
import weka.core.*;
/*The main class should follow, which
implements WeightedInstanceHandler*/
public class [your class
WeightedInstanceHandler{
name]
extends
extends
Classifier
Classifier
/*inlcude
the
variables
to
be
http://www.cns.bu.edu/~chhsiao/ZeroR.java*/
and
implements
declared:
refer
//write a method that returns a string describing classifier
public String globalInfo(){return “”;}
//write a method to generate the classifer
public void buildClassifier(Instance instances) throws Exception{
refer http://www.cns.bu.edu/~chhsiao/ZeroR.java
}
//write a method to classify a given instance
public double classifyInstance(Instance instance){
return
}
/*write a method to calculate the class membership probabilities
for the given test instance*/
public double [] distributionForInstance(Instance instance) throws
Exception{ refer http://www.cns.bu.edu/~chhsiao/ZeroR.java
}
3
//write a method to return a description of the classifier
public String tostring()
{refer http://www.cns.bu.edu/~chhsiao/ZeroR.java}
//write the main method for testing this class
public static void main(String [] argv){
refer http://www.cns.bu.edu/~chhsiao/ZeroR.java
}
}
2) Save your program
3. Evaluation Criteria (User Defined)
1) Write a Class for writing an evaluation criteria.
1.1)Set up New Java Class for evaluation criteria code
1.1.1)
On
the
Package
Explorer
tab
in
the
Eclipse
environment,
edu.bu.cps.celest.learninggame.eval-> New –> Class -> Enter a name ->Finish
4
right
click
on
1.2) Write classifier code as a Java class. See http://www.mindview.net/Books/TIJ/ for information about Java
Programming
1.2.1) In the window opened for [yourclassname.java], start writing the code as follows
The program:
//Include the necessary import(s)
import edu.bu.cps.celest.learninggame.eval.Eval;
import weka.core.Instance;
/*The main class should follow, which extends Eval*/
public class [your class name] extends Eval{
/*inlcude the variables to be declared: refer CN710 Evaluation Criteria
Construction 3.2*/
//write a constructor
public [your class name] (){}
//write a method Evaluate
public void Evaluate(Instance inst,double pred) throws Exception{
//refer CN710 Evaluation Criteria Construction 3.2
}
//write a method to generate output
public StringBuffer Output(){
// refer CN710 Evaluation Criteria Construction 3.2
}
}
2) Save your program
5
II. Testing
1) Run your program
2) Click on the Preprocess tab
Click This
3) Click on Open File
Click This
6
4) Select the dataset :cis_train1.arff
5) You will get a data set window.
6) Select the classify tab
Classify
7
7) Click the Choose button
Choose
8) A drop-down menu box will appear and from weka-classifiers-functions select your java file (ZeroR)
9) Click on the more options to set the Classifier evaluation options
Click here to select the
evaluation criteria
8
Default options are preselected
Choose the
evaluation criteria
code that you have
written
Click
Click
10) Click the start button to view the classifier output
Click
This is the result that you will see after several trials. You can click on an item in the Results list to review
previous results.
9
Notes: Sample code for classifiers (ARTMAP and State Vector Machines) and related files are available at
http://www.cns.bu.edu/~chhsiao/cn710_Chuan-Heng_Hsiao_code.zip
(See these example to use weka/gui/GenericPropertiesCreator.props to generate a sample classifier)
10
Download