Example #1
0
        static void Main(string[] args)
        {
            // cargamos los datos
            loadTrainigData();
            //Clase de ML.NET, la necesitamos para acceder a las operaciones del machine learning
            var mlContext = new MLContext();
            //Convertimos nuestros datos de trainingData en IDataView (Interfaz de ML.NET)
            IDataView dataView = mlContext.Data.LoadFromEnumerable <FeedbackTrainingData>(trainingData);
            // Creamos el pipeline
            //definimos nuestro algoritmo
            var pipeline = mlContext.Transforms.Text.FeaturizeText("Features", "feedbackText").Append(mlContext.BinaryClassification.Trainers.FastTree(numberOfLeaves: 50, numberOfTrees: 50, minimumExampleCountPerLeaf: 1));
            // Entrenamos el algoritmo
            var model = pipeline.Fit(dataView);

            //Test data para ver accuracy
            loadTestData();
            IDataView dataViewTest = mlContext.Data.LoadFromEnumerable <FeedbackTrainingData>(testData);
            var       predictions  = model.Transform(dataViewTest);
            var       metrics      = mlContext.BinaryClassification.Evaluate(predictions, "Label");

            Console.WriteLine(metrics.Accuracy);

            //
            Console.WriteLine("Feedback:");
            string feedbackString     = Console.ReadLine();
            var    predictionFunction = mlContext.Model.CreatePredictionEngine <FeedbackTrainingData, FeedbackPrediction>(model);
            var    feedbackInput      = new FeedbackTrainingData();

            feedbackInput.feedbackText = feedbackString;
            var feedbackPredicted = predictionFunction.Predict(feedbackInput);

            Console.WriteLine("Se predice:" + feedbackPredicted.isGood);
            Console.Read();
        }
Example #2
0
        static void Main(string[] args)
        {
            // load the training data
            LoadTrainingData();

            var mlContext = new MLContext();

            IDataView dataView = mlContext.CreateStreamingDataView <FeedbackTrainingData>(trainingData);

            var pipeline = mlContext.Transforms.Text.FeaturizeText("FeedbackText", "Features").Append(mlContext.BinaryClassification.Trainers.FastTree(numLeaves: 50, numTrees: 50, minDatapointsInLeaves: 1));

            var model = pipeline.Fit(dataView);

            LoadTestData();

            IDataView dataView1 = mlContext.CreateStreamingDataView <FeedbackTrainingData>(testData);

            var predictions = model.Transform(dataView1);

            var metrics = mlContext.BinaryClassification.Evaluate(predictions, "Label");

            Console.WriteLine("Feedback Prediction Model Accuracy : " + metrics.Accuracy);

            while (true)
            {
                Console.WriteLine("\nEnter Feedback String:");

                string feedbackString = Console.ReadLine().ToString();

                var predictionFunction = model.MakePredictionFunction <FeedbackTrainingData, FeedbackPrediction>(mlContext);

                var feedbackInput = new FeedbackTrainingData();

                feedbackInput.FeedbackText = feedbackString;

                var feedbackPredicted = predictionFunction.Predict(feedbackInput);

                if (feedbackPredicted.IsGood)
                {
                    Console.WriteLine("+ve feedback");
                }
                else
                {
                    Console.WriteLine("-ve feedback");
                }
            }
        }