public static void Run_Classify() { List <CDataRecord> records = LoadSample(); DataTransformer <CDataRecord> dt = new DataTransformer <CDataRecord>(); dt.DoFeaturesScaling(records); KernelSVM <CDataRecord> algorithm = new KernelSVM <CDataRecord>(); algorithm.C = 20; ((GaussianKernel)algorithm.Kernel).Sigma = 0.01; algorithm.Train(records); Console.WriteLine("SVM(Gaussian Kernel) Model Built!"); for (int i = 0; i < records.Count; i++) { CDataRecord rec = records[i] as CDataRecord; Console.WriteLine("rec: "); for (int j = 0; j < rec.Dimension; ++j) { Console.WriteLine("X[" + j + "] = " + "[" + rec[j] + "] "); } Console.WriteLine("Label: " + "[" + rec.Label + "] "); Console.WriteLine("Predicted Label: " + algorithm.Predict(records[i])); } }
public static void Run_Rank() { List <CDataRecord> records = LoadSample(); DataTransformer <CDataRecord> dt = new DataTransformer <CDataRecord>(); dt.DoFeaturesScaling(records); KernelSVM <CDataRecord> algorithm = new KernelSVM <CDataRecord>(); algorithm.C = 20; //large value, high bias ((GaussianKernel)algorithm.Kernel).Sigma = 0.01; //low value, high bias algorithm.Train(records); Console.WriteLine("SVM (Gaussian Kernel) Model Built!"); for (int i = 0; i < records.Count; i++) { CDataRecord rec = records[i] as CDataRecord; Console.WriteLine("rec: "); for (int j = 0; j < rec.Dimension; ++j) { Console.WriteLine("X[" + j + " = " + rec[j] + "]"); } Console.WriteLine("Label: " + rec.Label); List <KeyValuePair <string, double> > ranks = algorithm.Rank(records, rec); for (int k = 0; k < ranks.Count; ++k) { Console.WriteLine("{0}: score = {1}", ranks[k].Key, ranks[k].Value); } } }
public static Glm FitModel(GlmSolverFactory solverFactory, List <RDataRecord> records) { DataTransformer dt = new DataTransformer(); dt.DoFeaturesScaling(records); Glm solver = solverFactory.CreateSolver(records); solver.Solve(); return(solver); }