Cross-validating a machine learning model
In this recipe, we will be creating four methods that will be doing four different things--one method will load an ARFF file (assuming that the ARFF file is already created and saved somewhere); the second method will read the data in the ARFF file and generate a machine-learning model (we have arbitrarily chosen Naive Bayes model); the third method will be saving the model by using serialization, and the last method will be evaluating the model on the ARFF file using a 10-fold cross-validation.
How to do it...
- Create two instance variables. The first will contain all the instances of the iris dataset. The iris ARFF dataset can be found in the data folder of your installed Weka directory. The second variable will be a
NaiveBayes
classifier:Instances iris = null; NaiveBayes nb;
- Our first method will be loading the iris ARFF file using theÂ
DataSource
class, reading the content with theÂgetDataSet()
method of the class, and...