예제 #1
0
        public static void TrainSMO(Instances data)
        {
            //grab SMO, config
            weka.classifiers.functions.SMO smo = new SMO();
            smo.setOptions(weka.core.Utils.splitOptions(" -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));

            //train
            smo.buildClassifier(data);

            //test on self should get 100%
            weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(data);
            eval.evaluateModel(smo, data);
            Training_Output.printWekaResults(eval.toSummaryString("\nResults\n======\n", false));

            //save model serialize model
            weka.core.SerializationHelper.write(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG.model", smo);

            //load model deserialize model
            smo = (weka.classifiers.functions.SMO)weka.core.SerializationHelper.read(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG.model");

            //test loaded model
            eval = new weka.classifiers.Evaluation(data);
            eval.evaluateModel(smo, data);
            Training_Output.printWekaResults(eval.toSummaryString("\nResults\n======\n", false));
        }
예제 #2
0
        private static void WekaTrainingPipeline(Instances data)
        {
            //grab SMO, config
            TrainingTesting_SharedVariables.smo = new SMO();
            TrainingTesting_SharedVariables.smo.setOptions(weka.core.Utils.splitOptions(" -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
            GuiPreferences.Instance.setLog("SMO Assigned.");

            //train
            TrainingTesting_SharedVariables.smo.buildClassifier(data);
            GuiPreferences.Instance.setLog("Training on Data");

            //test on self should get 100%
            weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(data);
            eval.evaluateModel(TrainingTesting_SharedVariables.smo, data);
            Training_Output.printWekaResults(eval.toSummaryString("\nResults\n======\n", false));
            GuiPreferences.Instance.setLog("SMO Model Tested on Training Data, check that you get 100%.");

            //save model serialize model
            weka.core.SerializationHelper.write(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG.libsvm.arff.model", TrainingTesting_SharedVariables.smo);
            GuiPreferences.Instance.setLog("SMO Model Serialized and saved.");

            //load model deserialize model
            TrainingTesting_SharedVariables.smo = (weka.classifiers.functions.SMO)weka.core.SerializationHelper.read(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG.libsvm.arff.model");
            GuiPreferences.Instance.setLog("SMO Model DeSerialized and loaded.");

            //test loaded model
            eval = new weka.classifiers.Evaluation(data);
            eval.evaluateModel(TrainingTesting_SharedVariables.smo, data);
            Training_Output.printWekaResults(eval.toSummaryString("\nResults\n======\n", false));
            GuiPreferences.Instance.setLog("SMO Model Tested on data (sanity check for loaded model).");

            //display top IG on dicom view
            if (Preferences.Instance.attsel == null)
            {
                GuiPreferences.Instance.setLog("there are no ranked IG attributes or selected attr, continuing but please fix this possible bug.");
            }

            GuiPreferences.Instance.setLog("Dicom Viewer Displaying..");
            string dicomDir = GuiPreferences.Instance.WorkDirectory;

            dicomDir = dicomDir.Substring(0, dicomDir.Length - 4) + @"master\";
            string[] files     = System.IO.Directory.GetFiles(dicomDir, "*.dcm");
            string   firstFile = files[0].Substring(files[0].LastIndexOf(@"\") + 1);


            bool thresholdOrVoxelAmount;

            if (GuiPreferences.Instance.IgSelectionType == IGType.Threshold)
            {
                thresholdOrVoxelAmount = true;
            }
            else
            {
                thresholdOrVoxelAmount = false;
            }
            Form plotForm = new DicomImageViewer.MainForm(dicomDir + firstFile, firstFile,
                                                          Preferences.Instance.attsel.rankedAttributes(),
                                                          Convert.ToDouble(GuiPreferences.Instance.NudIGThreshold),
                                                          Convert.ToInt32(GuiPreferences.Instance.NudIGVoxelAmount),
                                                          thresholdOrVoxelAmount);// _trainTopIGFeatures);

            plotForm.StartPosition = FormStartPosition.CenterParent;
            plotForm.ShowDialog();
            plotForm.Close();
            GuiPreferences.Instance.setLog("Dicom Viewer Closed.");
        }