线性判别分析

Linear discriminant analysis using alglib

本文关键字:线性      更新时间:2023-10-16

我被要求对我的一个项目的一组数据进行线性判别分析。我正在使用ALGLIB (c++版本),它有一个渔场函数,但我需要一些帮助了解如何使用它。

用户回答了一组6个问题(答案是1-7之间的数字),这给了我一个示例数据集,例如{1,2,3,4,5,6}。然后我有5类,每类6个值,例如{0.765,0.895,1.345,2.456,0.789,5.678}。fisher lda函数接受一个二维的值数组,并返回另一个一维的值数组(我不知道它们是什么意思)。

据我所知,我需要看看哪个类的用户回答最适合?

如果能帮助我理解LDA和/或如何使用这个函数,我将不胜感激。

编辑:

下面是我要使用的函数的定义:

/*************************************************************************
Multiclass Fisher LDA
Subroutine finds coefficients of linear combination which optimally separates
training set on classes.
INPUT PARAMETERS:
    XY          -   training set, array[0..NPoints-1,0..NVars].
                    First NVars columns store values of independent
                    variables, next column stores number of class (from 0
                    to NClasses-1) which dataset element belongs to. Fractional
                    values are rounded to nearest integer.
    NPoints     -   training set size, NPoints>=0
    NVars       -   number of independent variables, NVars>=1
    NClasses    -   number of classes, NClasses>=2

OUTPUT PARAMETERS:
    Info        -   return code:
                    * -4, if internal EVD subroutine hasn't converged
                    * -2, if there is a point with class number
                          outside of [0..NClasses-1].
                    * -1, if incorrect parameters was passed (NPoints<0,
                          NVars<1, NClasses<2)
                    *  1, if task has been solved
                    *  2, if there was a multicollinearity in training set,
                          but task has been solved.
    W           -   linear combination coefficients, array[0..NVars-1]
  -- ALGLIB --
     Copyright 31.05.2008 by Bochkanov Sergey
*************************************************************************/
void fisherlda(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nvars, const ae_int_t nclasses, ae_int_t &info, real_1d_array &w);

你正在使用的是fishlda函数,它是LDA算法的实现。

LDA(线性判别分析)旨在找到最能表征或分离两类或两类以上对象或事件的特征的线性组合。

假设y=wx(w,x在这里都代表一个矩阵),所以fishlad的给定结果是一个系数的1d数组,即w.然后您可以使用这行来确定答案属于哪个类。