public void GetDataNotSameTest() { var provider = new ExcelDataProvider(file); var data1 = provider.GetData(); var data2 = provider.GetData(); Console.WriteLine(JsonConvert.SerializeObject(data1)); Console.WriteLine(JsonConvert.SerializeObject(data2)); Assert.AreNotSame(data1, data2); }
public void GetDataNotNullTest() { var provider = new ExcelDataProvider(file); var data = provider.GetData(); Console.WriteLine(JsonConvert.SerializeObject(data)); Assert.AreNotEqual(null, data); }
public static void Ex() { LearningPipeline pipeline = new LearningPipeline(); pipeline.Add(new TextLoader(@"C:\Users\Дарья\Desktop\AdverbNoun.csv").CreateFrom <Model>(useHeader: true, separator: ',')); pipeline.Add(new Dictionarizer(("Category", "Label"))); pipeline.Add(new TextFeaturizer("Features", "Word")); pipeline.Add(new StochasticDualCoordinateAscentClassifier()); //Vec < R4, 472 > pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "PredictedLabel" }); var model = pipeline.Train <Model, CategoryPrediction>(); model.WriteAsync(@"C:\Users\Дарья\Desktop\NewModel.zip"); model = PredictionModel.ReadAsync <Model, CategoryPrediction>(@"C:\Users\Дарья\Desktop\NewModel.zip").Result; var testData = new TextLoader(@"C:\Users\Дарья\Desktop\TestAdverbNoun.csv").CreateFrom <Model>(useHeader: true, separator: ','); var evaluator = new ClassificationEvaluator(); var metrics = evaluator.Evaluate(model, testData); Console.WriteLine($"AccuracyMicro: {metrics.AccuracyMicro}\nAccuracyMacro: {metrics.AccuracyMacro}"); var data = ExcelDataProvider.GetData(@"C:\Users\Дарья\Desktop\TestAdverbNoun.xlsx", 0); List <Model> models = new List <Model>(); data.ForEach(x => models.Add(new Model() { Category = x.Category, Word = x.Word })); foreach (var sample in models) { var prediction = model.Predict(sample); Console.WriteLine($"Word: {sample.Word}"); Console.WriteLine($"\nActual Category: {sample.Category} \nPredicted Category: {prediction.Category}\nPredicted Category scores: [{String.Join(",", prediction.Score)}]\n\n"); } Console.ReadLine(); }
static void Main(string[] args) { DataTable data = new DataTable("Categories of words"); data.Columns.Add("Category", "Word"); List <InputData> words = ExcelDataProvider.GetData(@"C:\Users\Дарья\Desktop\AdverbNoun.xlsx", 0); foreach (var word in words) { data.Rows.Add(word.Category, word.Word); } Codification codebook = new Codification(data, "Category", "Word"); DataTable symbols = codebook.Apply(data); int[][] inputs = symbols.ToJagged <int>("Category"); int[] outputs = symbols.ToArray <int>("Word"); var learner = new NaiveBayesLearning(); NaiveBayes nb = learner.Learn(inputs, outputs); data = new DataTable("Categories of words"); data.Columns.Add("Category", "Word"); words = ExcelDataProvider.GetData(@"C:\Users\Дарья\Desktop\TestAdverbNoun.xlsx", 0); foreach (var word in words) { data.Rows.Add(word.Category, word.Word); } int[] instance = codebook.Translate("helpful"); int c = nb.Decide(instance); string result = codebook.Translate("Category", c); double[] probs = nb.Probabilities(instance); Console.WriteLine(0); }
public static void ShowPredictResults(string dataPath, string modelPath, int predictDataSheetNumber) { MLContext mlContext = new MLContext(); List <InputData> inputs = ExcelDataProvider.GetData(dataPath, predictDataSheetNumber); List <Input> input = new List <Input>(); inputs.ForEach(x => input.Add(new Input(x.Category, x.Word))); IDataView dataView = mlContext.Data.LoadFromEnumerable <Input>(input); IEnumerable <Input> samples = mlContext.Data.CreateEnumerable <Input>(dataView, false); Console.WriteLine("Predictions"); foreach (var sample in samples) { Output predictionResult = Predict(sample, modelPath); Console.WriteLine($"Word: {sample.Word}"); //Console.WriteLine($"\nActual Category: {sample.Category} \nPredicted Category: {predictionResult.Category}\nPredicted Category scores: [{String.Join(",", predictionResult.Score)}]\n\n"); Console.WriteLine($"\nActual Category: {sample.Category} \nPredicted Category: {predictionResult.Prediction}\nPredicted Category scores: [{String.Join(",", predictionResult.Score)}]\n\n"); } Console.ReadKey(); }
private List <InputData> GetDataFromExcel(int worksheetIndex) { return(ExcelDataProvider.GetData(data.DataPath, worksheetIndex)); }