public void PredictTrueTest() { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string _trainDataPath = getPath + "\\GoDiet\\DietData\\DataModel\\trainData\\weight_lr_train1.csv"; MLContext mlContext = new MLContext(seed: 0); TextLoader _textLoader = mlContext.Data.CreateTextReader(new TextLoader.Arguments() { Separator = ",", HasHeader = true, Column = new[] { new TextLoader.Column("Label", DataKind.Bool, 1), new TextLoader.Column("BMI", DataKind.Text, 0) } }); IDataView dataView = _textLoader.Read(_trainDataPath); var pipeline = mlContext.Transforms.Text.FeaturizeText("BMI", "Features") .Append(mlContext.BinaryClassification.Trainers.FastTree(numLeaves: 10, numTrees: 10, minDatapointsInLeaves: 5)); var exp = pipeline.Fit(dataView); var model = BinaryClassML.Train(mlContext, _trainDataPath); bool res = BinaryClassML.Predict(mlContext, model, "58"); Assert.AreEqual(true, res); }
public void RecordDataFileContentTest() { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string modelPath = getPath + "\\GoDiet\\DietData\\DataModel\\modelPath"; BinaryClassML.RecordData(modelPath, ""); InitialWindow.SetUsername = "******"; string fileName = "binary_cl_" + InitialWindow.SetUsername.ToString() + ".txt"; string dataModelPath = Path.Combine(modelPath, fileName); string filePath = modelPath + "\\" + fileName; BinaryClassML.RecordData(modelPath, ""); string content = "Binary Classification Algorithm Data Record"; bool checkThis = false; using (StreamReader sr = new StreamReader(filePath)) { string contents = sr.ReadToEnd(); if (contents.Contains(content)) { checkThis = true; } } Assert.AreEqual(true, checkThis); }
public void RecordDataTest() { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string modelPath = getPath + "\\GoDiet\\DietData\\DataModel\\modelPath"; BinaryClassML.RecordData(modelPath, ""); Assert.AreEqual("Worked", BinaryClassML.check); }
public void SaveModelAsFile() { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string _trainDataPath = getPath + "\\GoDiet\\DietData\\DataModel\\trainData\\weight_lr_train1.csv"; MLContext mlContext = new MLContext(seed: 0); ITransformer model = BinaryClassML.Train(mlContext, _trainDataPath); BinaryClassML.SaveModelAsFile(mlContext, model); Assert.AreEqual("Saved", BinaryClassML.check); }
public void RecordDataExceptionThrownTest() { try { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string modelPath = getPath + "\\DietData\\DataModel\\modelPath"; BinaryClassML.RecordData(modelPath, ""); Assert.Fail(); } catch (Exception) { } }
public void EvaluateFailTest() { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string trainDataPath = getPath + "\\GoDiet\\DietData\\DataModel\\trainData\\weight_lr_train1.csv"; MLContext mlContext = new MLContext(seed: 0); var model = BinaryClassML.Train(mlContext, trainDataPath); BinaryClassML.Evaluate(mlContext, model); Assert.AreNotEqual("", BinaryClassML.check); }
public void SaveModelAsFileExceptionThrownTest() { try { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string _trainDataPath = getPath + "\\DietData\\DataModel\\trainData\\weight_lr_train1.csv"; MLContext mlContext = new MLContext(seed: 0); ITransformer model = BinaryClassML.Train(mlContext, _trainDataPath); BinaryClassML.SaveModelAsFile(mlContext, model); Assert.Fail(); } catch (Exception) { } }
public void RecordDataIsFileTest() { string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string modelPath = getPath + "\\GoDiet\\DietData\\DataModel\\modelPath"; BinaryClassML.RecordData(modelPath, ""); InitialWindow.SetUsername = "******"; string fileName = "binary_cl_" + InitialWindow.SetUsername.ToString() + ".txt"; string dataModelPath = Path.Combine(modelPath, fileName); string filePath = modelPath + "\\" + fileName; BinaryClassML.RecordData(modelPath, ""); Assert.IsTrue(File.Exists(filePath)); }