/// <summary> /// Load data from CSV. /// </summary> /// <param name="csvFilePath">CSV file path.</param> /// <param name="hasHeader">CSV has headers.</param> public virtual void LoadDataFromCsv(string csvFilePath, bool hasHeader = false) { if (initialized == false) { throw new Exception("ML Model has not been initialized yet."); } lock (mlModelCompilation) { hasHeaders = hasHeader; IEnumerable <string> csvLines = File.ReadAllLines(csvFilePath); if (hasHeader) { csvLines = csvLines.Skip(1); } foreach (string line in csvLines) { IList <double> dict = new List <double>(); string[] vals = line.Replace(" ", "").Split(","); for (int i = 0; i < vals.Length - 1; i++) { dict.Add(Convert.ToDouble(vals[i])); } Validity.Add(Convert.ToBoolean(vals[vals.Length - 1])); Data.Add(dict.ToArray()); } // Create random variable w with VectorGuassian (of size 3) // Features => (Gold | Nickel | Copper) Concentration, IsGoodMaterial? w = Variable.Random(new VectorGaussian(Vector.Zero(FeatureCount), PositiveDefiniteMatrix.Identity(FeatureCount))).Named("w"); // Create Observable variable based on valid_ui; y = Variable.Observed(Validity.ToArray()); BayesPointMachine.Run(this, y, w); } }