Giter VIP home page Giter VIP logo

Comments (2)

EdwardRaff avatar EdwardRaff commented on August 19, 2024

Unfortunately I'm very busy with some work right now, so getting to all these is going to take a bit.

I'm not sure what you are storing in your Table, you will have to determine if your features should be numeric or categorical yourself. Does the below code snippet help?

    public static void main(String[] args)
    {
        //Some random data we want to convert to a DataSet object manually 
        Random rand = new XORWOW();
        double[][] someStuffIWantToMakeIntoADataSet = new double[20][6];
        for(int i = 0; i < someStuffIWantToMakeIntoADataSet.length; i++)
            for(int j = 0; j < someStuffIWantToMakeIntoADataSet[i].length; j++)
                someStuffIWantToMakeIntoADataSet[i][j] = rand.nextDouble();

        //Lets decide the first 2 features are categorical and the rest are just numeric

        //First we need the list the categories. Well create 1 categorie with 2 options and a 2nd category with 3 options. 
        CategoricalData[] categories = new CategoricalData[]
        {
            new CategoricalData(2), new CategoricalData(3)
        };

        SimpleDataSet sds = new SimpleDataSet(categories, 4);

        for(double[] row : someStuffIWantToMakeIntoADataSet)
        {
            //first a place to store the categorical values. 
            int[] catValues = new int[categories.length];
            catValues[0] =  (int) Math.round(row[0]);//first cat will be whether the value was closer to 0 or 1
            catValues[1] =  (int) Math.round(row[1]*2);//similar for second
            //Next we need a place to store the numeric features
            Vec numericValues = new DenseVector(4);
            for(int i = 0; i < 4; i++)
                numericValues.set(i, row[2+i]);
            DataPoint dp = new DataPoint(numericValues, catValues, categories);
            //now just add to the dataset
            sds.add(dp);
        }

        //done, we have made a data set
    }

from jsat.

salamanders avatar salamanders commented on August 19, 2024

Perfect! Exactly what I was looking for - things like adding to the Vec one at a time being ok, not caring what the strings were that correspond to a category integer and just saving the final number - great stuff.

from jsat.

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.