public void Should_be_able_to_read_valid_dataset() { // Dataset extracted from first five rows of mpg.ds file. var dataset = new List <List <double> > { new List <double> { 18, 8, 307.0, 130.0, 3504.0, 12.0, 70, 1 }, new List <double> { 15, 8, 350.0, 165.0, 3693.0, 11.5, 70, 1 }, new List <double> { 18, 8, 318.0, 150.0, 3436.0, 11.0, 70, 1 }, new List <double> { 16, 8, 304.0, 150.0, 3433.0, 12.0, 70, 1 }, new List <double> { 17, 8, 302.0, 140.0, 3449.0, 10.5, 70, 1 } }; svm_problem prob = ProblemHelper.ReadAndScaleProblem(dataset); // Data count int dataCount = dataset.Count(); Assert.AreEqual(prob.l, dataCount, 0.01); Assert.AreEqual(prob.x.Count(), dataCount, 0.01); Assert.AreEqual(prob.y.Count(), dataCount, 0.01); // Scale Assert.AreEqual(prob.x.Max(v => v.Max(n => n.value)), 1.0, 0.1); Assert.AreEqual(prob.x.Min(v => v.Max(n => n.value)), 0.0, 0.1); }
static void Main(string[] args) { var path = Environment.CurrentDirectory; string DvCPath = System.IO.Path.Combine(path, DvC_TEST_FILE); string DvHPath = System.IO.Path.Combine(path, DvH_TEST_FILE); string HvCPath = System.IO.Path.Combine(path, HvC_TEST_FILE); DvC_prob = ProblemHelper.ReadAndScaleProblem(DvCPath); DvH_prob = ProblemHelper.ReadAndScaleProblem(DvHPath); HvC_prob = ProblemHelper.ReadAndScaleProblem(HvCPath); var DvCsvm = new C_SVC(DvC_prob, KernelHelper.RadialBasisFunctionKernel(gamma), C); var DvHsvm = new C_SVC(DvH_prob, KernelHelper.RadialBasisFunctionKernel(gamma), C); var HvCsvm = new C_SVC(HvC_prob, KernelHelper.RadialBasisFunctionKernel(gamma), C); var DvCcva = DvCsvm.GetCrossValidationAccuracy(5); var DvHcva = DvHsvm.GetCrossValidationAccuracy(2); var HvCcva = HvCsvm.GetCrossValidationAccuracy(5); DvCsvm.Export(System.IO.Path.Combine(path, DvC_MODEL_FILE)); DvHsvm.Export(System.IO.Path.Combine(path, DvH_MODEL_FILE)); HvCsvm.Export(System.IO.Path.Combine(path, HvC_MODEL_FILE)); Console.WriteLine(String.Format("--------------------------")); Console.WriteLine(String.Format("DvC Result: {0}%", (Math.Round(DvCcva * 100, 2)).ToString())); Console.WriteLine(String.Format("DvH Result: {0}%", (Math.Round(DvHcva * 100, 2)).ToString())); Console.WriteLine(String.Format("HvC Result: {0}%", (Math.Round(HvCcva * 100, 2)).ToString())); Console.WriteLine(String.Format("--------------------------")); Console.ReadKey(); }
private void buttonSVM_Click(object sender, EventArgs e) { List <double> values = new List <double>(); foreach (var column in checkedListBoxVariableRellenar.SelectedItems) { for (int i = 0; i < dt.Rows.Count; i++) { values.Add(double.Parse(dt.Rows[i][column.ToString()].ToString())); } var dataTraining = ProblemHelper.ReadAndScaleProblem(new List <List <double> >() { values }); var svm = new Epsilon_SVR(DataProblem, KernelHelper.RadialBasisFunctionKernel(Gamma), C, Elipson); double mse = svm.GetMeanSquaredError(); var prediction = svm.Predict(dataTraining.x[0]); } // 1. primero se debe armar una subtabla con los atributos que se van a utilizar. // que serian los que estan en el checkbox. // 2. elegir la columna sobre la que se quiere rellenar valores // 3. se quitan los registros que contengan datos faltantes de las variables predictoras, para este caso son los que tengan valor de -200 // 4. Aplicar el algoritmo de VSM // 5. Generar Vista con valores resultado // 6. Generar resumen de resultados: en tal fila, cambie tal por tal. }
public void TestInitialize() { var path = Environment.CurrentDirectory; var pos = path.IndexOf("libsvm.net"); var basePath = path.Substring(0, pos + 10); training_prob = ProblemHelper.ReadAndScaleProblem(System.IO.Path.Combine(basePath, TRAINING_FILE)); test_prob = ProblemHelper.ReadAndScaleProblem(System.IO.Path.Combine(basePath, TEST_FILE)); }
/// <summary> ///Test pour ReadAndScaleProblem ///</summary> //[TestMethod()] public void ReadAndScaleProblemTest() { string full_path = System.IO.Path.Combine(base_path, TEST_FILE); var prob = ProblemHelper.ReadAndScaleProblem(full_path); Assert.IsNotNull(prob); Assert.IsTrue(prob.x.Max(v => v.Max(n => n.value)) == 1.0); Assert.IsTrue(prob.x.Min(v => v.Min(n => n.value)) == -1.0); }
public static void LibSVM(List <string> inputData, List <string> testData) { var inputFilePath = @"D:\新西兰学习生活\大学上课\乐谱数据\input.txt"; var testFilePath = @"D:\新西兰学习生活\大学上课\乐谱数据\test.txt"; PrepareDataLibSvm(inputData, inputFilePath); PrepareDataLibSvm(testData, testFilePath); var _prob = ProblemHelper.ReadAndScaleProblem(inputFilePath); var svm = new C_SVC(_prob, KernelHelper.RadialBasisFunctionKernel(gamma), C); }
public void TestInitialize() { var path = Environment.CurrentDirectory; var pos = path.IndexOf("libsvm.net"); var basePath = path.Substring(0, pos + 10); string fullPath = System.IO.Path.Combine(basePath, LEU_TEST_FILE); // get data from file // Note that you should always scale your data _prob = ProblemHelper.ReadAndScaleProblem(fullPath); }
public bool buildSVMCorpus(string filename) { string trainDataPath = filename + "SimpleScaledTrainSVM.txt"; if (File.Exists(trainDataPath)) { _prob = ProblemHelper.ReadAndScaleProblem(trainDataPath); svm = new C_SVC(_prob, KernelHelper.LinearKernel(), C); fileExistance = true; var reader = new StreamReader(File.OpenRead(filename + "MinMax.txt")); string[] minMax = reader.ReadLine().Split(','); scale.min = Convert.ToDouble(minMax[0]); scale.max = Convert.ToDouble(minMax[1]); } return(fileExistance); }
public void Should_be_able_to_detect_invalid_feature_count_in_dataset() { var dataset = new List <List <double> > { new List <double> { 18, 8, 307.0, 130.0, 3504.0, 12.0, 70, 1 }, new List <double> { 15, 8, 350.0, 165.0, 3693.0, 11.5, 70, 1 }, new List <double> { 18, 8, 318.0, 150.0, 11.0, 70, 1 }, // miss the 4th feature column. new List <double> { 16, 8, 304.0, 150.0, 3433.0, 12.0, 70, 1 }, new List <double> { 17, 8, 302.0, 140.0, 3449.0, 10.5, 70, 1 } }; ProblemHelper.ReadAndScaleProblem(dataset); }
public void Should_be_able_to_detect_void_dataset() { ProblemHelper.ReadAndScaleProblem(new List <List <double> >()); }
public void Should_be_able_to_detect_null_dataset() { ProblemHelper.ReadAndScaleProblem((List <List <double> >)null); }