• PCA MATLAB代码


    clear all,clc;
    A=[[-1,1];[-2,-1];[-3,-2];[1,1];[2,1];[3,2]];
    A_mean=A-mean(A);
    A_div=A_mean;
    M=A_div'*A_div;
    N=A_div*A_div';
    [M_vector,M_val]=eig(M);
    [N_vector,N_val]=eig(N);
    
    M_vector=fliplr(M_vector);
    N_vector=fliplr(N_vector);
    %M_vector=flipud(M_vector)
    %N_vector=flipud(N_vector)
    
    M_val=diag(M_val);
    N_val=diag(N_val);
    M_val=flipud(M_val)
    N_val=flipud(N_val)
    
    theta1=sqrt(M_val(1));
    theta2=sqrt(M_val(2));
    cgma=zeros(size(A));
    cgma(1,1)=theta1;
    cgma(2,2)=theta2;
    %-(N_vector*cgma*M_vector')
    -N_vector*cgma
    [clo,row]=size(A)
    final_output=-N_vector(:,1)*sqrt((clo-1))
    explained_variance_=sum(cgma).*sum(cgma)./(clo-1);
    reverse=final_output*(sqrt(explained_variance_(1)).*M_vector(:,1)')+mean(A)
    

      

    clear,clc;
    A=[[0,1];[1,1];[1,0]];
    A_mean=A;
    %A_div=A_mean*A_mean';
    A_div=A_mean;
    M=A_div'*A_div;
    N=A_div*A_div';
    [M_vector,M_val]=eig(M);
    [N_vector,N_val]=eig(N);
    M_vector=fliplr(M_vector);
    N_vector=fliplr(N_vector);
    M_vector=flipud(M_vector)
    N_vector=flipud(N_vector)
    M_val=diag(M_val);
    N_val=diag(N_val);
    M_val=flipud(M_val)
    N_val=flipud(N_val)
    theta1=A_mean*M_vector(:,1)./N_vector(:,1)
    theta2=A_mean*M_vector(:,2)./N_vector(:,2)
    cgma=zeros(size(A));
    cgma(1,1)=theta1(1);
    cgma(2,2)=theta2(1);
    N_vector*cgma*M_vector'
    

      

    clear,clc;
    A=[[-1,1];[-2,-1];[-3,-2];[1,1];[2,1];[3,2]];
    A_mean=A-mean(A);
    A_div=A_mean*A_mean';
    A_div=A_mean;
    M=A_div'*A_div;
    N=A_div*A_div';
    [M_vector,M_val]=eig(M);
    [N_vector,N_val]=eig(N);
    
    M_vector=fliplr(M_vector);
    N_vector=fliplr(N_vector);
    %M_vector=flipud(M_vector)
    %N_vector=flipud(N_vector)
    
    M_val=diag(M_val);
    N_val=diag(N_val);
    M_val=flipud(M_val)
    N_val=flipud(N_val)
    
    theta1=sqrt(M_val(1));
    theta2=sqrt(M_val(2));
    cgma=zeros(size(A));
    cgma(1,1)=theta1;
    cgma(2,2)=theta2;
    -(N_vector*cgma*M_vector')
    N_vector*cgma
    

      

    早期的代码备份,这样文件删的心安理得。




    Le vent se lève! . . . il faut tenter de vivre!


    Le vent se lève! . . . il faut tenter de vivre!
  • 相关阅读:
    LeetCode 225. 用队列实现栈 做题笔记
    杨辉三角
    字母图形
    01字符串
    圆的面积
    饮料和啤酒
    进制转换
    从今天起 复习算法
    乘法群
    Paillier同态加密的介绍以及c++实现
  • 原文地址:https://www.cnblogs.com/bai2018/p/15357891.html
Copyright © 2020-2023  润新知