예제 #1
0
        private static void Main(string[] args)
        {
            var modelFilePath = GetModelFilePath(args.FirstOrDefault());

            var dataPath = Path.Combine(Environment.CurrentDirectory, "training-data.tsv");

            var trainer = new TrainerForBinaryClassification(dataPath);

            var metrics = trainer.Evaluate();

            var sb = new StringBuilder();

            sb.AppendLine("Model quality metrics evaluation");
            sb.AppendLine("--------------------------------");
            sb.AppendLine($"Accuracy: {metrics.Accuracy:P2}");
            sb.AppendLine($"Auc: {metrics.AreaUnderRocCurve:P2}");
            sb.AppendLine($"AUCPR: {metrics.AreaUnderPrecisionRecallCurve:P2}");
            sb.AppendLine($"F1Score: {metrics.F1Score:P2}");

            //  Ensure metrics are in a acceptable range
            if (metrics.F1Score < TrainerForBinaryClassification.Threshold)
            {
                throw new ApplicationException("F1Score is too low!");
            }

            //  Save model to disk
            if (trainer.SaveModel(modelFilePath))
            {
                SaveChangeLog(modelFilePath, sb.ToString());

                Console.WriteLine(sb);
                Console.WriteLine($"Data read from: {dataPath}");
                Console.WriteLine($"Model saved on: {modelFilePath}");
            }

#if DEBUG
            Console.ReadKey();
#endif
        }
예제 #2
0
        static void Main(string[] args)
        {
            var buildConfig = BuildConfig.GetCurrent();

            PrintConfigValues(buildConfig);

            var dataFilePath = GetDataFilePath(buildConfig);

            var trainer = new TrainerForBinaryClassification(dataFilePath);

            var metrics = trainer.Evaluate();

            //  Ensure metrics are in a acceptable range
            if (metrics.F1Score < TrainerForBinaryClassification.Threshold)
            {
                throw new ApplicationException("F1Score is too low!");
            }

            var modelOutputPath = buildConfig.GetModelFile().FullName;

            if (!trainer.SaveModel(modelOutputPath))
            {
                throw new ApplicationException($"ML Model cannot be saved to this position: {modelOutputPath}");
            }

            var printableMetrics = trainer.ToTextStats(metrics);

            Console.WriteLine(printableMetrics);

            Console.WriteLine($"Model written to disk, location: {modelOutputPath}");

            var changeLogPath = buildConfig.GetReleaseInfoMarkdown().FullName;

            File.WriteAllText(changeLogPath, trainer.ToMarkDownStats(metrics));

            Console.WriteLine($"Markdown changeLog written to disk, location: {changeLogPath}");
        }