Hi
Error message is as follows:-
weka.core.UnsupportedTypeException: weka.classifiers.bayes.NaiveBayes: Cannot handle date attributes
*************************************
I am connecting weka to Apache derby database - all OK
weka splits the no. of instances into training and testing - all OK
I am running a loop of 7 classifiers and NaiveBayes is Number 4.............
Each instance record is made up as follows........................
First two fields are Date and Time - used as primary key - but they are not attributes as such
Fields 3 thru 11 are 9 attributes
Fields 12 and 13 are the predictive attributes:- 12 decimal and 13 varchar
As I filter out attribute No. 1 which is the only date in each record, I am confused as to why the error message talks about 'date'
Any suggestions?
Bob M
******************************************************
// create an array of weka filters - select attributes to be unused
int[][] filtersArray = new int[][] {
{ 1, 3, 5, 6, 8, 10}, // KStar
{ 1, 3, 5, 6, 8, 10}, // J48
{ 1, 3, 5, 6, 7, 8, 10}, // JRip
{ 1, 3, 6, 7, 8, 9, 10}, // NaiveBayes
{ 1, 2, 3, 5, 6, 8, 10}, // LMT
{ 1, 3, 5, 6, 8, 11}, // KStar
{ 2, 4, 7, 9, 11} // LibSVM
};
// create strings of weka options
String[][] optionsArray = new String[][] {
weka.core.Utils.splitOptions("-B 35 -M a"), // KStar
weka.core.Utils.splitOptions("-C 0.25 -M 2"), // J48
weka.core.Utils.splitOptions("--F 3 -N 2.0 -0 2 -S 1 -E"), // JRip
weka.core.Utils.splitOptions(""), // NaiveBayes
weka.core.Utils.splitOptions("-I -1 -M 15 -W 0.0 -A"), // LMT
weka.core.Utils.splitOptions("-B 35 -M a"), // KStar
weka.core.Utils.splitOptions("M 2 -C 0.25 -Q 1") // LibSVM
};
//************************************************************************
private class WekaApp {
public BufferedReader readDataFile(String filename) {
BufferedReader inputReader = null;
return inputReader;
}
void doInit() throws Exception {
BufferedReader datafile = readDataFile("C:/Databases/us_copiosus");
InstanceQuery query = new InstanceQuery();
query.setQuery("SELECT * from USD_JPY");
Instances data = query.retrieveInstances();
data.setClassIndex(data.numAttributes() - 1);
// Split instances into training and testing (the split percentage is 97.56%)
double percent = 97.56;
int trainingSize = (int) Math.round(data.numInstances() * percent / 100);
int testingSize = data.numInstances() - trainingSize;
Instances training = new Instances(data, 0, trainingSize);
Instances testing = new Instances(data, trainingSize, testingSize);
// Choose a set of classifiers
Classifier[] models = new Classifier[] {
new KStar(),
new J48(),
new JRip(),
new NaiveBayes(),
new LMT(),
new KStar(),
new LibSVM() };
// Run for each classifier model
for(int j = 0; j < models.length; j++) {
Remove filter = new Remove(); // First, we create the base object.
filter.setAttributeIndicesArray(filtersArray[j]); // Finally, we provide an array of integer indexes.
//build classifier
FilteredClassifier fc = new FilteredClassifier(); // Create a FilteredClassifier object
((OptionHandler)models[j]).setOptions(optionsArray[j]);
fc.setClassifier(models[j]);
fc.setFilter(filter);
fc.buildClassifier(training);
// test the model
Evaluation eval = new Evaluation(training);
eval.evaluateModel(fc, testing);
// print the results a la weka Explorer:
String strSummary = eval.toSummaryString();
myConsole.getOut().println("results: "+ strSummary);
// get the confusion matrix
double[][] cmMatrix = eval.confusionMatrix();
for(int row_i=0;row_i<cmMatrix.length; row_i++){
for(int col_i=0;col_i<cmMatrix.length;col_i++){
myConsole.getOut().println(cmMatrix[row_i][col_i]);
myConsole.getOut().println("|");
}
myConsole.getOut().println();
}
//retrieve the last instance in the testing set
Instance lastInstance = testing.instance(testing.numInstances() - 1);
myConsole.getOut().println("lastInstance: "+ lastInstance);
// classifyInstance() just returns the index of the predicted label (the one with the highest probability) as a double
double pred = fc.classifyInstance(lastInstance);
myConsole.getOut().println("pred: "+ pred);
// add the prediction of the final testing instance to trend
// note prediction is class for classifiers 1 thru 5, and return for 6 & 7
if (pred >= 1) {
prediction = 1;
} else {
prediction = -1;
}
Predicted_Trend = Predicted_Trend + prediction;
myConsole.getOut().println("prediction: "+ prediction);
myConsole.getOut().println("Prediction_Trend: "+ Predicted_Trend);
}
}
}
}
************************************************
Error message is as follows:-
weka.core.UnsupportedTypeException: weka.classifiers.bayes.NaiveBayes: Cannot handle date attributes
*************************************
I am connecting weka to Apache derby database - all OK
weka splits the no. of instances into training and testing - all OK
I am running a loop of 7 classifiers and NaiveBayes is Number 4.............
Each instance record is made up as follows........................
First two fields are Date and Time - used as primary key - but they are not attributes as such
Fields 3 thru 11 are 9 attributes
Fields 12 and 13 are the predictive attributes:- 12 decimal and 13 varchar
As I filter out attribute No. 1 which is the only date in each record, I am confused as to why the error message talks about 'date'
Any suggestions?
Bob M
******************************************************
// create an array of weka filters - select attributes to be unused
int[][] filtersArray = new int[][] {
{ 1, 3, 5, 6, 8, 10}, // KStar
{ 1, 3, 5, 6, 8, 10}, // J48
{ 1, 3, 5, 6, 7, 8, 10}, // JRip
{ 1, 3, 6, 7, 8, 9, 10}, // NaiveBayes
{ 1, 2, 3, 5, 6, 8, 10}, // LMT
{ 1, 3, 5, 6, 8, 11}, // KStar
{ 2, 4, 7, 9, 11} // LibSVM
};
// create strings of weka options
String[][] optionsArray = new String[][] {
weka.core.Utils.splitOptions("-B 35 -M a"), // KStar
weka.core.Utils.splitOptions("-C 0.25 -M 2"), // J48
weka.core.Utils.splitOptions("--F 3 -N 2.0 -0 2 -S 1 -E"), // JRip
weka.core.Utils.splitOptions(""), // NaiveBayes
weka.core.Utils.splitOptions("-I -1 -M 15 -W 0.0 -A"), // LMT
weka.core.Utils.splitOptions("-B 35 -M a"), // KStar
weka.core.Utils.splitOptions("M 2 -C 0.25 -Q 1") // LibSVM
};
//************************************************************************
private class WekaApp {
public BufferedReader readDataFile(String filename) {
BufferedReader inputReader = null;
return inputReader;
}
void doInit() throws Exception {
BufferedReader datafile = readDataFile("C:/Databases/us_copiosus");
InstanceQuery query = new InstanceQuery();
query.setQuery("SELECT * from USD_JPY");
Instances data = query.retrieveInstances();
data.setClassIndex(data.numAttributes() - 1);
// Split instances into training and testing (the split percentage is 97.56%)
double percent = 97.56;
int trainingSize = (int) Math.round(data.numInstances() * percent / 100);
int testingSize = data.numInstances() - trainingSize;
Instances training = new Instances(data, 0, trainingSize);
Instances testing = new Instances(data, trainingSize, testingSize);
// Choose a set of classifiers
Classifier[] models = new Classifier[] {
new KStar(),
new J48(),
new JRip(),
new NaiveBayes(),
new LMT(),
new KStar(),
new LibSVM() };
// Run for each classifier model
for(int j = 0; j < models.length; j++) {
Remove filter = new Remove(); // First, we create the base object.
filter.setAttributeIndicesArray(filtersArray[j]); // Finally, we provide an array of integer indexes.
//build classifier
FilteredClassifier fc = new FilteredClassifier(); // Create a FilteredClassifier object
((OptionHandler)models[j]).setOptions(optionsArray[j]);
fc.setClassifier(models[j]);
fc.setFilter(filter);
fc.buildClassifier(training);
// test the model
Evaluation eval = new Evaluation(training);
eval.evaluateModel(fc, testing);
// print the results a la weka Explorer:
String strSummary = eval.toSummaryString();
myConsole.getOut().println("results: "+ strSummary);
// get the confusion matrix
double[][] cmMatrix = eval.confusionMatrix();
for(int row_i=0;row_i<cmMatrix.length; row_i++){
for(int col_i=0;col_i<cmMatrix.length;col_i++){
myConsole.getOut().println(cmMatrix[row_i][col_i]);
myConsole.getOut().println("|");
}
myConsole.getOut().println();
}
//retrieve the last instance in the testing set
Instance lastInstance = testing.instance(testing.numInstances() - 1);
myConsole.getOut().println("lastInstance: "+ lastInstance);
// classifyInstance() just returns the index of the predicted label (the one with the highest probability) as a double
double pred = fc.classifyInstance(lastInstance);
myConsole.getOut().println("pred: "+ pred);
// add the prediction of the final testing instance to trend
// note prediction is class for classifiers 1 thru 5, and return for 6 & 7
if (pred >= 1) {
prediction = 1;
} else {
prediction = -1;
}
Predicted_Trend = Predicted_Trend + prediction;
myConsole.getOut().println("prediction: "+ prediction);
myConsole.getOut().println("Prediction_Trend: "+ Predicted_Trend);
}
}
}
}
************************************************