Beispiel #1
0
        public static void Main(string[] args)
        {
            // Create a training set
            IList <IDatum <string, string> > trainingData = new List <IDatum <string, string> >();

            trainingData.Add(MakeStopLights(Green, Red));
            trainingData.Add(MakeStopLights(Green, Red));
            trainingData.Add(MakeStopLights(Green, Red));
            trainingData.Add(MakeStopLights(Red, Green));
            trainingData.Add(MakeStopLights(Red, Green));
            trainingData.Add(MakeStopLights(Red, Green));
            trainingData.Add(MakeStopLights(Red, Red));
            // Create a test set
            IDatum <string, string> workingLights = MakeStopLights(Green, Red);
            IDatum <string, string> brokenLights  = MakeStopLights(Red, Red);
            // Build a classifier factory
            LinearClassifierFactory <string, string> factory = new LinearClassifierFactory <string, string>();

            factory.UseConjugateGradientAscent();
            // Turn on per-iteration convergence updates
            factory.SetVerbose(true);
            //Small amount of smoothing
            factory.SetSigma(10.0);
            // Build a classifier
            LinearClassifier <string, string> classifier = factory.TrainClassifier(trainingData);

            // Check out the learned weights
            classifier.Dump();
            // Test the classifier
            System.Console.Out.WriteLine("Working instance got: " + classifier.ClassOf(workingLights));
            classifier.JustificationOf(workingLights);
            System.Console.Out.WriteLine("Broken instance got: " + classifier.ClassOf(brokenLights));
            classifier.JustificationOf(brokenLights);
        }
        public static void Main(string[] args)
        {
            Edu.Stanford.Nlp.Classify.RVFDataset <string, string> data = new Edu.Stanford.Nlp.Classify.RVFDataset <string, string>();
            ClassicCounter <string> c1 = new ClassicCounter <string>();

            c1.IncrementCount("fever", 3.5);
            c1.IncrementCount("cough", 1.1);
            c1.IncrementCount("congestion", 4.2);
            ClassicCounter <string> c2 = new ClassicCounter <string>();

            c2.IncrementCount("fever", 1.5);
            c2.IncrementCount("cough", 2.1);
            c2.IncrementCount("nausea", 3.2);
            ClassicCounter <string> c3 = new ClassicCounter <string>();

            c3.IncrementCount("cough", 2.5);
            c3.IncrementCount("congestion", 3.2);
            data.Add(new RVFDatum <string, string>(c1, "cold"));
            data.Add(new RVFDatum <string, string>(c2, "flu"));
            data.Add(new RVFDatum <string, string>(c3, "cold"));
            data.SummaryStatistics();
            LinearClassifierFactory <string, string> factory = new LinearClassifierFactory <string, string>();

            factory.UseQuasiNewton();
            LinearClassifier <string, string> c  = factory.TrainClassifier(data);
            ClassicCounter <string>           c4 = new ClassicCounter <string>();

            c4.IncrementCount("cough", 2.3);
            c4.IncrementCount("fever", 1.3);
            RVFDatum <string, string> datum = new RVFDatum <string, string>(c4);

            c.JustificationOf((IDatum <string, string>)datum);
        }
Beispiel #3
0
 protected internal virtual void JustificationOf(IDatum <string, string> testDatum, PrintWriter pw, string label)
 {
     classifier.JustificationOf(testDatum, pw);
 }