0

Suppose I have a data set with 10 classes. Each class contains 3 points in 3D:

Class 1: (1,2,3),(4,5,6),(7,8,9)
Class 2: (2,3,4),(5,6,7),(8,9,10)
.
.
Class 10: (10,15,20),(10,11,19),(4,8,9)

How can I determine if class X belongs to to one of the classes above using Alglib LDA (or any other free LDA library)?

Example code will be appreciated.

Igor
  • 1,253
  • 1
  • 25
  • 34
  • Any code showing what you have tried so far will be appreciated too. – L.B Jun 16 '12 at 18:32
  • Can't even start writing it. I didn't understood PCA until I wrote the class myself and it worked fine. Although I do understand the basics of LDA I can't figure out the logic of how to determine the belongings of one class to another. With PCA the comparison determined with the size of the EUCLIDEAN DISTANCE. With LDA it has something to do with the projection of the class on the vector with the highest eigen value. – Igor Jun 16 '12 at 18:48

1 Answers1

3

After some time I finally figured it out:

static public double[,] Test()
    {
        // This example is for points in 3D.
        // The forth variable is the class label. In this case 2 classes: 0 and 1.
        double[,] xy = new double[,]
        {
        { 4,2,1, 0 }, { 2,4,2, 0 }, { 2,3,3, 0 }, { 3,6,4, 0 }, { 4,4,5, 0 },
        { 9,10,10, 1 }, { 6,8,11, 1 }, { 9,5,12, 1 }, { 8,7,9, 1 }, { 10,8,10, 1 }
        };

        int NPoints = 10;
        int NVars = 3; // 1 for 1 dimension, 2 for 2D and so on...
        int NClasses = 2;

        int info = 0;
        double[,] w = new double[0, 0];

        alglib.lda.fisherldan(xy, NPoints, NVars, NClasses, ref info, ref w);

        return w; // The projection vector/s.
    }
Igor
  • 1,253
  • 1
  • 25
  • 34
  • Hi. Could you possibly explain what's going on here? I'm using the C++ version of this library to try and analyse a set of 6 responses to questions (answers between 1 and 7) and match them to 5 sets/classes. I'm really stuck so any help would be appreciated. – Rob Sanders Jul 27 '15 at 08:11
  • HI @RASS. Just saw your question. I hope you figured it out by now. If not, don't hesitate to ask again. – Igor Aug 30 '15 at 12:50
  • Hi @Igor. No luck yet unfortunately, to be honest I haven't been able to spend much time on it. I'm working on a project where the user has to answer 6 questions and the answers they give for each question range between 1 and 7. I then have 4 characteristics which have each been assigned a value and using the user's answers and a set of fishers lda constants have to work put which characteristic best suits the user. I don't know if you can shed any light on the issue? Many thanks. – Rob Sanders Aug 31 '15 at 16:41
  • Hi @RASS. Let me begin by saying that I haven't took any course in LDA so everything I know I learned from the web, so consider that I might be wrong. Having said that, Your problem is seems relativity simple. NClasses = 6 (6 questions). NPoints = 6 (6 questions x 1 answer = 6 points). NVars = 2 (x is question. y is answer => 2D). Now, You have 4 characteristics. That means that somehow you'll need to translate those characteristics into 4 defined vectors and each time you get a projection vector(w) for a user - check the closest defined characteristic vector to it. Hope it helps. – Igor Sep 01 '15 at 11:07
  • @Igor how can use this code for example to classifier (3,5,2) ? – Hadi Ranji Feb 08 '17 at 18:01
  • @HadiRanji, I'm not sure I understood the question. Can you please be more specific? – Igor Feb 08 '17 at 22:33
  • @Igor , My question exactly is your first question. How can use this function to classifier X ? – Hadi Ranji Feb 11 '17 at 15:11
  • @HadiRanji, Give me an example data set and I'll try to help you. – Igor Feb 12 '17 at 12:30
  • @Igor , by your dataset for x and y i need to known class x(3,5,2) is classifier 0 or 1 ? – Hadi Ranji Feb 12 '17 at 18:36
  • @HadiRanji, I can't find the source code for my project and I can't remember how I did the prediction. I do know that with the help of another function I passed to it the projection vector and the class, and it did the classification. – Igor Feb 13 '17 at 10:32