Nebula Developers
Nebula Developers

Reputation: 1

MLContext' does not contain a definition for 'CreateStreamingDataView'

I am a newbie in Ml.Net C# and I was trying to follow a tutorial, but I found this problem that I can't figure it out by my own. It says that MlContext doesn't contain any definition for CreateStreamingDataView. Here is the tutorial I was following https://www.youtube.com/watch?v=83LMXWmzRDM&ab_channel=Questpond . And here is the code:

namespace Predictive_FeedBack
{
    class FeedBackTrainingData
    {
        
        [LoadColumn(1)]
        public string FeedBackText { get; set; }
        [LoadColumn(0),ColumnName("Label") ]
        public bool IsGood { get; set; }


    }


    class Program
    {
        static List<FeedBackTrainingData> trainingdata =
            new List<FeedBackTrainingData>();
        static List<FeedBackTrainingData> testdata =
            new List<FeedBackTrainingData>();

        static void LoadTestData()
        {
            testdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "good",
                IsGood = true


            });
            testdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "bad",
                IsGood = false


            });
            testdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "nice",
                IsGood = true


            });
            testdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "awful",
                IsGood = false


            });
            testdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "horrible terrible",
                IsGood = false


            });
        }
            static void LoadTrainingData()
        {
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is good",
                IsGood = true


            }); 
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is horible",
                IsGood = false


            }); 
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is BAD",
                IsGood = false


            }); 
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "You can better",
                IsGood = false


            }); 
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is awful",
                IsGood = false


            }); 
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is terrible",
                IsGood = false


            });
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is Awesome",
                IsGood = true


            });
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is good, nice",
                IsGood = true


            });
            trainingdata.Add(new FeedBackTrainingData()
            {

                FeedBackText = "This is Well",
                IsGood = true


            });




        }

        
        static void Main(string[] args)
        {
            //Step 1 - We need to load Training data

            LoadTrainingData();
            //Step 2 - Create object of MLContext
            var mlContext = new MLContext();
            //Step 3 - Convert dataview in AI data view!
            IDataView dataView = mlContext.Data.LoadFromEnumerable<FeedBackTrainingData>(trainingdata);
            //Step 4- Create pipeline and define the workflows
            var pipeline = mlContext.Transforms.Text.FeaturizeText("Features", "FeedBackText")
                .Append(mlContext.BinaryClassification.Trainers.FastTree(numberOfLeaves:50, numberOfTrees: 50, minimumExampleCountPerLeaf:1)) ;
            //Step 5 - Train the algorithm and we want the model out.
            var model = pipeline.Fit(dataView);

            //Step 6- load test data and run the test data to check model accuracy
            LoadTestData();

            IDataView dataView1 = mlContext.CreateStreamingDataView<FeedBackTrainingData>("testdata");
            var predictions = model.Transform(dataView1);
            var metrics = mlContext.BinaryClassification.Evaluate(predictions, "Label");
       

Upvotes: 0

Views: 970

Answers (2)

user10609954
user10609954

Reputation: 1

Now it seems to maybe be.. IDataView dataView = mlContext.Data.LoadFromEnumerable(feedBackTrainingData); I could be wrong.. but that seems to be the closest.. Im following the video now.. UGH.. or rather..

mlContext.Data.LoadFromEnumerable(feedBackTrainingData);

Upvotes: 0

user3906315
user3906315

Reputation: 11

With the latest ML.NET 0.10.0, CreateStreamingDataView went missing. (Yes, I have the Microsoft.ML.Data namespace included.) Therefore, for those having this issue, replace:

var data = mlContext.CreateStreamingDataView(dataset);

With:

var data = mlContext.Data.ReadFromEnumerable(dataset);

Upvotes: 1

Related Questions