void ApplyOnTest(IEnumerable<Image> test, Stopwatch sw, IOracle oracle, string resultFile) { Console.WriteLine("Begin predicting on TEST ... elapsed time (in s):" + sw.Elapsed.TotalSeconds); int nbTest = test.Count(); List<int> result = new List<int>(nbTest); int count = 0; foreach (Image t in test) { int predict = oracle.Predict(t); //t.ToImage(count.ToString() + ".bmp"); //Console.WriteLine(count.ToString() + " = predict => " + predict); result.Add(predict); count++; if (count % 1000 == 0) { Console.WriteLine("at count=" + count); Console.WriteLine("elapsed time (in s):" + sw.Elapsed.TotalSeconds); } } using (StreamWriter writer = new StreamWriter(resultFile)) { foreach (int res in result) writer.WriteLine(res); } Console.WriteLine("elapsed time (in s):" + sw.Elapsed.TotalSeconds); }
static void InfoAboutTrainingSet(List<Person> ps, IOracle oracle = null) { double nbSurvived = ps.Count( p => oracle == null ? p.Survived : oracle.Predict(p) ); double nbTotal = ps.Count(); double rate = nbSurvived / nbTotal; Console.WriteLine("NbSurvived:{0};NbTotal:{1};SurvivalRate:{2}", nbSurvived, nbTotal, rate); }
static void WriteToTestResult(IOracle forest) { List<Person> test = ImportFromCsv.GetDataSet(__dataFolder + "originalTest.csv", train: false); using (StreamReader reader = new StreamReader(__dataFolder + "originalTest.csv")) // Just to take the csv header ... using (StreamWriter writer = new StreamWriter(__dataFolder + "/result.csv")) { writer.Write("survived,"); writer.WriteLine(reader.ReadLine()); foreach (var p in test) { bool predict = forest.Predict(p); writer.Write(predict ? "1," : "0,"); writer.WriteLine(reader.ReadLine()); } } }
static double MesureModelOnValidation(List<Person> valid, IOracle oracle) { // Mesrue forest's Performance on Validation int nbErrorOnValidation = 0; foreach (var v in valid) { bool predict = oracle.Predict(v); if (predict != v.Survived) nbErrorOnValidation++; } double percent = (nbErrorOnValidation + 0.00) / valid.Count * 100; return percent; }
void ApplyOnValidation(IEnumerable<Image> validation, Stopwatch sw, IOracle oracle) { int nbTotal = 0; int nbCorrect = 0; Console.WriteLine("Begin predicting ...Elapsed time (in s):" + sw.Elapsed.TotalSeconds); Console.WriteLine(); foreach (Image v in validation) { nbTotal++; if (nbTotal % 50 == 0) { Console.WriteLine("at nbTotal=" + nbTotal + ". Elapsed time (in s):" + sw.Elapsed.TotalSeconds); } int predict = oracle.Predict(v); if (predict == v.Label) nbCorrect++; } Console.WriteLine("nbTotal:" + nbTotal); Console.WriteLine("nbCorrect:" + nbCorrect); Console.WriteLine("elapsed time (in s):" + sw.Elapsed.TotalSeconds); }
private double Score(IEnumerable<Image> valid, IOracle oracle) { double nbImage = 0; double correct = 0; foreach (Image image in valid) { nbImage++; int predict = oracle.Predict(image); if (predict == image.Label) { correct++; } } return correct / nbImage; }