public async Task <Microsoft.ML.Data.MulticlassClassificationMetrics> Start(Action <TrainerOptions> action) { if (action == null) { throw new ArgumentNullException(); } var options = new TrainerOptions(); action.Invoke(options); Trainer.OnPreprocessorChanged = OnPreprocessorChanged; Trainer.OnPhaseChangedEvent = OnPhaseChangedEvent; var metrics = await Trainer.Start(op => { op.DataFileName = options.DataFileName; op.TestDataFileName = options.TestDataFileName; op.ProcessedDataFileName = options.ProcessedDataFileName; op.MLModelFileName = options.MLModelFileName; }); return(metrics); }
private static bool SelectTrainerOption(int trainerID) { while (true) { TrainerManager tm = new TrainerManager(); tm.ShowPersonalMessage(trainerID); Console.WriteLine(); Console.WriteLine("1. view my courses"); Console.WriteLine("2. view students per course"); Console.WriteLine("3. view assignments per student per course"); Console.WriteLine("4. mark assignments per student per course"); Console.WriteLine("9. Logout"); Console.WriteLine("0. Exit"); string input = Console.ReadLine(); Console.Clear(); bool goodInput = Int32.TryParse(input, out int choice); if (!goodInput) { continue; } if (choice == 0) { break; } TrainerOptions mainOption = (TrainerOptions)choice; switch (mainOption) { case TrainerOptions.viewCourses: TrainerPerCourseManager manager = new TrainerPerCourseManager(); manager.ReadTrainerCourses(trainerID); break; case TrainerOptions.viewStudentsPerCourse: StudentPerCourseManager manager2 = new StudentPerCourseManager(); manager2.Read(); break; case TrainerOptions.viewAssignmentsPerStudentPerCourse: AssignmentPerStudentManager manager3 = new AssignmentPerStudentManager(); manager3.ReadAssignmentsPerCoursePerStudent(); break; case TrainerOptions.markAssignmentsPerStudentPerCourse: AssignmentPerStudentManager manager4 = new AssignmentPerStudentManager(); manager4.MarkAssignmentsPerCoursePerStudent(); break; case TrainerOptions.logout: Console.WriteLine("logging out"); Console.ReadKey(); Console.Clear(); return(false); default: break; } } return(true); }
public async Task <Microsoft.ML.Data.MulticlassClassificationMetrics> Start(Action <TrainerOptions> action) { _ = action ?? throw new ArgumentNullException(); var options = new TrainerOptions(); action.Invoke(options); Microsoft.ML.Data.MulticlassClassificationMetrics metrics = null; try { HasStarted = true; DataPreprocessor.OnPreprocessorChanged = OnPreprocessorChanged ?? DataPreprocessor.OnPreprocessorChanged; DataPreprocessor.OnPreprocessorStop = OnPreprocessorStop ?? DataPreprocessor.OnPreprocessorStop; Trainer.OnStageChanged = (tracker) => { if (tracker.TrainingStage == TrainingStage.Evaluating) { OnPhaseChangedEvent?.Invoke(TrainerPhases.Testing); } }; OnPhaseChangedEvent?.Invoke(TrainerPhases.DataPreprocessing); await DataPreprocessor.Start(o => { o.DataFileName = options.DataFileName; o.PDataFileName = options.ProcessedDataFileName; }); OnPhaseChangedEvent?.Invoke(TrainerPhases.TestDataPreprocessing); await DataPreprocessor.Start(o => { o.DataFileName = options.TestDataFileName; o.PDataFileName = "Processed" + options.TestDataFileName; }); OnPhaseChangedEvent?.Invoke(TrainerPhases.Training); metrics = await Trainer.Start(o => { o.ProcessedDataFileName = options.ProcessedDataFileName; o.TestPDataFileName = "Processed" + options.TestDataFileName; o.MLModelFileName = options.MLModelFileName; }); await MetricsDataStorage.CreateMetricsFileAsync(options.MLModelFileName, metrics); OnPhaseChangedEvent?.Invoke(TrainerPhases.Completed); } catch (UnauthorizedAccessException ex) { throw new UnauthorizedAccessException("User may not have permission to access the required file"); } catch (System.IO.FileNotFoundException ex) { throw new System.IO.FileNotFoundException("File does not found"); } catch (Exception ex) { throw new Exception("Unexpected error occured"); } finally { HasStarted = false; } return(metrics); }