public void TestLibsvmClassify()
        {
            var advancedClassify = new AdvancedClassify();
            var numericalset     = advancedClassify.LoadNumerical();
            var result           = advancedClassify.ScaleData(numericalset);
            var scaledSet        = result.Item1;
            var scalef           = result.Item2;
            var prob             = new SVMProblem();

            foreach (var matchRow in scaledSet)
            {
                prob.Add(matchRow.NumData.Select((v, i) => new SVMNode(i + 1, v)).ToArray(), matchRow.Match);
            }
            var param = new SVMParameter()
            {
                Kernel = SVMKernelType.RBF
            };
            var m = prob.Train(param);

            m.SaveModel("trainModel");
            Func <double[], SVMNode[]> makeInput = ma => scalef(ma).Select((v, i) => new SVMNode(i + 1, v)).ToArray();
            var newrow = new[] { 28, -1, -1, 26, -1, 1, 2, 0.8 };//男士不想要小孩,而女士想要

            TestOutput(m.Predict(makeInput(newrow)));
            newrow = new[] { 28, -1, 1, 26, -1, 1, 2, 0.8 };//双方都想要小孩
            TestOutput(m.Predict(makeInput(newrow)));
        }
        public void TestLoadNumerical()
        {
            var advancedClassify = new AdvancedClassify();
            var numericalset     = advancedClassify.LoadNumerical();
            var dataRow          = numericalset[0].Data;

            _output.WriteLine(JsonConvert.SerializeObject(dataRow));
        }
        public void TestScaledLinearTrain()
        {
            var advancedClassify = new AdvancedClassify();
            var numericalset     = advancedClassify.LoadNumerical();
            var result           = advancedClassify.ScaleData(numericalset);
            var scaledSet        = result.Item1;
            var scalef           = result.Item2;
            var avgs             = advancedClassify.LinearTrain(scaledSet);

            _output.WriteLine(JsonConvert.SerializeObject(numericalset[0].NumData));
            _output.WriteLine(numericalset[0].Match.ToString());
            _output.WriteLine(advancedClassify.DpClassify(scalef(numericalset[0].NumData), avgs).ToString());
            _output.WriteLine(numericalset[11].Match.ToString());
            _output.WriteLine(advancedClassify.DpClassify(scalef(numericalset[11].NumData), avgs).ToString());
        }
        public void TestNlClassifyMore()
        {
            var advancedClassify = new AdvancedClassify();
            var numericalset     = advancedClassify.LoadNumerical();
            var result           = advancedClassify.ScaleData(numericalset);
            var scaledSet        = result.Item1;
            var scalef           = result.Item2;
            var ssoffset         = advancedClassify.GetOffset(scaledSet);

            TestOutput(numericalset[0].Match);
            TestOutput(advancedClassify.NlClassify(scalef(numericalset[0].NumData), scaledSet, ssoffset));
            TestOutput(numericalset[1].Match);
            TestOutput(advancedClassify.NlClassify(scalef(numericalset[1].NumData), scaledSet, ssoffset));
            TestOutput(numericalset[2].Match);
            TestOutput(advancedClassify.NlClassify(scalef(numericalset[2].NumData), scaledSet, ssoffset));
            var newrow = new[] { 28, -1, -1, 26, -1, 1, 2, 0.8 };//男士不想要小孩,而女士想要

            TestOutput(advancedClassify.NlClassify(scalef(newrow), scaledSet, ssoffset));
            newrow = new[] { 28, -1, 1, 26, -1, 1, 2, 0.8 };//双方都想要小孩
            TestOutput(advancedClassify.NlClassify(scalef(newrow), scaledSet, ssoffset));
        }