def lda(data,labels,reg=0.0):
    means = {}
    priors = {}
    
    classes = list(set(labels))
    classes.sort()
    
    # number of classes
    C = len(classes)
    
    # number of data points
    N = data.shape[0]
    
    # number of dimensions
    D = data.shape[1]

    for key in classes:
        priors[key] = float((labels == key).sum())/labels.shape[0]
        means[key] = data[labels==key,:].mean(axis=0)
    
    # Compute the between class cov
    t1 = [mean for key,mean in means.iteritems()]
    t1 = np.array(t1)
    
    # mean of class means
    t2 = t1.mean(axis=0)
    t3 = t2 - t1
    Sb = np.dot(t3.T,t3)/(C-1)
    
    # size of cov matrix should be DxD
    assert Sb.shape == (D,D)
    
    # Compute the within class cov
    
    data_w = data.copy()
    for key in classes:
        # subtract the class mean (c_mean) from each data point
        c_mean = means[key].reshape(1,D)
        data_w[labels == key,:] -= c_mean
        
    Sw = np.dot(data_w.T,data_w) / (N-C) # within class scatter

    # Check the shape of SW    
    assert Sw.shape == (D,D)
    
    #Compute vectors using generalized eigenvector solver: Sb v = l Sw v
    if reg >= 0:
        Sw = Sw+reg*np.eye(Sw.shape[0]) # regularization for stability
    val,vec = la.eigh(Sb,Sw)
    
    # Reorder vectors so the most important comes first
    order = val.argsort()[::-1] # reverse order
    val = val[order]
    vec = vec[:,order]
    val = val[:C-1]
    vec = vec[:,:C-1]
    
    #scale the eigen values
    val = val/val.sum()
    
    return val,vec,means,priors
Lists capabilities
dataset/ETHPy150Open bolme/pyvision/src/pyvision/ml/lda.py/lda--crossover with--dataset/ETHPy150Open jasonhancock/cloudstack-python-client/CloudStack/Client.py/Client.listCapabilities