public void Dataset_GetInstance_WithLabelsAndKeys() { // Arrange string filename = @"Dataset\Iris.csv"; IReader reader = new CSVReader(filename); SOM som = new SOM(); som.GetData(reader); Dataset dataset = som.Dataset; dataset.SetKey("Id"); dataset.SetLabel("Species"); // Act double[] result = dataset.GetInstance <double>(0); // Assert int expectedCount = 4; double x1 = 5.1; double x2 = 3.5; double x3 = 1.4; double x4 = 0.2; Assert.AreEqual(expectedCount, result.Length); Assert.AreEqual(x1, result[0]); Assert.AreEqual(x2, result[1]); Assert.AreEqual(x3, result[2]); Assert.AreEqual(x4, result[3]); }
// GET: SOM public ActionResult Index() { string filepath = Server.MapPath("~/Dataset/epileptic_dataset.csv"); _reader = new CSVReader(filepath); _model.GetData(_reader); _model.Dataset.SetLabel("Patient"); _model.Dataset.SetLabel("y"); _model.FeatureLabel = "y"; _model.InitializeMap(); _model.Train(); _model.LabelNodes(); return(View(_model)); }
public void SOM_IgnoreColumns_GetIsLabelColumn_WhenIsLabelTrue() { // Arrange string filename = @"Dataset\Iris.csv"; IReader reader = new CSVReader(filename); SOM som = new SOM(); som.GetData(reader); // Act Dataset dataset = som.Dataset; dataset.SetLabel("Species"); List <int> ignoreColumns = dataset.GetIgnoreColumns(); // Assert string expected = "Species"; string result = dataset.Features[ignoreColumns[0]].FeatureName; Assert.AreEqual(expected, result); }
public static void Program1(string[] args) { Stopwatch stopwatch = new Stopwatch(); string filepath = @"C:\Users\Vilson\Desktop\Datasets\Financial Distress\FD_Training.csv"; SOM _model = new SOM(10, 10, 0.3, 20); _model.Training += _model_Training; IReader _reader = new CSVReader(filepath); IClusterer _kmeans = new KMeansClustering(); _model.GetData(_reader); _model.Dataset.SetLabel("Company"); _model.Dataset.SetLabel("Time"); _model.Dataset.SetLabel("Financial Distress"); _model.Dataset.SetLabel("Status"); _model.FeatureLabel = "Status"; Console.WriteLine("Start initializing map..."); stopwatch.Start(); _model.InitializeMap(); stopwatch.Stop(); Console.WriteLine("Completed initialization..."); Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed); Console.WriteLine("Start training model..."); stopwatch.Restart(); _model.Train(); stopwatch.Stop(); Console.WriteLine("Completed training model..."); Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed); Console.WriteLine("Start labelling node..."); stopwatch.Restart(); _model.LabelNodes(); stopwatch.Stop(); Console.WriteLine("Completed labelling node..."); Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed); Console.WriteLine("Start clustering nodes..."); stopwatch.Restart(); var flattenedMap = ArrayHelper <Node> .FlattenMap(_model.Map); var clusteredNodes = _kmeans.Cluster(flattenedMap, 3); stopwatch.Stop(); Console.WriteLine("Completed clustering nodes..."); Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed); string trainingPath = @"C:\Users\Vilson\Desktop\Datasets\Financial Distress\Training"; List <TrajectoryMapper> dbTrajectories = new List <TrajectoryMapper>(); Console.WriteLine("Start plotting trajectories..."); stopwatch.Restart(); foreach (var file in Directory.EnumerateFiles(trainingPath)) { TrajectoryMapper trajectoryMapper = new TrajectoryMapper(_model); IReader trajectoryReader = new CSVReader(file); trajectoryMapper.GetData(trajectoryReader); trajectoryMapper.GetTrajectories(); dbTrajectories.Add(trajectoryMapper); } stopwatch.Stop(); Console.WriteLine("Completed plotting trajectories..."); Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed); string testingPath = @"C:\Users\Vilson\Desktop\Datasets\Financial Distress\Test\fd_297.csv"; TrajectoryMapper testMapper = new TrajectoryMapper(_model); IReader trjaectoryDataReader = new CSVReader(testingPath); testMapper.GetData(trjaectoryDataReader); var unknownTrajectory = testMapper.GetTrajectories(); IFileHelper fileHelper = new FileHelper(); ISimilarityMeasure similarityMeasure = new CompressionDissimilarityMeasure(fileHelper); foreach (var trajectory in dbTrajectories) { var currentTrajectory = trajectory.GetTrajectories(); var score = similarityMeasure.MeasureSimilarity(currentTrajectory, unknownTrajectory); Console.WriteLine("{0}: {1}", trajectory.FileName, score); } Console.ReadLine(); }