Ejemplo n.º 1
0
    for i,l in enumerate(labels):
        plt.scatter(xtPCA[labelsTrain==l,0],xtPCA[labelsTrain==l,1],alpha=0.5,c=classColors[i,:])

    plt.title('Projected data over the components')
    plt.xlim([-4,4])
    plt.ylim([-4,4])
    plt.show()

if (0):
    
    #%% PARTIAL LEAST SQUARES
    #%% PLS SVD
    nComponents = np.arange(1,nClasses+1)
    plsSvdScores = np.zeros((5,np.alen(nComponents)))
    for i,n in enumerate(nComponents):
        plssvd = PLSSVD(n_components=n)
        plssvd.fit(Xtrain,Ytrain)
        XtrainT = plssvd.transform(Xtrain)
        XtestT = plssvd.transform(Xtest)
        plsSvdScores[:,i] = util.classify(XtrainT,XtestT,labelsTrain,labelsTest)
        
    plssvd = PLSSVD(n_components=2)
    xt,yt = plssvd.fit_transform(Xtrain,Ytrain)
    fig = plt.figure()
    util.plotData(fig,xt,labelsTrain,classColors)
    plt.title('First 2 components of projected data')
    
    #%% Plot accuracies for PLSSVD 
    plt.figure()
    for i in range (5):
        plt.plot(nComponents,plsSvdScores[i,:],lw=3)