示例#1
0
文件: Form1.cs 项目: dftell/testML
        void TestML()
        {
            ExpectList el = new PK10ExpectReader().ReadNewestData(DateTime.Now.AddDays(-17));//至少180*16天+当天的记录数>1000
            //MessageBox.Show(el.LastData.OpenCode);
            var mapping    = new DaXiao_Mapping();
            var classifier = BayesPointMachineClassifier.CreateMulticlassClassifier(mapping);
            FeatureLabeItems trainingSet = new PKDataListSetFactory(el).OccurFeatureAndLabels();

            classifier.Train(trainingSet.FeatureVectors, trainingSet.Labels);
            List <Vector> testVector = new List <Vector>();//1
            Vector        v          = Vector.Zero(1);

            v[0] = 1;
            testVector.Add(v);
            var    predictions = classifier.PredictDistribution(testVector);
            string estimate    = classifier.Predict(0, testVector);

            MessageBox.Show(estimate);
        }
示例#2
0
文件: Form1.cs 项目: dftell/testML
        void TestSerial()
        {
            //ExpectList el = new PK10ExpectReader().ReadNewestData(DateTime.Now.AddDays(-17));//至少180*16天+当天的记录数>1000
            //ExpectList el = new PK10ExpectReader().ReadNewestData(725888,1200);//725888以前1200
            ExpectList el = new PK10ExpectReader().ReadHistory()
                            //MessageBox.Show(el.LastData.OpenCode);
                            var mapping = new Serial_Mapping();
            DataTable dtAll = new DataTable();
            Dictionary <int, string> ret  = new Dictionary <int, string>();
            PKDataListSetFactory     pksf = new PKDataListSetFactory(el);
            Dictionary <int, int>    res  = pksf.OccurProbList(1000, 1);

            MessageBox.Show(string.Join(";", res.Values.ToList()));
            ////////////////for (int i=0;i<10;i++)
            ////////////////{
            ////////////////    dtAll.Columns.Add(string.Format("key{0}", i), typeof(string));
            ////////////////    dtAll.Columns.Add(string.Format("val{0}", i), typeof(double));
            ////////////////}
            ////////////////for(int i=0;i<10;i++)
            ////////////////{
            ////////////////    dtAll.Rows.Add(dtAll.NewRow());
            ////////////////}
            ////////////////StringBuilder sb = new StringBuilder();//删除packages
            ////////////////for (int i = 0; i < 10; i++)
            ////////////////{

            ////////////////    var classifier = BayesPointMachineClassifier.CreateMulticlassClassifier(mapping);
            ////////////////    FeatureLabeItems trainingSet = pksf.OccurColumnFeatureAndLabels(i, 1000, 1);
            ////////////////    classifier.Train(trainingSet.FeatureVectors, trainingSet.Labels);
            ////////////////    List<Vector> testVector = new List<Vector>();//1
            ////////////////    Vector v = Vector.Zero(1);
            ////////////////    v[0] = int.Parse(el.LastData.ValueList[i]=="0"?"10":el.LastData.ValueList[i]);
            ////////////////    testVector.Add(v);
            ////////////////    var predictions = classifier.PredictDistribution(testVector);
            ////////////////    string estimate = classifier.Predict(0, testVector);
            ////////////////    sb.AppendLine(estimate);
            ////////////////    int row1 = 0;
            ////////////////    foreach(var vv in predictions)
            ////////////////    {
            ////////////////        foreach(string key in vv.Keys)
            ////////////////        {
            ////////////////            dtAll.Rows[row1][string.Format("key{0}", i)] = key;
            ////////////////            dtAll.Rows[row1][string.Format("val{0}", i)] = vv[key];
            ////////////////            row1++;
            ////////////////        }
            ////////////////    }
            ////////////////}
            ////////////////DataTable mydt = new DataTable();
            ////////////////for (int i = 0; i < 10; i++)
            ////////////////{
            ////////////////    mydt.Columns.Add(string.Format("key{0}", i), typeof(string));
            ////////////////    mydt.Columns.Add(string.Format("val{0}", i), typeof(double));
            ////////////////}
            ////////////////for (int i = 0; i < 101; i++)
            ////////////////{
            ////////////////    mydt.Rows.Add(mydt.NewRow());
            ////////////////}
            ////////////////for (int i = 0; i < 10; i++)
            ////////////////{
            ////////////////    Dictionary<string, double> mydata = pksf.OccurColumnProb(i, 1000, 1);
            ////////////////}
            ////////////////int row = 0;
            ////////////////double sum = 0;
            ////////////////foreach(string key in mydata.Keys)
            ////////////////{
            ////////////////    mydt.Rows[row][string.Format("key{0}", 0)] = key;
            ////////////////    mydt.Rows[row][string.Format("val{0}", 0)] = mydata[key];
            ////////////////    sum += mydata[key];
            ////////////////    row++;
            ////////////////}
            ////////////////DataView dv = new DataView(dtAll);
            ////////////////mydt.Rows[100][string.Format("key{0}", 0)] = "合计";
            ////////////////mydt.Rows[100][string.Format("val{0}", 0)] = sum;
            ////////////////this.dataGridView1.DataSource = mydt;
            ////////////////MessageBox.Show(BayesDicClass.getBAMaxValue(mydata, 5).ToString());
            //MessageBox.Show(sb.ToString());
        }