public static ScreenData[] GetDataFromFile(string filepath) { string[] lines = File.ReadAllLines(filepath); ScreenData[] gData = new ScreenData[lines.Length]; //for (int i = 0; i < lines.Length; i++) //{ // string[] sVals = lines[i].Split(';'); // int[] iVals = { Convert.ToInt32(sVals[0]), Convert.ToInt32(sVals[1]), Convert.ToInt32(sVals[2]) }; // gData[i] = new ScreenData { Red = iVals[0], White = iVals[1], Kill = iVals[2] }; //} return(gData); }
private void Worker_LearnThresholds_DoWork(object sender, DoWorkEventArgs e) { LearningHelper learninghelper = new LearningHelper(); int samplescollected = 0; while (!Worker_LearnThresholds.CancellationPending) { while (GetKillNumber() == 0 && !Worker_LearnThresholds.CancellationPending) { ScreenData scrData = GetScreenData(); if (GetKillNumber() == 0) { scrData.Kill = false; learninghelper.AddData(scrData); samplescollected++; } } List <int> thisKill = new List <int>(); while (GetKillNumber() > 0 && !Worker_LearnThresholds.CancellationPending) { ScreenData scrData = GetScreenData(); if (GetKillNumber() > 0) { scrData.Kill = true; learninghelper.AddData(scrData); samplescollected++; } } } Worker_LearnThresholds.ReportProgress(0, String.Format("Collected a total of {0} samples", samplescollected)); Worker_LearnThresholds.ReportProgress(0, "Creating model from samples...."); double accuracy = learninghelper.LearnFromData(5000); Worker_LearnThresholds.ReportProgress(0, String.Format("Model created. Accuracy on 20% of testdata is {0}", accuracy)); learninghelper.SaveModel(@"./learning/KillDetectionModel.mdl"); }
public bool CheckForKill(ScreenData values) { model.Predict(values); return(values.Kill); }
public void AddData(ScreenData screendata) { data.Add(screendata); }