Exemple #1
0
        public static Dictionary <int, double> getLabels(List <Instance> TrainList, List <Instance> TestList)
        {
            Dictionary <int, double> ret = new Dictionary <int, double>();
            List <int> testLabels        = new List <int>();

            for (int i = 0; i < 10; i++)
            {
                testLabels.Add((i + 1) % 10);
            }
            List <Instance> instances = TrainList;// DataSet.readDataSet("examples/zoo.train");
            MaxEnt          me        = new MaxEnt(instances);

            me.Train();
            for (int i = 0; i < testLabels.Count; i++)
            {
                TestList[TestList.Count - 1].Label = testLabels[i]; //最后一条记录的label更换为测试的label
                List <Instance> trainInstances = TestList;          // DataSet.readDataSet("examples/zoo.test");
                int             pass           = 0;
                foreach (Instance instance in trainInstances)
                {
                    int predict = me.Classify(instance);
                    if (predict == instance.Label)
                    {
                        pass += 1;
                    }
                }
                ret.Add(testLabels[i], (double)1.0 * pass / trainInstances.Count);
            }
            return(ret);
            //System.out.println("accuracy: " + 1.0 * pass / trainInstances.size());
        }
Exemple #2
0
        public static double Run(List <Instance> TrainList, List <Instance> TestList)
        {
            List <Instance> instances = TrainList;// DataSet.readDataSet("examples/zoo.train");
            MaxEnt          me        = new MaxEnt(instances);

            me.Train();
            List <Instance> trainInstances = TestList;// DataSet.readDataSet("examples/zoo.test");
            int             pass           = 0;

            foreach (Instance instance in trainInstances)
            {
                int predict = me.Classify(instance);
                if (predict == instance.Label)
                {
                    pass += 1;
                }
            }
            return((double)1.0 * pass / trainInstances.Count);
            //System.out.println("accuracy: " + 1.0 * pass / trainInstances.size());
        }