假设我有一个包含10个类的数据集。每个类包含3个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)
如何使用Alglib LDA(或任何其他免费的LDA库)确定类X是否属于上述类之一?
示例代码将不胜感激。
答案 0 :(得分: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.
}