static void Main(string[] args) { //create Students (objects) Student s1 = new Student("Nick", 19); Student s2 = new Student("Bella", 18); Student s3 = new Student("Victor", 21); Student s4 = new Student("Susie", 20); s1.Level = "Sophomore"; s3.Level = "Graduate"; s2.Major = "English"; s4.Major = "History"; //create filestream to save the info from ToString() into the file.txt FileStream f = new FileStream("file.text", FileMode.OpenOrCreate, FileAccess.ReadWrite); // streamWriter is used to write into the file.txt StreamWriter s = new StreamWriter(f); //create an array of students (or list)- to applay methods to each of them Student[] stud_array = new Student[] { s1, s2, s3, s4 }; //use foreach foreach (var Stud in stud_array) { //Prints out info as a list / from array Console.WriteLine(Stud.DisplayInformation()); Console.WriteLine(""); Console.WriteLine("---------------------------------------------------------------------------------------------------------------------"); //saves info in the file.txt Stud.ToString(); //method to write into streamWriter object (s) - after that the file.txt is created with saved info: s.WriteLine(Stud.ToString()); } // always close the objects: streamwriter and filestream - after being done with them s.Close(); f.Close(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
public string CreateGraph(Stud dataA, Stud dataB, bool kmeans, bool dbscan, bool linearregression, bool polynomialregression, bool pearsoncorrelation, bool spearmancorrelation, bool knearest, bool naivebayes) { var gradedStudents = Students.StudentsGraded; var classifyungraded = knearest || naivebayes; if (classifyungraded) { var grades = new Dictionary <int, double>(); var clusters = new Dbscan(210, 3, Students.StudentsGraded.Select(x => x.ToGenericVector(Stud.Attempts, Stud.Class, Stud.FailRatio, Stud.Fails, Stud.Succeeds, Stud.SuccessRatio, Stud.Grade))); foreach (var cluster in clusters.DataClusters) { grades[cluster.Key] = cluster.Value.Sum(x => x[6]) / cluster.Value.Count(); } Classification classification = new NaiveBayesClassification(clusters.DataClusters, 50000); if (knearest) { classification = new KnearestClassification(clusters.DataClusters, 5); } foreach (var student in Students.StudentsUngraded) { var cluster = classification.ClassifyPoint(student.ToGenericVector(Stud.Attempts, Stud.Class, Stud.FailRatio, Stud.Fails, Stud.Succeeds, Stud.SuccessRatio, Stud.Grade)); student.Grade = (int)grades[cluster]; gradedStudents.Add(student); } } var list = new List <int>(); var a = list .GroupBy(x => x) .Select(x => x.OrderBy(y => y)) .Select(x => x.First()); foreach (var student in gradedStudents) { student.Filter(); } var data = new Dataset(gradedStudents.Select(x => x.ToGenericVector(dataA, dataB))); var highChart = new HighchartsAdapter(Highchart.Scatterplot); //Dbscan removes outliers, so we have to change are dataset afterwards if (dbscan) { var newData = new List <GenericVector>(); var dBscan = new Dbscan(50, 3, data); foreach (var cluster in dBscan.DataClusters) { newData.AddRange(cluster.Value); } data = new Dataset(newData); highChart.AddClusters(dBscan); } if (kmeans) { highChart.AddClusters(new Kmeans(4, 100, data)); } if (linearregression) { highChart.AddRegression(new LinearRegression(data.Select(x => x.ToVector2()))); } if (polynomialregression) { highChart.AddRegression(new PolynomialRegression(data.Select(x => x.ToVector2()), 3)); } if (pearsoncorrelation) { highChart.AddCorrelation(new PearsonCorrelation(data.Select(x => x.ToVector2()))); } if (spearmancorrelation) { highChart.AddCorrelation(new SpearmanCorrelation(data.Select(x => x.ToVector2()))); } highChart.SetDivId("plotkmeans"); highChart.SetTitle($"{dataA} vs {dataB}"); highChart.SetXlabel(dataA.ToString()); highChart.SetYlabel(dataB.ToString()); return(highChart.CreateTemplate()); }