0

假设我有一个包含 10 个类的数据集。每个类在 3D 中包含 3 个点:

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)

如何使用 Alglib LDA(或任何其他免费 LDA 库)确定 X 类是否属于上述类之一?

示例代码将不胜感激。

4

1 回答 1

3

一段时间后,我终于想通了:

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.
    }
于 2012-06-20T01:03:59.053 回答