Giter Site home page Giter Site logo

Comments (3)

sjwoodard avatar sjwoodard commented on July 19, 2024

Changing the training percentage from 0.80 to 0.75 resolved the discrepancy. I think this is probably the expected result of using the Naive Bayes model, and this issue can be closed. Thanks again!

from numl.

sethjuarez avatar sethjuarez commented on July 19, 2024

Awesome. I got worried!

from numl.

groffg avatar groffg commented on July 19, 2024

Update: created separate issue for this; please disregard this comment

I must be doing something horribly wrong. I'm trying to use naive bayes to categorize some data based on input via a spreadsheet. The code runs, but it seems to give me the same category regardless of my input. I've appended some sample code below (gloss over the helper call that reads Excel; that just takes the sheet & converts to a .net dataset). Also, I'm limiting the training data to the first 100 rows. Any more than that and the program gets an out of memory exception!

So I have two questions:

  • how to get a meaningful prediction/classification?
  • how to load much larger training dataset without memory overflow?
    [Serializable]
    public class PeerCategory
    {
        [Feature]
        public string PeerCategoryDesc { get; set; }
        [Label]
        public string CAPeerCategory { get; set; }
    }

    [TestFixture]
    //[Ignore]
    public class BayesTest
    {

        [Test]
        public void TestExcel()
        {
            string pathToFile = @"C:\data\Training Data.xlsx";
            using (var reader = new FileReaderExcel(pathToFile))
            {
                int index = reader.GetSheetIndexByName("V6");
                var dt = reader.GetDataTableFromExcelSheet(index, true);
                var peerCatList = (
                    from DataRow row in dt.Rows
                    select new PeerCategory()
                    {
                        PeerCategoryDesc = row.Field<string>(0), 
                        CAPeerCategory = row.Field<string>(1)
                    }).Take(100).ToList();


                var width = peerCatList.Select(t => t.CAPeerCategory).Distinct().Count();

                IGenerator generator = new NaiveBayesGenerator(width);
                generator.Descriptor = Descriptor.Create<PeerCategory>();
                LearningModel learned = Learner.Learn(peerCatList, 0.8, 1000, generator);

                IModel model = learned.Model;
                double accuracy = learned.Accuracy;


                var value1 = model.Predict(GetItem("paint"));
                var value2 = model.Predict(GetItem("flower"));
                var value3 = model.Predict(GetItem("sofa"));
                var value4 = model.Predict(GetItem("desk"));
                var value5 = model.Predict(GetItem("bones"));
                                // value1 thru 5 will be the same category over and over again!!

            }

        }

        public PeerCategory GetItem(string desc)
        {
            var item = new PeerCategory()
            {
                PeerCategoryDesc = desc,
                CAPeerCategory = string.Empty
            };
            return item;
        }

from numl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.